Difference between revisions of "Parsec"

From HaskellWiki
Jump to: navigation, search
(A stub for parsec)
 
m (Examples: (added closing parens))
 
(38 intermediate revisions by 20 users not shown)
Line 1: Line 1:
== Parsec ==
 
 
{{Template:Stub}}
   
[[Category:Compiler Tools]]
+
[[Category:Compiler tools]]
  +
[[Category:Combinators]]
  +
[[Category:Packages]]
  +
[[Category:Libraries]]
   
  +
  +
== Introduction ==
 
Parsec is an industrial strength, monadic parser combinator library for
 
Parsec is an industrial strength, monadic parser combinator library for
 
Haskell. It can parse context-sensitive, infinite look-ahead grammars
 
Haskell. It can parse context-sensitive, infinite look-ahead grammars
 
but it performs best on predictive (LL[1]) grammars.
 
but it performs best on predictive (LL[1]) grammars.
   
See [http://www.cs.uu.nl/people/daan/download/parsec/parsec.html the Parsec site]
 
  +
The latest stable release with Haddock documentation is available on [http://hackage.haskell.org/package/parsec Hackage] and development versions are [http://code.haskell.org/parsec3/ available via the Darcs repository].
for downloads and documentation.
 
   
=== Usage ===
 
  +
 
== Usage ==
   
 
Parsec lets you construct parsers by combining higher-order
 
Parsec lets you construct parsers by combining higher-order
[[Combinators]] to create larger expressions. Combinator parsers are
+
[[Combinator]]s to create larger expressions. Combinator parsers are
 
written and used within the same programming language as the rest of the
 
written and used within the same programming language as the rest of the
program. The parsers are first-class citizens of the langugage, unlike
+
program. The parsers are first-class citizens of the language, unlike
 
[[Happy]] parsers, which must be generated via a preprocessor.
 
[[Happy]] parsers, which must be generated via a preprocessor.
   
Much more documentation can be found on the parsec site.
 
  +
An example for parsing a simple grammar of expressions can be found [http://www.haskell.org/haskellwiki/Parsing_expressions_and_statements here].
   
{{Template:Stub}}
 
  +
Much more documentation can be found on [https://web.archive.org/web/20140528151730/http://legacy.cs.uu.nl/daan/parsec.html the parsec website].
  +
  +
== Examples ==
  +
  +
* [http://book.realworldhaskell.org/read/using-parsec.html "Using Parsec"] chapter on [http://book.realworldhaskell.org/ Real World Haskell]. (The JSON examples require revision to work under GHC 7.10.x, and possibly earlier versions. This 2008 publication would benefit from an updated edition.)
  +
  +
* [http://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_Hours/Parsing Write Yourself a Scheme in 48 Hours/Parsing]. Note, that where the example uses the read function, the Token module of Parsec could have been used, to handle numbers.
  +
  +
See also the [http://packdeps.haskellers.com/reverse/parsec list of reverse dependencies for Parsec].
  +
  +
== Parsec clones in other languages ==
  +
  +
* PCL for OCaml [http://lprousnth.files.wordpress.com/2007/08/pcl.pdf] (PDF)
  +
* JParsec for Java [http://jparsec.codehaus.org/JParsec+Overview]
  +
* NParsec, JParsec ported to C# [http://jparsec.codehaus.org/NParsec+Tutorial]
  +
* Ruby Parsec, JParsec ported to Ruby [http://jparsec.codehaus.org/Ruby+Parsec]]
  +
* FParsec for F# [http://www.quanttec.com/fparsec/]
  +
* XParsec for F# [http://corsis.github.com/XParsec/] is a type-and-source-polymorphic, generalized and extensible parsec implementation in F# 3.0 which supports powerful domain-specific non-linear navigation combinators (such as for XML trees)
  +
* Parsec-Erlang [https://bitbucket.org/dmercer/parsec-erlang/], is a faithful reproduction of Parsec in Erlang (there is also an older toy Parsec-like parser that isn't monadic, nor does it give error messages: [http://www.engr.uconn.edu/~jeffm/Source/Erlang/])
  +
* AliceParsec for Alice ML [http://www.ps.uni-sb.de/alice/contribs.html]
  +
* Parsnip for C++ [http://parsnip-parser.sourceforge.net/]
  +
* A Nemerle port [http://kriomant.net/nparsec.zip] (Zip file)
  +
* Pysec for Python [http://www.valuedlessons.com/2008/02/pysec-monadic-combinatoric-parsing-in.html]
  +
* JSParsec for JavaScript: [http://code.google.com/p/jsparsec/]
  +
* Bennu JavaScript Parser Combinator Library: [https://github.com/mattbierner/bennu/]
  +
* ParsecJ for Java [https://github.com/jon-hanson/parsecj/] is implemented in a functional style based on the original Parsec papers.
  +
  +
Interesting non-Parsec parser combinator libraries:
  +
* Parse::RecDescent for Perl [https://metacpan.org/module/Parse::RecDescent]
  +
* Spirit for C++ [http://boost-spirit.com/home/doc/]
  +
  +
== Links ==
  +
 
=== Docs ===
  +
  +
* [http://research.microsoft.com/pubs/65201/parsec-paper-letter.pdf Parsec: Direct Style Monadic Parser Combinators For The Real World] (PDF)
 
* [http://research.microsoft.com/en-us/um/people/daan/download/parsec/parsec.pdf Parsec, a fast combinator parser] (PDF)
  +
  +
=== Blog articles ===
  +
  +
* [http://therning.org/magnus/posts/2007-05-27-289-adventures-in-parsing.html Adventures in Parsing] by Magnus Therning
  +
* [http://therning.org/magnus/posts/2007-05-29-290-more-adventures-in-parsing.html More Adventures in Parsing]
  +
* [http://therning.org/magnus/posts/2007-06-03-295-adventures-in-parsing-part-3.html Adventures in Parsing, Part 3]
  +
* [http://therning.org/magnus/posts/2007-06-05-296-adventures-in-parsing-part-4.html Adventures in Parsing, Part 4]
  +
  +
* [http://panicsonic.blogspot.com/2009/12/adventures-in-parsec.html Adventures in Parsec] by Antoine Latter
  +
  +
* [http://blog.jakubarnold.cz/2014/08/10/parsing-css-with-parsec.html Parsing CSS with Parsec] by Jacub Arnold
  +
  +
=== Other ===
  +
  +
* [https://github.com/JakeWheat/intro_to_parsing Introduction to parsing with Haskell and Parsec]
  +
* [http://stackoverflow.com/questions/tagged/parsec Parsec] on Stack Overflow

Latest revision as of 23:23, 2 January 2016

This article is a stub. You can help by expanding it.


Introduction

Parsec is an industrial strength, monadic parser combinator library for Haskell. It can parse context-sensitive, infinite look-ahead grammars but it performs best on predictive (LL[1]) grammars.

The latest stable release with Haddock documentation is available on Hackage and development versions are available via the Darcs repository.


Usage

Parsec lets you construct parsers by combining higher-order Combinators to create larger expressions. Combinator parsers are written and used within the same programming language as the rest of the program. The parsers are first-class citizens of the language, unlike Happy parsers, which must be generated via a preprocessor.

An example for parsing a simple grammar of expressions can be found here.

Much more documentation can be found on the parsec website.

Examples

  • "Using Parsec" chapter on Real World Haskell. (The JSON examples require revision to work under GHC 7.10.x, and possibly earlier versions. This 2008 publication would benefit from an updated edition.)

See also the list of reverse dependencies for Parsec.

Parsec clones in other languages

  • PCL for OCaml [1] (PDF)
  • JParsec for Java [2]
  • NParsec, JParsec ported to C# [3]
  • Ruby Parsec, JParsec ported to Ruby [4]]
  • FParsec for F# [5]
  • XParsec for F# [6] is a type-and-source-polymorphic, generalized and extensible parsec implementation in F# 3.0 which supports powerful domain-specific non-linear navigation combinators (such as for XML trees)
  • Parsec-Erlang [7], is a faithful reproduction of Parsec in Erlang (there is also an older toy Parsec-like parser that isn't monadic, nor does it give error messages: [8])
  • AliceParsec for Alice ML [9]
  • Parsnip for C++ [10]
  • A Nemerle port [11] (Zip file)
  • Pysec for Python [12]
  • JSParsec for JavaScript: [13]
  • Bennu JavaScript Parser Combinator Library: [14]
  • ParsecJ for Java [15] is implemented in a functional style based on the original Parsec papers.

Interesting non-Parsec parser combinator libraries:

  • Parse::RecDescent for Perl [16]
  • Spirit for C++ [17]

Links

Docs

Blog articles

Other