Industrial-strength monadic parser combinators for Haskell
open sourceBSD-2-Clausefree
Megaparsec is a monadic parser combinator library for Haskell that aims to balance speed, flexibility and the quality of parse errors. It has everything Parsec-style libraries offer, plus combinators to end parsing with a custom error, recover from errors and carry on, and observe errors without stopping, and fast primitives such as tokens and takeWhileP that make it about as fast as Attoparsec when written carefully. It parses String, ByteString and Text out of the box, custom token streams through a type class, and has typed, custom error messages that can report several errors at once. Its lexer module helps with white space, comments and indentation.
Problems it solves
- write a parser in Haskell that gives users clear error messages
- parse a configuration or programming language in Haskell and keep going after the first error
- get Attoparsec-like speed from a parser library with better errors
Features
- Monadic parser combinators built around the MonadParsec type class
- Recovers from parse errors and reports several at once
- Typed, custom parse errors whose position can differ from the current offset
- Fast tokens, takeWhileP and takeP primitives
- Parses String, ByteString, Text and custom token streams
- Lexer modules for white space, comments, indentation and binary data
Alternatives
The same job
These do what Megaparsec does.
- parsec Monadic parser combinators
- parser-combinators Common Haskell parser combinators with no dependencies beyond base
