uu-tc-2009.2.2: Haskell 98 parser combintors for INFOB3TC at Utrecht University

ParseLib.Parallel.Derived

Contents

Synopsis

Documentation

Derived combinators

(<$) :: b -> Parser s a -> Parser s bSource

Variant of <$> that ignores the result of the parser.

 f <$ p = const f <$> p

(<*) :: Parser s a -> Parser s b -> Parser s aSource

Variant of <*> that ignores the result of the right argument.

 f <* p = const <$> p <*> q

(*>) :: Parser s a -> Parser s b -> Parser s bSource

Variant of *> that ignores the result of the left argument.

 f *> p = flip const <$> p <*> q

epsilon :: Parser s ()Source

Parser for epsilon that does return '()'.

symbol :: Eq s => s -> Parser s sSource

Parses a specific given symbol.

token :: Eq s => [s] -> Parser s [s]Source

Parses a specific given sequence of symbols.

pack :: Parser s a -> Parser s b -> Parser s c -> Parser s bSource

Takes three parsers: a delimiter, the parser for the content, and another delimiter. Constructs a sequence of the three, but returns only the result of the enclosed parser.

sequence :: [Parser s a] -> Parser s [a]Source

Takes a list of parsers and combines them in sequence, returning a list of results.

choice :: [Parser s a] -> Parser s aSource

Takes a list of parsers and combines them using choice.

EBNF parser combinators

option :: Parser s a -> a -> Parser s aSource

Parses an optional element. Takes the default value as its second argument.

optional :: Parser s a -> Parser s (Maybe a)Source

Variant of option that returns a Maybe, provided for compatibility with the applicative interface.

many :: Parser s a -> Parser s [a]Source

Parses many, i.e., zero or more, occurrences of a given parser.

some :: Parser s a -> Parser s [a]Source

Parser some, i.e., one or more, occurrences of a given parser.

many1 :: Parser s a -> Parser s [a]Source

Same as some. Provided for compatibility with the lecture notes.

listOf :: Parser s a -> Parser s b -> Parser s [a]Source

Takes a parser p and a separator parser s. Parses a sequence of ps that is separated by ss.

Chain expression combinators

chainr :: Parser s a -> Parser s (a -> a -> a) -> Parser s aSource

Takes a parser pe and an operator parser po. Parses a sequence of pes separated by pos. The results are combined using the operator associated with po in a right-associative way.

chainl :: Parser s a -> Parser s (a -> a -> a) -> Parser s aSource

Takes a parser pe and an operator parser po. Parses a sequence of pes separated by pos. The results are combined using the operator associated with po in a left-associative way.

Greedy parsers

greedy :: Parser s b -> Parser s [b]Source

Greedy variant of many.

greedy1 :: Parser s b -> Parser s [b]Source

Greedy variant of many1.

End of input

eof :: Parser s ()Source

Succeeds only on the end of the input.