Copyright | (c) comp 2020 |
---|---|
License | MIT |
Maintainer | onecomputer00@gmail.com |
Stability | stable |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Primitive definitions and operations for parser combinators.
Synopsis
- newtype ParserT s e l m a = ParserT {
- unParserT :: Continuations s e l m a
- type Parser s e l = ParserT s e l Identity
- type ThenOk s l m a r = a -> [l] -> State s -> m r
- type ThenErr s e l m r = ParseError s e l -> State s -> m r
- type Continuations s e l m a = forall r. State s -> ThenOk s l m a r -> ThenErr s e l m r -> ThenOk s l m a r -> ThenErr s e l m r -> m r
- data Reply s e l a = Reply {
- replyState :: !(State s)
- replyConsumed :: !Bool
- replyResult :: !(Either (ParseError s e l) a)
- makeParserT :: Monad m => (State s -> m (Reply s e l a)) -> ParserT s e l m a
- contParserT :: Monad m => ParserT s e l m a -> State s -> m (Reply s e l a)
Parser types
newtype ParserT s e l m a Source #
The type of a parser for a stream s
, using custom errors e
and custom labels l
.
If custom errors or custom labels are not needed, you can simply set it to Void
to ignore it. Generally,
if your parser cannot error, you would do so. Otherwise, you should set the error and label types to something that
would allow you to create useful error messages. In particular, labels are tracked in order to create a list of
expected items whenever parsers fail.
ParserT
implements MonadParser
for the primitive parser combinators, Alternative
for branching parsers, and the
usual stack of Functor
, Applicative
, and Monad
, along with the classes from mtl
.
ParserT | |
|
Instances
Stream s => MonadParser s e l (ParserT s e l m) Source # | |
Defined in Hectoparsec.Primitive matchToken :: (Maybe (Token s) -> Either (ErrorItem s e l) a) -> ParserT s e l m a Source # matchTokens :: Int -> (Chunk s -> Either (ErrorItem s e l) a) -> ParserT s e l m a Source # matchTokenWhile :: (Token s -> Bool) -> (Chunk s -> Either (ErrorItem s e l) a) -> ParserT s e l m a Source # endOfInput :: ParserT s e l m () Source # withLabel :: Maybe l -> ParserT s e l m a -> ParserT s e l m a Source # try :: ParserT s e l m a -> ParserT s e l m a Source # lookAhead :: ParserT s e l m a -> ParserT s e l m a Source # notFollowedBy :: ParserT s e l m a -> ParserT s e l m () Source # recover :: (ParseError s e l -> ParserT s e l m a) -> ParserT s e l m a -> ParserT s e l m a Source # observing :: ParserT s e l m a -> ParserT s e l m (Either (ParseError s e l) a) Source # parseError :: ParseError s e l -> ParserT s e l m a Source # | |
MonadRWS r w st m => MonadRWS r w st (ParserT s e l m) Source # | |
Defined in Hectoparsec.Primitive | |
MonadError err m => MonadError err (ParserT s e l m) Source # | |
Defined in Hectoparsec.Primitive throwError :: err -> ParserT s e l m a Source # catchError :: ParserT s e l m a -> (err -> ParserT s e l m a) -> ParserT s e l m a Source # | |
MonadReader r m => MonadReader r (ParserT s e l m) Source # | |
MonadState st m => MonadState st (ParserT s e l m) Source # | |
MonadWriter w m => MonadWriter w (ParserT s e l m) Source # | |
MonadTrans (ParserT s e l) Source # | |
MonadFail (ParserT s e l m) Source # | |
MonadIO m => MonadIO (ParserT s e l m) Source # | |
Alternative (ParserT s e l m) Source # | Allows for branching parsers. The Note that In general, if any branch comsumes input, regardless of success, that branch will be commited to, and error messages will be based entirely on that branch. |
Applicative (ParserT s e l m) Source # | |
Defined in Hectoparsec.Primitive pure :: a -> ParserT s e l m a Source # (<*>) :: ParserT s e l m (a -> b) -> ParserT s e l m a -> ParserT s e l m b Source # liftA2 :: (a -> b -> c) -> ParserT s e l m a -> ParserT s e l m b -> ParserT s e l m c Source # (*>) :: ParserT s e l m a -> ParserT s e l m b -> ParserT s e l m b Source # (<*) :: ParserT s e l m a -> ParserT s e l m b -> ParserT s e l m a Source # | |
Functor (ParserT s e l m) Source # | |
Monad (ParserT s e l m) Source # | |
MonadPlus (ParserT s e l m) Source # | Equivalent to the |
MonadCont m => MonadCont (ParserT s e l m) Source # | |
(Stream s, IsString a, Eq a, a ~ Chunk s) => IsString (ParserT s e l m a) Source # | Allows for overloaded string literals to become parsers. This is equivalent to calling |
Defined in Hectoparsec.Primitive fromString :: String -> ParserT s e l m a Source # | |
Monoid a => Monoid (ParserT s e l m a) Source # | Lifts the underlying |
Semigroup a => Semigroup (ParserT s e l m a) Source # | Lifts the underlying |
type ThenOk s l m a r = a -> [l] -> State s -> m r Source #
Continuation for a successful parse. The labels are used for tracking what was expected.
type ThenErr s e l m r = ParseError s e l -> State s -> m r Source #
Continuation for a failed parse.
type Continuations s e l m a = forall r. State s -> ThenOk s l m a r -> ThenErr s e l m r -> ThenOk s l m a r -> ThenErr s e l m r -> m r Source #
Continuations for a parser. ParserT
uses this for performance reasons.
The reply after parsing.
Reply | |
|