syntax: Reversible parsing and pretty-printing.

[ data, library, mit ] [ Propose Tags ] [ Report a vulnerability ]

"syntax" allows you to write a single syntax description and instantiate is both as a parser and a pretty printer.

Syntax descriptions are written in applicative or arrow style. The library uses a custom typeclass hierarchy, provided by the "semi-iso" package. Most of the time you will be using operators like /$/, /*/ and /+/ (= <|>), just like parser combinators. When more power is needed - e.g. when the syntax depends on the parsed or printed value - you turn to arrows.

Semi-isomorphisms from "semi-iso" are the basic building block of syntax descriptions. I recommend reading the hackage page of "semi-iso" first, as it contains much more information.

Once you write a syntax description (polymorphic in the syntax category) you can instantiate it both as a parser or as a pretty-printer. The library "syntax-attoparsec" gives you the ability to extract an Attoparsec parser. Pretty-printing is implemented by the "syntax-printer" library, which uses Text and ByteString builders. (Note that formatting is handled by "syntax" itself, not by the printer library)

Advanced formatting and parsing (for example indentation, haskell layout rule) is implemented as category transformers (similar to monad transformers). Currently only simple indentation is implemented (in Data.Syntax.Indent) - basically a reader category transformer that tracks current indentation level. I plan on implementing Haskell layout rule in the future.

The library can work with both text and binary data. Alas, there are no binary combinators implemented yet.

EXAMPLES! See syntax-example and syntax-example-json for examples.

  • "syntax-example" implements a simple lambda calculus.

  • "syntax-example-json" implements a json parser and pretty printer.

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.1.0, 0.2.0.0, 0.2.1.0, 0.3.0.0, 1.0.0.0
Dependencies base (>=4 && <5), lens (>=4), mono-traversable, scientific (>=0.3), semi-iso (>=1), text, vector [details]
License MIT
Copyright Paweł Nowak 2014
Author Paweł Nowak
Maintainer Paweł Nowak <pawel834@gmail.com>
Revised Revision 2 made by pawel834 at 2015-11-19T04:05:20Z
Category Data
Source repo head: git clone git@github.com:Pawel834/syntax.git
Uploaded by pawel834 at 2014-12-12T23:30:44Z
Distributions
Reverse Dependencies 4 direct, 0 indirect [details]
Downloads 5097 total (6 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user [build log]
All reported builds failed as of 2014-12-12 [all 1 reports]