hectoparsec-0.1.0.0: Flexible and powerful parser combinators
Copyright(c) comp 2020
LicenseMIT
Maintaineronecomputer00@gmail.com
Stabilitystable
Portabilityportable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Hectoparsec.Primitive

Contents

Description

Primitive definitions and operations for parser combinators.

Synopsis

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.

Constructors

ParserT 

Fields

Instances

Instances details
Stream s => MonadParser s e l (ParserT s e l m) Source # 
Instance details

Defined in Hectoparsec.Primitive

Methods

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 #

getState :: ParserT s e l m (State s) Source #

putState :: State s -> ParserT s e l m () Source #

MonadRWS r w st m => MonadRWS r w st (ParserT s e l m) Source # 
Instance details

Defined in Hectoparsec.Primitive

MonadError err m => MonadError err (ParserT s e l m) Source # 
Instance details

Defined in Hectoparsec.Primitive

Methods

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 # 
Instance details

Defined in Hectoparsec.Primitive

Methods

ask :: ParserT s e l m r Source #

local :: (r -> r) -> ParserT s e l m a -> ParserT s e l m a Source #

reader :: (r -> a) -> ParserT s e l m a Source #

MonadState st m => MonadState st (ParserT s e l m) Source # 
Instance details

Defined in Hectoparsec.Primitive

Methods

get :: ParserT s e l m st Source #

put :: st -> ParserT s e l m () Source #

state :: (st -> (a, st)) -> ParserT s e l m a Source #

MonadWriter w m => MonadWriter w (ParserT s e l m) Source # 
Instance details

Defined in Hectoparsec.Primitive

Methods

writer :: (a, w) -> ParserT s e l m a Source #

tell :: w -> ParserT s e l m () Source #

listen :: ParserT s e l m a -> ParserT s e l m (a, w) Source #

pass :: ParserT s e l m (a, w -> w) -> ParserT s e l m a Source #

MonadTrans (ParserT s e l) Source # 
Instance details

Defined in Hectoparsec.Primitive

Methods

lift :: Monad m => m a -> ParserT s e l m a Source #

MonadFail (ParserT s e l m) Source # 
Instance details

Defined in Hectoparsec.Primitive

Methods

fail :: String -> ParserT s e l m a Source #

MonadIO m => MonadIO (ParserT s e l m) Source # 
Instance details

Defined in Hectoparsec.Primitive

Methods

liftIO :: IO a -> ParserT s e l m a Source #

Alternative (ParserT s e l m) Source #

Allows for branching parsers. The empty parser will always fail.

Note that p <|> q will only try q if p fails and did not consume any input. For parsers p that consume input, they can be backtracked to allow the next parser to be attempted using try p.

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.

Instance details

Defined in Hectoparsec.Primitive

Methods

empty :: ParserT s e l m a Source #

(<|>) :: ParserT s e l m a -> ParserT s e l m a -> ParserT s e l m a Source #

some :: ParserT s e l m a -> ParserT s e l m [a] Source #

many :: ParserT s e l m a -> ParserT s e l m [a] Source #

Applicative (ParserT s e l m) Source # 
Instance details

Defined in Hectoparsec.Primitive

Methods

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 # 
Instance details

Defined in Hectoparsec.Primitive

Methods

fmap :: (a -> b) -> ParserT s e l m a -> ParserT s e l m b Source #

(<$) :: a -> ParserT s e l m b -> ParserT s e l m a Source #

Monad (ParserT s e l m) Source # 
Instance details

Defined in Hectoparsec.Primitive

Methods

(>>=) :: ParserT s e l m a -> (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 b Source #

return :: a -> ParserT s e l m a Source #

MonadPlus (ParserT s e l m) Source #

Equivalent to the Alternative instance.

Instance details

Defined in Hectoparsec.Primitive

Methods

mzero :: ParserT s e l m a Source #

mplus :: ParserT s e l m a -> ParserT s e l m a -> ParserT s e l m a Source #

MonadCont m => MonadCont (ParserT s e l m) Source # 
Instance details

Defined in Hectoparsec.Primitive

Methods

callCC :: ((a -> ParserT s e l m b) -> ParserT s e l m a) -> ParserT s e l m a 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 string.

Instance details

Defined in Hectoparsec.Primitive

Methods

fromString :: String -> ParserT s e l m a Source #

Monoid a => Monoid (ParserT s e l m a) Source #

Lifts the underlying Monoid into the parser.

Instance details

Defined in Hectoparsec.Primitive

Methods

mempty :: ParserT s e l m a Source #

mappend :: ParserT s e l m a -> ParserT s e l m a -> ParserT s e l m a Source #

mconcat :: [ParserT s e l m a] -> ParserT s e l m a Source #

Semigroup a => Semigroup (ParserT s e l m a) Source #

Lifts the underlying Semigroup into the parser.

Instance details

Defined in Hectoparsec.Primitive

Methods

(<>) :: ParserT s e l m a -> ParserT s e l m a -> ParserT s e l m a Source #

sconcat :: NonEmpty (ParserT s e l m a) -> ParserT s e l m a Source #

stimes :: Integral b => b -> ParserT s e l m a -> ParserT s e l m a Source #

type Parser s e l = ParserT s e l Identity Source #

The ParserT type specialized to the Identity monad.

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.

data Reply s e l a Source #

The reply after parsing.

Constructors

Reply 

Fields

makeParserT :: Monad m => (State s -> m (Reply s e l a)) -> ParserT s e l m a Source #

Creates a parser based on a reply.

contParserT :: Monad m => ParserT s e l m a -> State s -> m (Reply s e l a) Source #

Runs a parser and retrieve the reply.