Copyright | (c) Marcus Völker 2017 |
---|---|
License | MIT |
Maintainer | marcus.voelker@rwth-aachen.de |
Safe Haskell | Safe |
Language | Haskell2010 |
This module implements LParse's core: The parser data structure, instances of the important typeclasses and functions to run the parser
- data Parser r t a = Parser {}
- check :: Parser Bool t a -> t -> Bool
- parse :: Parser r t a -> t -> (a -> r) -> (String -> r) -> r
- doParse :: Parser (Either String a) t a -> t -> Either String a
- debugParse :: Show a => Parser (IO ()) t a -> t -> IO ()
- debugParse' :: Parser (IO ()) t a -> t -> (a -> IO ()) -> IO ()
Documentation
The Parser structure itself wraps a function from a collection of tokens (collectively of type t) to a double continuation giving back a string in case of an error (the error message) and a pair (a,t) in case of a success (the parsing result and rest of the input)
Arrow (Parser r) Source # | Lifting a function to an arrow applies the function to the input. (***) executes two parsers in parallel, giving both results as a pair (but only if both succeed) |
Category * (Parser r) Source # | The identity parser returns the input. Concatenating two parsers means using the parsing result of the first as tokens for the second |
Monad (Parser r t) Source # | returning a value means building a parser that consumes no input and just gives back the value (i.e. always succeeds)
the bind operator means using the parser, creating a second parser from the result (with the given function) and then parsing with that.
Both parsers successively consume input, i.e. |
Functor (Parser r t) Source # | via Monad/Functor laws |
Applicative (Parser r t) Source # | via Monad/Applicative laws |
Alternative (Parser r t) Source # | an empty parser in the sense of Alternative always fails and throws nothing. Branching between parsers means trying both in a row and taking the first one that succeeds |
MonadPlus (Parser r t) Source # | Defined via Alternative |
check :: Parser Bool t a -> t -> Bool Source #
Runs the parser on the tokens and returns whether the parse succeeded. Results are discarded.
parse :: Parser r t a -> t -> (a -> r) -> (String -> r) -> r Source #
Runs the parser on the tokens, using two functions to run the contained continuation
doParse :: Parser (Either String a) t a -> t -> Either String a Source #
Same as parse
, but giving back the results via Either