Copyright | (c) Lackmann Phymetric |
---|---|
License | GPL-3 |
Maintainer | olaf.klinke@phymetric.de |
Stability | experimental |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
This module defines a MonadParsec
instance for
(a type isomorphic to)
where StateT
s Maybe
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 tryFast
you can first attempt to specialize and run the fast parser
supplied by this module 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.
Synopsis
- data SimpleParser s a
- tryFast :: forall s a result. (Applicative result, Stream s) => (Parsec Void s a -> String -> s -> result a) -> (forall p. MonadParsec Void s p => p a) -> String -> s -> result a
- toSimpleParser :: StateT s Maybe a -> SimpleParser s a
- runSimpleParser :: SimpleParser s a -> s -> Maybe (a, s)
Documentation
data SimpleParser s a Source #
This parser type is isomorphic to
StateT s Maybe
but has roughly the same instances as Parsec
.
Since it maintains no state besides the unconsumed input,
it is considerably faster than Parsec
but can be built using the same combinators.
Instances
:: forall s a result. (Applicative result, Stream s) | |
=> (Parsec Void s a -> String -> s -> result a) | function to run if fast parsing fails |
-> (forall p. MonadParsec Void s p => p a) | a generic parser |
-> String | input stream name |
-> s | input stream |
-> result a |
Conversion from/to StateT
toSimpleParser :: StateT s Maybe a -> SimpleParser s a Source #
Use this to implement more parser combinators.
runSimpleParser :: SimpleParser s a -> s -> Maybe (a, s) Source #
Run the SimpleParser
on the given input.
Consider using tryFast
instead if possible.