simple-parser-0.2.2: Simple parser combinators

SimpleParser.Parser

Description

ParserT is the core monad transformer for parsing.

Synopsis

# Documentation

newtype ParserT e s m a Source #

A ParserT is a stateerrorlist transformer useful for parsing. All MTL instances are for this transformer only. If, for example, your effect has its own MonadState instance, you'll have to use 'lift get' instead of get.

Constructors

 ParserT FieldsrunParserT :: s -> ListT m (ParseResult e s a)

#### Instances

Instances details

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

Use Parser if you have no need for other monadic effects.

runParser :: Parser e s a -> s -> [ParseResult e s a] Source #

Runs a non-effectful parser from an inital state and collects all results.

filterParser :: Monad m => (a -> Bool) -> ParserT e s m a -> ParserT e s m a Source #

Filters parse results

reflectParser :: Monad m => ParserT e s m a -> ParserT e s m (ParseValue e a) Source #

A kind of "catch" that returns all results, success and failure.

branchParser :: (Foldable f, Monad m) => f (ParserT e s m a) -> ParserT e s m a Source #

Combines the results of many parsers. Equvalent to asum.

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

If the parse results in ANY successes, keep only those. Otherwise return all failures. This may block indefinitely as it awaits either the end of the parser or its first success. See isolateParser if you want only one success.

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

If the parse results in ANY successes, keep only THE FIRST. Otherwise return all failures. This may block indefinitely as it awaits either the end of the parser or its first success. See suppressParser if you want all successes.

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

If the parser yields no results (success or failure), yield a given value.

optionalParser :: Monad m => ParserT e s m a -> ParserT e s m (Maybe a) Source #

A parser that yields Nothing if there are no results (success or failure), otherwise wrapping successes in Just.

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

Removes all failures from the parse results. Equivalent to 'catchError (const empty)'.

greedyStarParser :: Monad m => ParserT e s m a -> ParserT e s m [a] Source #

Yields the LONGEST string of 0 or more successes of the given parser (and passes through failures).

greedyStarParser_ :: Monad m => ParserT e s m a -> ParserT e s m () Source #

Same as greedyStarParser but discards the result.

greedyPlusParser :: Monad m => ParserT e s m a -> ParserT e s m [a] Source #

Yields the LONGEST string of 1 or more successes of the given parser (and passes through failures).

greedyPlusParser_ :: Monad m => ParserT e s m a -> ParserT e s m () Source #

Same as greedyPlusParser but discards the result.

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

Yield the results of the given parser, but rewind back to the starting state. Note that these results may contain errors, so you may want to stifle them with silenceParser, for example.