encyclopegia.org

Parsec (parser)

Parsec is a library for writing parsers written in the programming language Haskell. It is based on higher-order parser combinators, so a complicated parser can be made out of many smaller ones. It has been reimplemented in many other languages, including Erlang, Elixir, OCaml, Racket, F#, and the imperative programming languages C#, and Java. Because a parser combinator-based program is generally slower than a parser generator-based program, Parsec is normally used for small domain-specific languages, while Happy is used for compilers such as the Glasgow Haskell Compiler (GHC). Other Haskell parser combinator libraries that have been derived from Parsec include Megaparsec and Attoparsec. Parsec is free software released under the BSD-3-Clause license.

Parsec is a library for writing parsers written in the programming language Haskell. It is based on higher-order parser combinators, so a complicated parser can be made out of many smaller ones. It has been reimplemented in many other languages, including Erlang, Elixir, OCaml, Racket, F#, and the imperative programming languages C#, and Java. Because a parser combinator-based program is generally slower than a parser generator-based program, Parsec is normally used for small domain-specific languages, while Happy is used for compilers such as the Glasgow Haskell Compiler (GHC). Other Haskell parser combinator libraries that have been derived from Parsec include Megaparsec and Attoparsec. Parsec is free software released under the BSD-3-Clause license. Parser combinator libraries like Parsec provide utility functions to run the parsers on real values. A parser to recognize a single digit from a string can be split into two functions: one to create the parser, and a main function that calls one of these utility functions ( parse in this case) to run the parser: import Text.Parsec -- has general parsing utility functions import Text.Parsec.Char -- contains specific basic combinators type Parser = Stream s m Char => ParsecT s u m String parser :: Parser parser = string "hello" main :: IO () main = print (parse parser " " "hello world") -- prints 'Right "hello"' We define a Parser type to make the type signature of parser easier to read. If we wanted to alter this program, say to read either the string "hello" or the string "goodbye" , we could use the operator , provided by the Alternative typeclass, to combine two parsers into a single parser that tries either: parser = string "hello" string "goodbye" ==References== ==External links== Parsec on the Haskell wiki Parsec on Hackage

References

No reference rows published for this article.

Cite this article

MLA

"Parsec (parser)." encyclopegia.org, 2026, https://encyclopegia.org/wiki/parsec-parser. Accessed 24 November 2026.

Chicago

"Parsec (parser)." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/parsec-parser.

APA

encyclopegia.org. (2026). Parsec (parser). Retrieved November 24, 2026, from https://encyclopegia.org/wiki/parsec-parser

Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

Parsec

stub · references available

parser combinator

stub · references available

Scannerless Boolean Parser

stub · references available

Help:Switch parser function

stub · references available

packrat parser

stub · references available

Earley parser

enwiki · references available

LALR parser

enwiki · references available

LR parser

enwiki · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1334836044 · 0.5 · snapshot enwiki-001334836044

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.