parsec (original) (raw)
parsec: Monadic parser combinators
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.
The main entry point is the Text.Parsec module which provides defaults for parsing Char
acter data.
The Text.ParserCombinators.Parsec module hierarchy contains the legacy parsec-2
API and may be removed at some point in the future.
Modules
[Index] [Quick Jump]
- 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
- Text.Parsec
Downloads
- parsec-3.1.18.0.tar.gz [browse] (Cabal source package)
- Package description (as included in the package)
Maintainer's Corner
For package maintainers and hackage trustees
Candidates
- No Candidates
Versions [RSS] | 2.0, 2.0.0.1, 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, 3.1.12.0, 3.1.13.0, 3.1.14.0, 3.1.15.0, 3.1.15.1, 3.1.16.0, 3.1.16.1, 3.1.17.0, 3.1.18.0 | ||||||||
---|---|---|---|---|---|---|---|---|---|
Change log | ChangeLog.md | ||||||||
Dependencies | base (>=4.12.0.0 && <4.22), bytestring (>=0.10.8.2 && <0.13), mtl (>=2.2.2 && <2.4), text (>=1.2.3.0 && <1.3 | | >=2.0 && <2.2) [details] | |||||||
Tested with | ghc ==8.6.5 | | ==8.8.4 | ==8.10.7 | ==9.0.2 | ==9.2.8 | ||||
License | BSD-2-Clause | ||||||||
Author | Daan Leijen daan@microsoft.com, Paolo Martini paolo@nemail.it, Antoine Latter aslatter@gmail.com | ||||||||
Maintainer | Oleg Grenrus oleg.grenrus@iki.fi, Herbert Valerio Riedel hvr@gnu.org | ||||||||
Category | Parsing | ||||||||
Home page | https://github.com/haskell/parsec | ||||||||
Bug tracker | https://github.com/haskell/parsec/issues | ||||||||
Source repo | head: git clone https://github.com/haskell/parsec | ||||||||
Uploaded | by phadej at 2025-01-05T00:08:05Z | ||||||||
Distributions | Arch:3.1.16.1, Fedora:3.1.16.1, FreeBSD:3.1.9 | ||||||||
Reverse Dependencies | 945 direct, 14244 indirect [details] | ||||||||
Downloads | 405225 total (110 in the last 30 days) | ||||||||
Rating | 2.75 (votes: 18)[estimated by Bayesian average] | ||||||||
Your Rating | λ λ λ | ||||||||
Status | Docs available [build log]Last success reported on 2025-01-05 [all 1 reports] |
Readme for parsec-3.1.18.0
Please refer to the package description on Hackage for more information.
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:
- Parsec on Hackage, contains the generated documentation.
- The 2001 paper written by Daan Leijen, some what outdated (PDF,HTML, thanks to archive.org; and PDF, thanks to Microsoft Research).
- Using Parsec, chapter 16 of Real World Haskell.
- An introduction to the Parsec libraryon Kunigami's blog.
- An introduction to parsing text in Haskell with Parsec on Wilson's blog.
- Differences between Parsec andAttoparsec(Haskell's other prominent parser library) as explained inan answer on StackExchange.
- Differences between Parsec and Happy(Haskell's parser generator) as explained in two answers on separate StackExchange questions (1,2).
- Differences between Parsec andMegaparsec(an advanced fork of Parsec) as explained inMegaparsec's README.
By analyzing Parsec's reverse dependencies on Hackagewe can find open source project that make use of Parsec. For examplebibtex,ConfigFile,csv andhjson.
Getting started
This requires a working version of cabal
and ghci
, which are part of any modern installation of Haskell, such asHaskell 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 ')' :: Parsec String () 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 inthe Github issue tracker for this project.
Pull-requests are also welcome.
License
See the LICENSEfile in the repository.