Monadic parser combinators

Version on this page:3.1.9
LTS Haskell 8.19:3.1.11
Stackage Nightly 2017-06-23:3.1.11
Latest on Hackage:3.1.11
BSD3 licensed by Daan Leijen, Paolo Martini
Maintained by Antoine Latter

Module documentation for 3.1.9

There are no documented modules for this package.

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- ... linking ... done.
Loading package array- ... linking ... done.
Loading package deepseq- ... linking ... done.
Loading package bytestring- ... linking ... done.
Loading package mtl- ... linking ... done.
Loading package text- ... 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.


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.



- Include `` in package.


- Most types now have a `Typeable` instance. 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 'Eq' instance for 'ParseError'
- Fixed a regression from 3.1.6: 'runP' is again exported from module


- 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 'lookAhead'.


- Export 'Text' instances from Text.Parsec
- Make Text.Parsec exports more visible
- Re-arrange Text.Parsec exports
- Add functions 'crlf' and 'endOfLine' to Text.Parsec.Char for handling
input streams that do not have normalized line terminators.
- Fix off-by-one error in Token.charControl

3.1.4 & 3.1.5

- Bump dependency on 'text'


- Fix a regression introduced in 3.1.2 related to positions reported by error messages.
Depends on:
Used by 851 packages:
AGI, Annotations, Ansi2Html, Aurochs, Barracuda, BioHMM, Biobase, BlogLiterately, Blogdown, Bravo, CLASE, CPL, CarneadesDSL, ClustalParser, Combinatorrent, ConfigFile, ConfigFileTH, Configger, CoreErlang, DBlimited, DarcsHelpers, DisTract, Dung, Elm, Emping, Eq, EtaMOO, FerryCore, Feval, Flippi, Folly, GLM, Gamgine, Ganymede, GenI, Genbank, GroteTrap, GuiHaskell, HAppS-Server, HDBC-postgresql, HJVM, HLearn-classification, HPath, HSFFIG, HStringTemplate, HTTP, HUnit-Plus, HaTeX, HaTeX-meta, HackMail, HandsomeSoup, HasGP, Haschoo, Hashell, HaskellTorrent, Hayoo, Hedi, Holumbus-Searchengine, HostAndPort, Hsed, Hsmtlib, IndentParser, JSON-Combinator, JSONParser, JsContracts, Konf, L-seed, LambdaCalculator, LambdaPrettyQuote, LambdaShell, LslPlus, MFlow, MTGBuilder, MissingH, MonadLab, ParsecTools, ParserFunction, PlslTools, Proper, Pugs, Pup-Events-Client, Pup-Events-Demo, Pup-Events-Server, QuickPlot, RESTng, RJson, RNAdesign, RNAlien, SBench, SVGFonts, SVGPath, Scurry, SelectSequencesFromMSA, ShellCheck, SmtLib, StockholmAlignment, StrappedTemplates, Tablify, Taxonomy, TaxonomyTools, Top, TransformeR, UMM, VKHS, ViennaRNAParser, WURFL, WashNGo, WebBits, WebBits-Html, WeberLogic, Webrexp, WikimediaParser, XMLParser, XMPP, Yocto, abacate, abcnotation, ace, acme-lolcat, adblock2privoxy, adhoc-network, aeson-extra, aeson-parsec-picky, aeson-qq, air-extra, algebra-dag, algebra-sql, alms, alpha, ampersand, amrun, anansi, anatomy, antfarm, apiary-purescript, app-settings, arbtt, arguedit, arx, arxiv, assembler, atndapi, atomo, atp-haskell, attoparsec-parsec, aws-sdk, b9, bamboo, bamboo-theme-mini-html5, baskell, batchd, bbdb, bein, bencode, bert, bibdb, bibtex, bidirectionalization-combined, billeksah-forms, billeksah-main, billeksah-main-static, billeksah-pane, billeksah-services, bio, bioace, biophd, bird, bond, boolexpr, brain-bleep, buchhaltung, buster, buster-gtk, bustle, c0parser, cabal-debian, cabal-graphdeps, cabal-macosx, cabal2doap, cake3, calculator, caldims, caledon, cantor, casui, cedict, cg, cgen, cgi, chatter, chitauri, chuchu, chunks, citeproc-hs, citeproc-hs-pandoc-filter, clafer, claferIG, clckwrks-cli, clevercss, clippings, cmathml3, cmdtheline, cmv, cnc-spec-compiler, codec-libevent, codo-notation, combinatorial-problems, competition, compiler-warnings, config-manager, conjure, console-program, copilot-libraries, copilot-theorem, core, criterion, csv, dapi, darcs, darcs-beta, darcs-buildpackage, darcs-cabalized, darcswatch, dash-haskell, dataflow, datalog, dates, dawdle, dbus, dbus-core, dbus-qq, dcpu16, ddc-base, ddc-core, dead-simple-json, debian, dedukti, deiko-config, deka, deka-tests, dfsbuild, diagrams-contrib, diagrams-haddock, dice, dictparser, diplomacy, diplomacy-server, disassembler, diversity, docopt, doctemplates, docvim, doi, dom-selector, dotfs, dson, dson-parsec, easyjson, ebnf-bff, ecma262, egison, egison-quote, egison-tutorial, ehs, elm-compiler, elm-repl, email, epub-tools, erd, ersatz, exference, extcore, fadno-xml, fasta, fdo-trash, fig, file-command-qq, filestore, flat-tex, flight-igc, flite, flo, flow2dot, fltkhs, formal, format, forml, fptest, fquery, free-theorems-seq, fsmActions, ftphs, funcons-tools, geniconvert, gentlemark, ggtsTC, ghc-core-html, ghc-events-analyze, ghc-imported-from, ghc-man-completion, ghc-pkg-autofix, ghci-history-parser, ginger, ginsu, git-checklist, gitHUD, gitit, gitlib-cmdline, glambda, gmndl, goatee, goatee-gtk, gopherbot, grammar-combinators, graph-rewriting-cl, graph-rewriting-lambdascope, graph-rewriting-ski, graph-rewriting-ww, graph-utils, grm, gsmenu, hLLVM, hScraper, hack-contrib-press, hackage-security, hackage-server, hackport, haggis, hail, hails, hakaru, hako, hakyll, hakyll-contrib-links, happs-tutorial, happstack-helpers, happstack-server, happstack-util, haquery, harchive, harpy, hascat-lib, hascat-system, hask-home, haskeem, haskell-brainfuck, haskell-gettext, haskell-platform-test, haskell-reflect, haskellscrabble, haskelm, haskhol-core, haskintex, haskore, hastily, hatex-guide, hatt, hawitter, haxparse, hbayes, hbro, hbro-contrib, hdigest, hdo, helisp, helium, hellnet, her-lexer-parsec, herbalizer, here, heredocs, hesh, hesql, heterocephalus, hexpr, hexquote, hfoil, hg-buildpackage, hgdbmi, hgeometry, hgom, hi, hiccup, hifi, highlighting-kate, hipe, hist-pl-transliter, hit, hjpath, hjs, hjson, hledger, hledger-lib, hledger-web, hmarkup, hmatrix-static, hmeap, hmeap-utils, hmk, hmt, hmumps, hourglass-fuzzy-parsing, hpaco-lib, hpc-tracer, hpdft, hpodder, hprotoc, hprotoc-fork, hpuz, hpyrg, hquery, hs-gizapp, hs-java, hs-logo, hsc3-rw, hsdip, hsemail, hsemail-ns, hsini, hsmisc, hsnock, hsoptions, hsshellscript, hssqlppp, htoml, http-encodings, http-monad, hugs2yc, hunch, hunit-parsec, hunp, hunt-searchengine, husk-scheme, husky, huttons-razor, hxt, hxt-css, hxt-curl, hxt-filter, hxt-http, hxt-regex-xmlschema, hxt-relaxng, hxt-xpath, hxt-xslt, hybrid, hydrogen-parsing, hydrogen-prelude-parsec, hydrogen-syntax, hydrogen-util, i18n, iCalendar, ideas, ideas-math, ihaskell, ihaskell-parsec, imbib, imparse, implicit, inch, indentation, indentation-parsec, indentparser, indents, infer-upstream, infernu, inline-c, internetmarke, iptables-helpers, iptadmin, ipython-kernel, ircbot, iso8583-bitmaps, iteratee-parsec, ivor, ivory-bitdata, iyql, jmacro, json, json-qq, json2, kaleidoscope, katt, kdesrc-build-extra, keyword-args, khph, kicad-data, kif-parser, kontrakcja-templates, laborantin-hs, labyrinth, labyrinth-server, lambda-calculator, lambda2js, lambdaBase, lambdabot-core, lambdabot-haskell-plugins, lambdabot-misc-plugins, language-asn1, language-bash, language-boogie, language-dockerfile, language-dot, language-ecmascript, language-ecmascript-analysis, language-eiffel, language-fortran, language-glsl, language-go, language-java, language-java-classfile, language-mixal, language-pig, language-puppet, language-qux, language-sh, language-slice, language-typescript, language-webidl, ldif, leksah, leksah-server, lentil, lhae, libGenI, liquid-fixpoint, liquidhaskell, lispparser, lit, live-sequencer, llsd, llvm-general, llvm-general-pure, llvm-pretty, load-env, log2json, logic-classes, logplex-parse, lojban, lol-calculus, lol-typing, ltk, luthor, lvmlib, maccatcher, mackerel-client, maclight, mappy, marvin-interpolate, mathista, maxsharing, mbox-tools, mbox-utility, mediawiki2latex, melody, mi, microstache, midi-utils, mighttpd, mighttpd2, mikrokosmos, miniforth, ministg, ml-w, modelicaparser, modulo, mohws, monadiccp, mongoDB, mprover, mps, msh, msu, mud, multifocal, multipart, multipart-names, multipath, music-score, mustache, mustache-haskell, mustache2hs, mvclient, namelist, nanoAgda, natural-sort, neat, neat-interpolation, needle, netcore, netease-fm, netrc, nettle-openflow, network-dbus, network-hans, network-uri, nextstep-plist, nicify-lib, nixfromnpm, nntp, noise, numeric-prelude, nymphaea, octopus, ofx, onama, only, open-pandoc, openssh-github-keys, optimusprime, orchid, org2anki, orgmode, os-release, ottparse-pretty, panda, pandoc, pandoc-citeproc, paragon, parco-parsec, parse-dimacs, parsec-extra, parsec-free, parsec-numbers, parsec-numeric, parsec-parsers, parsec-permutation, parsec-pratt, parsec-tagsoup, parsec-trace, parsec-utils, parsec3-numbers, parsedate, parseerror-eq, parsely, parsergen, parsers, pb-next, peg, penn-treebank, penny, penny-bin, penny-lib, period, pgm, phoityne, phoityne-vscode, photoname, phybin, pi-calculus, pi-forall, picologic, piki, pisigma, pngload, pngload-fixed, polar-configfile, polyseq, postgrest, postmaster, preprocessor-tools, press, pretty-simple, primula-bot, prof2dot, prolog, proto-lens, protobuf-simple, protocol-buffers, prove-everywhere-server, psc-ide, pseudo-boolean, purescript, puzzle-draw, pxsl-tools, quantities, quoridor-hs, radium, radium-formula-parser, range, rdf4h, really-simple-xml-parser, record-syntax, redHandlers, reflex-jsx, regex-deriv, regex-dfa, regex-parsec, regex-pderiv, regex-tdfa, regex-tdfa-rc, regex-xmlschema, regexchar, regexdot, relative-date, repl, repl-toolkit, repo-based-blog, resolve, riak-protobuf, rl-satton, rlglue, rlwe-challenges, roshask, roundtrip-string, rpf, rsagl, rsagl-math, rss2irc, ruff, ruin, rws, s-cargot, salvia-protocol, scan, scc, scholdoc, scholdoc-citeproc, scholdoc-texmath, scion-browser, scyther-proof, sdf2p1-parser, secd, semver-range, serokell-util, sfnt2woff, sgf, shakespeare, shelltestrunner, show-please, shqq, sifflet, sifflet-lib, simgi, simple-config, simple-eval, simple-nix, simple-pascal, simple-sql-parser, simple-stacked-vm, sindre, sitepipe, smallcaps, snaplet-mongoDB, snippet-extractor, snm, snorkels, sphinxesc, splitter, spoonutil, sprinkles, sqlite-simple-errors, srcinst, sshd-lint, stackage-cabal, stdata, steambrowser, subleq-toolchain, super-user-spark, sylvia, system-uuid, tableaux, taffybar, tagset-positional, tagsoup-parsec, tagsoup-selection, tak, tamarin-prover, tamarin-prover-term, tamarin-prover-theory, tamarin-prover-utils, tasty-integrate, tempered, template-hsml, templatepg, term-rewriting, tex2txt, texmath, text-format-heavy, text-json-qq, text-render, text-xml-qq, th-typegraph, tidal, time-w3c, tkhs, todos, toysolver, tpdb, transformations, treemap-html, treemap-html-tools, tsparse, tttool, turtle-options, twentefp, twentefp-number, twidge, twiml, twine, txt-sushi, typed-wire, typedquery, typescript-docs, uAgda, uni-util, units-parser, uri, urn, urxml, vcswrapper, vimeta, vintage-basic, vision, vty, vty-examples, web-mongrel2, web-routes, web-routes-boomerang, web-routes-regular, web-routes-th, webidl, webserver, while-lang-parser, whiskers, windowslive, wtk-gtk, wxcore, wxdirect, wyvern, xhaskell-library, xhb, xlsx-templater, xml-hamlet, xml-parsec, xmlhtml, xmobar, xmonad-extras, yabi-muno, yamlkeysdiff, yes-precure5-command, yeshql, yesod-bin, yesod-core, yi-core, yices, yocto, yql, yst, yuuko, yxdb-utils, zampolit
comments powered byDisqus