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: 6.5.0
- newtype Hints t = Hints [Set (ErrorItem t)]
- data Reply e s a = Reply (State s) Consumption (Result (Token s) e a)
- data Consumption
- data Result t e a
- = OK a
- | Error (ParseError t e)
- newtype ParsecT e s m a = ParsecT {}
- toHints :: NonEmpty SourcePos -> ParseError t e -> Hints t
- withHints :: Ord (Token s) => Hints (Token s) -> (ParseError (Token s) e -> State s -> m b) -> ParseError (Token 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)
Data types
Hints
represent a collection of ErrorItem
s to be included into
ParserError
(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 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 (Token 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 t 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
.
(Ord e, Stream s) => MonadParsec e s (ParsecT e s m) Source # | |
(Stream s, MonadState st m) => MonadState st (ParsecT e s m) Source # | |
(Stream s, MonadReader r m) => MonadReader r (ParsecT e s m) Source # | |
(Stream s, MonadError e' m) => MonadError e' (ParsecT e s m) Source # | |
MonadTrans (ParsecT e s) Source # | |
Stream s => Monad (ParsecT e s m) Source # |
|
Functor (ParsecT e s m) Source # | |
(Stream s, MonadFix m) => MonadFix (ParsecT e s m) Source # | Since: 6.0.0 |
Stream s => MonadFail (ParsecT e s m) Source # | |
Stream s => Applicative (ParsecT e s m) Source # |
|
(Stream s, MonadIO m) => MonadIO (ParsecT e s m) Source # | |
(Ord e, Stream s) => Alternative (ParsecT e s m) Source # |
|
(Ord e, Stream s) => MonadPlus (ParsecT e s m) Source # |
|
(Stream s, MonadCont m) => MonadCont (ParsecT e s m) Source # | |
((~) * a (Tokens s), IsString a, Eq a, Stream s, Ord e) => IsString (ParsecT e s m a) Source # | Since: 6.3.0 |
(Stream s, Semigroup a) => Semigroup (ParsecT e s m a) Source # | Since: 5.3.0 |
(Stream s, Monoid a) => Monoid (ParsecT e s m a) Source # | Since: 5.3.0 |
Helper functions
toHints :: NonEmpty SourcePos -> ParseError t e -> Hints t Source #
Convert ParseError
record into Hints
.
:: Ord (Token s) | |
=> Hints (Token s) | Hints to use |
-> (ParseError (Token s) e -> State s -> m b) | Continuation to influence |
-> ParseError (Token s) e | First argument of resulting continuation |
-> State s | Second argument of resulting continuation |
-> m b |
withHints hs c
makes “error” continuation c
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 | First argument of resulting continuation |
-> State s | Second argument of resulting continuation |
-> Hints t | Third argument of resulting continuation |
-> m b |
accHints hs c
results in “OK” continuation that will add given hints
hs
to third argument of original continuation c
.