uu-tc-error-0.3.0.0: Haskell 98 parser combintors for INFOB3TC at Utrecht University
Safe HaskellSafe-Inferred
LanguageHaskell2010

ParseLib.Simple.Core

Description

If you are only interested in full parses of some parser p, enforce full parses on the Parser level using the eof combinator as in parse (p <* eof) input. This ensures error reporting.

Report bugs to gitlab or p.rednaz@googlemail.com, please.

Synopsis

The type of parsers

type Parser s r = [s] -> ([(r, [s])], DifferenceList (ParseError [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.

expected :: [s] -> Parser s a Source #

Parser combinators

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

Choice between two parsers with the same result type.

(<<|>) :: Parser s a -> Parser s a -> Parser s 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 <*>.

Lookahead

look :: Parser s [s] Source #

Returns the rest of the input without consuming anything.

Running parsers

parseAndTrace :: (ErrorsPretty s, Ord s) => Config -> Parser s a -> [s] -> [(a, [s])] Source #

Runs a parser on a given string printing error messages to standard error (stderr).

The ErrorsPretty constraint is automatically fulfilled by Show instances. But if you see the following GHC error, you usually need to add an (ErrorsPretty s) constraint to your function and import ParseLib.Error (ErrorsPretty).

Overlapping instances for ErrorsPretty s
arising from a use of ‘parseAndTrace’

ErrorsPretty is not defined in this package but in uu-tc-error-error. We did this so you can switch back and forth between this library and uu-tc without the need to remove ErrorsPretty constraints from your code. Just permanently keep uu-tc-error-error in your .cabal file. It does not conflict with uu-tc because there are no module name collisions.

parseWithConfig :: Ord s => Config -> Parser s a -> [s] -> Either (ParseErrorBundle [s]) (NonEmpty (a, [s])) Source #

Runs a parser on a given string. Pretty print the error information with errorBundlePrettyImproved.

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

Runs a parser on a given string printing error messages to standard error (stderr).

Notice that, when using parse, you might need to add Ord and ErrorsPretty constraints to your own functions and ensure your own data types are deriving (Ord, Show).

The ErrorsPretty constraint is automatically fulfilled by Show instances. But if you see the following GHC error, you usually need to add an (ErrorsPretty s) constraint to your function and import ParseLib.Error (ErrorsPretty).

Overlapping instances for ErrorsPretty s
arising from a use of ‘parse’

ErrorsPretty is not defined in this package but in uu-tc-error-error. We did this so you can switch back and forth between this library and uu-tc without the need to remove ErrorsPretty constraints from your code. Just permanently keep uu-tc-error-error in your .cabal file. It does not conflict with uu-tc because there are no module name collisions.