hpp-0.6.5: A Haskell pre-processor
Safe HaskellSafe-Inferred
LanguageHaskell2010

Hpp.Parser

Description

Parsers over streaming input.

Synopsis

Documentation

type Parser (m :: Type -> Type) 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 :: Type -> Type) 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 :: forall (m :: Type -> Type) src i. Monad m => ParserT m src i (Maybe i) Source #

awaitJust :: forall (m :: Type -> Type) src i. (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 :: forall (m :: Type -> Type) i src. Monad m => i -> ParserT m src i () Source #

Push a value back into a parser's source.

droppingWhile :: forall (m :: Type -> Type) i src. 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 :: forall (m :: Type -> Type) i src. Monad m => [i] -> ParserT m src i () Source #

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

takingWhile :: forall (m :: Type -> Type) i src. 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 :: forall (m :: Type -> Type) i r. 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 :: forall (m :: Type -> Type) src i. Monad m => (src -> src) -> ParserT m (Input m src) i () Source #

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

onIsomorphism :: forall (m :: Type -> Type) a b src r. 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.