Copyright | © 2015–2018 Megaparsec contributors © 2007 Paolo Martini © 1999–2001 Daan Leijen |
---|---|
License | FreeBSD |
Maintainer | Mark Karpov <markkarpov92@gmail.com> |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Internal definitions. Versioning rules do not apply here. Please do not rely on these unless you really know what you're doing.
Since: megaparsec-6.5.0
Synopsis
- newtype Hints t = Hints [Set (ErrorItem t)]
- data Reply e s a = Reply (State s) Consumption (Result s e a)
- data Consumption
- data Result s e a
- = OK a
- | Error (ParseError s e)
- newtype ParsecT e s m a = ParsecT {}
- toHints :: Stream s => Int -> ParseError s e -> Hints (Token s)
- withHints :: Stream s => Hints (Token s) -> (ParseError s e -> State s -> m b) -> ParseError s e -> State s -> m b
- accHints :: Hints t -> (a -> State s -> Hints t -> m b) -> a -> State s -> Hints t -> m b
- refreshLastHint :: Hints t -> Maybe (ErrorItem t) -> Hints t
- runParsecT :: Monad m => ParsecT e s m a -> State s -> m (Reply e s a)
- withParsecT :: (Monad m, Ord e') => (e -> e') -> ParsecT e s m a -> ParsecT e' s m a
Data types
Hints
represent a collection of ErrorItem
s to be included into
ParseError
(when it's a TrivialError
) as “expected” message items
when a parser fails without consuming input right after successful parser
that produced the hints.
For example, without hints you could get:
>>>
parseTest (many (char 'r') <* eof) "ra"
1:2: unexpected 'a' expecting end of input
We're getting better error messages with the help of hints:
>>>
parseTest (many (char 'r') <* eof) "ra"
1:2: unexpected 'a' expecting 'r' or end of input
All information available after parsing. This includes consumption of input, success (with returned value) or failure (with parse error), and parser state at the end of parsing.
See also: Consumption
, Result
.
Reply (State s) Consumption (Result s e a) |
data Consumption Source #
This data structure represents an aspect of result of parser's work.
See also: Consumption
, Reply
.
OK a | Parser succeeded |
Error (ParseError s e) | Parser failed |
newtype ParsecT e s m a Source #
is a parser with custom data component of error
ParsecT
e s m ae
, stream type s
, underlying monad m
and return type a
.
Instances
Helper functions
:: Stream s | |
=> Int | Current offset in input stream |
-> ParseError s e | Parse error to convert |
-> Hints (Token s) |
Convert ParseError
record into Hints
.
:: Stream s | |
=> Hints (Token s) | Hints to use |
-> (ParseError s e -> State s -> m b) | Continuation to influence |
-> ParseError s e | First argument of resulting continuation |
-> State s | Second argument of resulting continuation |
-> m b |
makes “error” continuation withHints
hs cc
use given hints hs
.
Note that if resulting continuation gets ParseError
that has custom
data in it, hints are ignored.
:: Hints t |
|
-> (a -> State s -> Hints t -> m b) | An “OK” continuation to alter |
-> a -> State s -> Hints t -> m b | Altered “OK” continuation |
results in “OK” continuation that will add given
hints accHints
hs chs
to third argument of original continuation c
.
Low-level unpacking of the ParsecT
type.