uu-tc-2015.1.1: Haskell 98 parser combinators for INFOB3TC at Utrecht University

Safe HaskellSafe




The type of parsers

type Parser s r = [s] -> [(r, [s])] Source #

An input string is mapped to a list of successful parses. For each succesful parse, we return the result of type r, and the remaining input string. The input must be a list of symbols.

Elementary parsers

anySymbol :: Parser s s Source #

Parses any single symbol.

satisfy :: (s -> Bool) -> Parser s s Source #

Takes a predicate and returns a parser that parses a single symbol satisfying that predicate.

empty :: Parser s a Source #

Parser for the empty language, i.e., parser that always fails.

failp :: Parser s a Source #

Same as empty; provided for compatibility with the lecture notes.

succeed :: a -> Parser s a Source #

Parser that always succeeds, i.e., for epsilon.

pure :: a -> Parser s a Source #

Same as succeed; provided for compatiblity with the applicative interface.

Parser combinators

(<|>) :: Parser s a -> Parser s a -> Parser s a infixr 3 Source #

Choice between two parsers with the same result type.

(<<|>) :: Foldable t1 => (t2 -> t1 a) -> (t2 -> t1 a) -> t2 -> t1 a infixr 3 Source #

Biased choice. If the left hand side parser succeeds, the right hand side is not considered. Use with care!

(<*>) :: Parser s (b -> a) -> Parser s b -> Parser s a infixl 4 Source #

Sequence of two parsers.

(<$>) :: (a -> b) -> Parser s a -> Parser s b infixl 4 Source #

Map a function over the results of a parser. The <$> combinator can also be defined in terms of succeed and <*>:

f <$> p  =  succeed f <*> p

(>>=) :: Parser s a -> (a -> Parser s b) -> Parser s b infixl 1 Source #

Monadic bind. Do not use this combinator unless absolutely required. Most sequencing can be done with <*>.


look :: Parser s [s] Source #

Returns the rest of the input without consuming anything.

Running parsers

parse :: Parser s a -> [s] -> [(a, [s])] Source #

For compatibility with the "newtype" version of the library: runs a parser on a given string.