pa-field-parser: “Vertical” parsing of values

[ bsd3, data, library, possehl-analytics ] [ Propose Tags ] [ Report a vulnerability ]

Modules

[Last Documentation]

  • FieldParser

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0, 0.1.0.1, 0.2.0.0, 0.2.0.1, 0.3.0.0, 0.3.1.0
Change log CHANGELOG.md
Dependencies aeson, aeson-better-errors, attoparsec, base (<5), case-insensitive, containers, pa-error-tree, pa-prelude (>=0.2.0.0), scientific, semigroupoids, template-haskell, text, time [details]
License BSD-3-Clause
Copyright 2023 Possehl Analytics GmbH
Author
Maintainer Philip Patsch <philip.patsch@possehl-analytics.com>
Category Data, Possehl-Analytics
Home page https://github.com/possehl-analytics/pa-hackage
Uploaded by Profpatsch at 2024-09-04T12:37:50Z
Distributions NixOS:0.3.1.0
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 264 total (3 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs not available [build log]
All reported builds failed as of 2024-09-04 [all 2 reports]

Readme for pa-field-parser-0.3.1.0

[back to package description]

pa-field-parser

A small library for “vertical parsing” of values.

Traditional parsers are “horizontal” parsers, they take a flat list of tokens and produce structure:


[  token1 token2 token3 token4 token5 ]
----> horizontal parser

result:

- token1
|
`-- token2
|
`-- token3
  |
  `-- token 4 -- token 5

A FieldParser is a “vertical” parser. Once you have some low-level type in hand, usually you want to do some more checks, to “upgrade” it so to say:


  Integer
    ^
    | signedDecimal
    |
   Text
    ^
    | utf8
    |
ByteString

As a FieldParser, this would look like:

utf8 :: FieldParser ByteString Text
signedDecimal :: FieldParser Text Integer

(utf8 >>> signedDecimal) :: FieldParser ByteString Integer

>>> is from Control.Category, but Profunctor is also available to map over the left and right arguments.

When run, this produces either a value or a helpful error message.

They can be freely combined with other libraries, and act as a nice adapter between them. For example, the JSON-related functions integrate with aeson-better-errors and any FieldParser Value a can be converted to a FromJSON instance for aeson. attoparsec is also available to easily turn bytes or text parsers into FieldParsers.

You can use this library as-is, but the design is easily adaptable to your codebase, the idea is very simple. Feel free to copy and paste what you need.