hpp-0.6.3: A Haskell pre-processor

Safe HaskellSafe
LanguageHaskell2010

Hpp.Parser

Description

Parsers over streaming input.

Synopsis

Documentation

type Parser m i = ParserT m (Input m [i]) i Source #

A Parser is a bit of state that carries a source of input consisting of a list of values which are either actions in an underlying monad or sequences of inputs. Thus we have chunks of input values with interspersed effects.

type ParserT m src i = StateT (Source m src i) m Source #

A ParserT is a bit of state that carries a source of input.

evalParse :: Monad m => Parser m i o -> [i] -> m o Source #

Evaluate a Parser with a given input stream.

await :: Monad m => ParserT m src i (Maybe i) Source #

awaitJust :: (Monad m, HasError m) => String -> ParserT m src i i Source #

await that throws an error with the given message if no more input is available. This may be used to locate where in a processing pipeline input was unexpectedly exhausted.

replace :: Monad m => i -> ParserT m src i () Source #

Push a value back into a parser's source.

droppingWhile :: Monad m => (i -> Bool) -> ParserT m src i () Source #

Discard all values until one fails to satisfy a predicate. At that point, the failing value is replaced, and the droppingWhile stream stops.

precede :: Monad m => [i] -> ParserT m src i () Source #

Push a stream of values back into a parser's source.

takingWhile :: Monad m => (i -> Bool) -> ParserT m src i [i] Source #

Echo all values until one fails to satisfy a predicate. At that point, the failing value is replaced, and the takingWhile stream stops.

onElements :: Monad m => ParserT m (Input m [[i]]) i r -> Parser m [i] r Source #

A parser on lists of things can embed a parser on things. For example, if we have a parser on lists of words, we can embed a parser on individual words.

onInputSegment :: Monad m => (src -> src) -> ParserT m (Input m src) i () Source #

insertInputSegment :: Monad m => src -> m () -> ParserT m (Input m src) i () Source #

onIsomorphism :: Monad m => (a -> b) -> (b -> Maybe a) -> ParserT m ([b], src) b r -> ParserT m src a r Source #

Given a function with type a -> b, and a partial inverse, b -> Maybe a, we can embed a parser on values of type b in a parser on values of type a.