faster-megaparsec: Speed up Megaparsec parsing when parsing succeeds

[ gpl, library, parsing ] [ Propose Tags ]


[Skip to Readme]


[Index] [Quick Jump]


Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


  • No Candidates
Versions [RSS],,,
Change log
Dependencies base (>=4.7 && <5), megaparsec (>=6 && <10), mtl (<2.4) [details]
License GPL-3.0-only
Copyright 2022 Lackmann Phymetric GmbH
Author Olaf Klinke
Category Parsing
Home page
Bug tracker
Source repo head: darcs get
Uploaded by olf at 2022-11-11T15:26:54Z
Downloads 188 total (14 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2022-11-11 [all 1 reports]

Readme for faster-megaparsec-

[back to package description]


This package defines a MonadParsec instance for (a type isomorphic to) StateT s Maybe where s is a Megaparsec Stream type such as String, Text or ByteString. This parser can be faster than Cassava for csv parsing but at the cost of no error information whatsoever.

If, however, you construct your parser in a generic MonadParsec fashion, then with the help of Text.Megaparsec.Simple.tryFast you can first attempt to specialize and run the fast parser supplied by this package and only on parse error specialize the parser to ParsecT and parse again, yielding an informative error message.
This buys you speed in the smooth case of successful parsing at the cost of double parse when something goes wrong.

Beware that the behaviour of a SimpleParser can differ from its Parsec sibling because

  • SimpleParser is always backtracking since it does not know whether it has consumed tokens,
  • any fancy parsing that relies on inspecting parser state components such as offset will not work as intended.