Module documentation for 3.1.11
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.
- 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 library on Kunigami's blog.
- An introduction to parsing text in Haskell with Parsec on Wilson's blog.
- Differences between Parsec and Attoparsec (Haskell's other prominent parser library) as explained in an 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 and Megaparsec (an advanced fork of Parsec) as explained in Megaparsec's README.
This requires a working version of
ghci, which are part of
any modern installation of Haskell, such as
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
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-220.127.116.11 ... linking ... done. Loading package bytestring-0.10.4.0 ... linking ... done. Loading package mtl-18.104.22.168 ... linking ... done. Loading package text-22.214.171.124 ... 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 ")"
Right () results indicate successes: the parentheses matched.
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.
Issues (bugs, feature requests or otherwise feedback) may be reported in the Github issue tracker for this project.
Pull-requests are also welcome.
See the LICENSE file in the repository.
Add official support for
NOTE: This is the first version whose
SafeHaskellproperties have become an intentional part of the API contract; previous versions were merely accidentally safe-inferred (or not depending on various factors; in other words, this was a fragile property). If you rely on
SafeHaskellto consider module imports from
parsecsafe, this is the first version of
parsecwhich actually guarantees a well-defined state; you can declare this requirement by either specifying
build-depends: parsec >= 126.96.36.199 && < 3.2
or, starting with
build-depends: parsec ^>= 188.8.131.52
Drop support for GHC 7.0, GHC 7.2, and GHC 7.4.1; support window starts with GHC 7.4.2.
Support limited to GHC 7.0 & GHC 7.2 only
Fix space leak in Applicative/Monad interface (#37)
parserTracedcombinators for debugging.
- Most types now have a
Typeableinstance. Some instances are dropped from older versions of GHC (sorry about that!).
- The token-parser now rejects Unicode numeric escape sequences for characters outside the Unicode range.
- The token-parser now loses less precision when parsing literal doubles.
- Documentation fixes and corrections.
- We no longer test parsec builds on GHC 7.4.
- Many and various updates to documentation and package description (inlcuding the homepage links).
- Add an
- Fixed a regression from 3.1.6:
runPis again exported from module Text.Parsec.
Fix a regression from 3.1.6 related to exports from the main module.
- Fix a regression from 3.1.6 related to the reported position of error messages. See bug #9 for details.
- Reset the current error position on success of
Textinstances from Text.Parsec
- Make Text.Parsec exports more visible
- Re-arrange Text.Parsec exports
- Add functions
endOfLineto Text.Parsec.Char for handling input streams that do not have normalized line terminators.
- Fix off-by-one error in Token.charControl
Relax dependency on
Relax dependency on
- Fix a regression introduced in 3.1.2 related to positions reported by error messages.