flatparse-0.5.1.0: High-performance parsing from strict bytestrings
Safe HaskellSafe-Inferred
LanguageHaskell2010

FlatParse.Stateful.Parser

Description

Minimal parser definition.

Synopsis

Parser

newtype ParserT (st :: ZeroBitType) r e a Source #

ParserT st r e a is a parser with a state token type st, a reader environment r, an error type e and a return type a. The different state token types support different embedded effects; see Parser, ParserIO and ParserST below.

Constructors

ParserT 

Fields

Instances

Instances details
MonadIO (ParserT IOMode r e) Source #

You may lift IO actions into a ParserIO using liftIO.

Instance details

Defined in FlatParse.Stateful.Parser

Methods

liftIO :: IO a -> ParserT IOMode r e a #

Alternative (ParserT st r e) Source # 
Instance details

Defined in FlatParse.Stateful.Parser

Methods

empty :: ParserT st r e a #

(<|>) :: ParserT st r e a -> ParserT st r e a -> ParserT st r e a #

some :: ParserT st r e a -> ParserT st r e [a] #

many :: ParserT st r e a -> ParserT st r e [a] #

Applicative (ParserT st r e) Source # 
Instance details

Defined in FlatParse.Stateful.Parser

Methods

pure :: a -> ParserT st r e a #

(<*>) :: ParserT st r e (a -> b) -> ParserT st r e a -> ParserT st r e b #

liftA2 :: (a -> b -> c) -> ParserT st r e a -> ParserT st r e b -> ParserT st r e c #

(*>) :: ParserT st r e a -> ParserT st r e b -> ParserT st r e b #

(<*) :: ParserT st r e a -> ParserT st r e b -> ParserT st r e a #

Functor (ParserT st r e) Source # 
Instance details

Defined in FlatParse.Stateful.Parser

Methods

fmap :: (a -> b) -> ParserT st r e a -> ParserT st r e b #

(<$) :: a -> ParserT st r e b -> ParserT st r e a #

Monad (ParserT st r e) Source # 
Instance details

Defined in FlatParse.Stateful.Parser

Methods

(>>=) :: ParserT st r e a -> (a -> ParserT st r e b) -> ParserT st r e b #

(>>) :: ParserT st r e a -> ParserT st r e b -> ParserT st r e b #

return :: a -> ParserT st r e a #

MonadPlus (ParserT st r e) Source # 
Instance details

Defined in FlatParse.Stateful.Parser

Methods

mzero :: ParserT st r e a #

mplus :: ParserT st r e a -> ParserT st r e a -> ParserT st r e a #

type Parser = ParserT PureMode Source #

The type of pure parsers.

type ParserIO = ParserT IOMode Source #

The type of parsers which can embed IO actions.

type ParserST s = ParserT (STMode s) Source #

The type of parsers which can embed ST actions.

pureLazy :: a -> ParserT st r e a Source #

Same as pure for ParserT except that it does not force the returned value.

Result

type Res# (st :: ZeroBitType) e a = (# st, ResI# e a #) Source #

Primitive parser result wrapped with a state token.

You should rarely need to manipulate values of this type directly. Use the provided bidirectional pattern synonyms OK#, Fail# and Err#.

pattern OK# :: (st :: ZeroBitType) -> a -> Addr# -> Int# -> Res# st e a Source #

Res# constructor for a successful parse. Contains the return value, a pointer to the rest of the input buffer, and the next Int state, plus a state token.

pattern Err# :: (st :: ZeroBitType) -> e -> Res# st e a Source #

Res# constructor for errors which are by default non-recoverable. Contains the error, plus a state token.

pattern Fail# :: (st :: ZeroBitType) -> Res# st e a Source #

Res# constructor for recoverable failure. Contains only a state token.

Internal

type ResI# e a = (# (# a, Addr#, Int# #) | (# #) | (# e #) #) Source #

Primitive parser result.

Choice operator (defined with right associativity)

(<|>) :: ParserT st r e a -> ParserT st r e a -> ParserT st r e a infixr 6 Source #

Choose between two parsers. If the first parser fails, try the second one, but if the first one throws an error, propagate the error. This operation can arbitrarily backtrack.

Note: this exported operator has different fixity than the same operator in Applicative. Hide this operator if you want to use the Alternative version.