Copyright | © 2015–present 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: 6.5.0
Synopsis
- newtype Hints t = Hints [Set (ErrorItem t)]
- data Reply e s a = Reply (State s e) 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 e -> m b) -> ParseError s e -> State s e -> m b
- accHints :: Hints t -> (a -> State s e -> Hints t -> m b) -> a -> State s e -> Hints t -> m b
- refreshLastHint :: Hints t -> Maybe (ErrorItem t) -> Hints t
- runParsecT :: Monad m => ParsecT e s m a -> State s e -> m (Reply e s a)
- withParsecT :: forall e e' s m a. (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 e) Consumption (Result s e a) |
data Consumption Source #
Whether the parser has failed or not. On success we include the
resulting value, on failure we include a ParseError
.
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 to Hints
.
:: Stream s | |
=> Hints (Token s) | Hints to use |
-> (ParseError s e -> State s e -> m b) | Continuation to influence |
-> ParseError s e | First argument of resulting continuation |
-> State s e | 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 e -> Hints t -> m b) | An “OK” continuation to alter |
-> a -> State s e -> 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.
Transform any custom errors thrown by the parser using the given
function. Similar in function and purpose to withExceptT
.
Note that the inner parser will start with empty collection of
“delayed” ParseError
s. Any delayed ParseError
s produced in the inner
parser will be lifted by applying the provided function and added to the
collection of delayed parse errors of the outer parser.
Since: 7.0.0