The parsec package

[Tags:bsd3, library]

Parsec is designed from scratch as an industrial-strength parser library. It is simple, safe, well documented (on the package homepage), has extensive libraries, good error messages, and is fast. It is defined as a monad transformer that can be stacked on arbitrary monads, and it is also parametric in the input stream type.


[Skip to Readme]

Properties

Versions 2.0, 2.1.0.0, 2.1.0.1, 3.0.0, 3.0.1, 3.1.0, 3.1.1, 3.1.2, 3.1.3, 3.1.4, 3.1.5, 3.1.6, 3.1.7, 3.1.8, 3.1.9, 3.1.10, 3.1.11
Change log CHANGES
Dependencies base (==4.*), bytestring, mtl, text (>=0.2 && <1.3) [details]
License BSD3
Author Daan Leijen <daan@microsoft.com>, Paolo Martini <paolo@nemail.it>
Maintainer Antoine Latter <aslatter@gmail.com>
Stability Unknown
Category Parsing
Home page https://github.com/aslatter/parsec
Bug tracker https://github.com/aslatter/parsec/issues
Source repository head: git clone https://github.com/aslatter/parsec
Uploaded Fri May 13 03:05:25 UTC 2016 by AntoineLatter
Distributions Arch:3.1.11, Debian:3.1.9, Fedora:3.1.5, FreeBSD:3.1.9, LTSHaskell:3.1.11, NixOS:3.1.11, Stackage:3.1.11
Downloads 215130 total (51 in the last 30 days)
Votes
2 []
Status Docs pending
Build status unknown [no reports yet]

Modules

  • Text
    • Text.Parsec
      • Text.Parsec.ByteString
        • Text.Parsec.ByteString.Lazy
      • Text.Parsec.Char
      • Text.Parsec.Combinator
      • Text.Parsec.Error
      • Text.Parsec.Expr
      • Text.Parsec.Language
      • Text.Parsec.Perm
      • Text.Parsec.Pos
      • Text.Parsec.Prim
      • Text.Parsec.String
      • Text.Parsec.Text
        • Text.Parsec.Text.Lazy
      • Text.Parsec.Token
    • ParserCombinators
      • Text.ParserCombinators.Parsec
        • Text.ParserCombinators.Parsec.Char
        • Text.ParserCombinators.Parsec.Combinator
        • Text.ParserCombinators.Parsec.Error
        • Text.ParserCombinators.Parsec.Expr
        • Text.ParserCombinators.Parsec.Language
        • Text.ParserCombinators.Parsec.Perm
        • Text.ParserCombinators.Parsec.Pos
        • Text.ParserCombinators.Parsec.Prim
        • Text.ParserCombinators.Parsec.Token

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Readme for parsec

Readme for parsec-3.1.11

Parsec Build Status

A monadic parser combinator library, written by Daan Leijen. Parsec is designed from scratch as an industrial-strength parser library. It is simple, safe, well documented, has extensive libraries, good error messages, and is fast.

Some links:

By analyzing Parsec's reverse dependencies on Hackage we can find open source project that make use of Parsec. For example bibtex, ConfigFile, csv and hjson.

Getting started

This requires a working version of cabal and ghci, which are part of any modern installation of Haskell, such as Haskell Platform.

First install Parsec.

cabal install parsec

Below we show how a very simple parser that tests matching parentheses was made from GHCI (the interactive GHC environment), which we started with the ghci command).

Prelude> :m +Text.Parsec
Prelude Text.Parsec> let parenSet = char '(' >> many parenSet >> char ')'
Loading package transformers-0.3.0.0 ... linking ... done.
Loading package array-0.5.0.0 ... linking ... done.
Loading package deepseq-1.3.0.2 ... linking ... done.
Loading package bytestring-0.10.4.0 ... linking ... done.
Loading package mtl-2.1.3.1 ... linking ... done.
Loading package text-1.1.1.3 ... linking ... done.
Loading package parsec-3.1.5 ... linking ... done.
Prelude Text.Parsec> let parens = (many parenSet >> eof) <|> eof
Prelude Text.Parsec> parse parens "" "()"
Right ()
Prelude Text.Parsec> parse parens "" "()(())"
Right ()
Prelude Text.Parsec> parse parens "" "("
Left (line 1, column 2):
unexpected end of input
expecting "(" or ")"

The Right () results indicate successes: the parentheses matched. The Left [...] result indicates a parse failure, and is detailed with an error message.

For a more thorough introduction to Parsec we recommend the links at the top of this README file.

Contributing

Issues (bugs, feature requests or otherwise feedback) may be reported in the Github issue tracker for this project.

Pull-requests are also welcome.

License

See the LICENSE file in the repository.