faster-megaparsec: Speed up Megaparsec parsing when parsing succeeds

[ gpl, library, parsing ] [ Propose Tags ]

see README.md


[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.0.1, 0.1.1.0, 0.1.2.0
Change log CHANGELOG.md
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
Maintainer olaf.klinke@phymetric.de, olf@aatal-apotheke.de
Category Parsing
Home page https://hub.darcs.net/olf/faster-megaparsec
Bug tracker https://hub.darcs.net/olf/faster-megaparsec/issues
Source repo head: darcs get https://hub.darcs.net/olf/faster-megaparsec
Uploaded by olf at 2022-11-11T15:26:54Z
Distributions
Downloads 167 total (11 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-0.1.2.0

[back to package description]

faster-megaparsec

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.