Google

>
 HaXmlParentContentsIndex
Text.ParserCombinators.HuttonMeijerWallace
Contents
The parser monad
Primitive parser combinators
Derived combinators
Error handling
State handling
Re-parsing
Description
This library of monadic parser combinators is based on the ones defined by Graham Hutton and Erik Meijer. It has been extended by Malcolm Wallace to use an abstract token type (no longer just a string) as input, and to incorporate a State Transformer monad, useful for symbol tables, macros, and so on. Basic facilities for error reporting have also been added.
Synopsis
data Parser s t a = P (s -> [t] -> [(a, s, [t])])
item :: Parser s t t
papply :: Parser s t a -> s -> [t] -> [(a, s, [t])]
(+++) :: Parser s t a -> Parser s t a -> Parser s t a
tok :: (Eq t) => t -> Parser s (p, t) t
nottok :: (Eq t) => [t] -> Parser s (p, t) t
many :: Parser s t a -> Parser s t [a]
many1 :: Parser s t a -> Parser s t [a]
sepby :: Parser s t a -> Parser s t b -> Parser s t [a]
sepby1 :: Parser s t a -> Parser s t b -> Parser s t [a]
chainl :: Parser s t a -> Parser s t (a -> a -> a) -> a -> Parser s t a
chainl1 :: Parser s t a -> Parser s t (a -> a -> a) -> Parser s t a
chainr :: Parser s t a -> Parser s t (a -> a -> a) -> a -> Parser s t a
chainr1 :: Parser s t a -> Parser s t (a -> a -> a) -> Parser s t a
ops :: [(Parser s t a, b)] -> Parser s t b
bracket :: (Show p, Show t) => Parser s (p, t) a -> Parser s (p, t) b -> Parser s (p, t) c -> Parser s (p, t) b
elserror :: (Show p, Show t) => Parser s (p, t) a -> String -> Parser s (p, t) a
stupd :: (s -> s) -> Parser s t ()
stquery :: (s -> a) -> Parser s t a
stget :: Parser s t s
reparse :: [t] -> Parser s t ()
The parser monad
data Parser s t a
Constructors
P (s -> [t] -> [(a, s, [t])]) The parser type is parametrised on the types of the state s, the input tokens t, and the result value a. The state and remaining input are threaded through the monad.
Instances
Functor (Parser s t)
Monad (Parser s t)
MonadPlus (Parser s t)
Primitive parser combinators
item :: Parser s t t
Deliver the first remaining token.
papply :: Parser s t a -> s -> [t] -> [(a, s, [t])]
Apply the parser to some real input, given an initial state value.
Derived combinators
(+++) :: Parser s t a -> Parser s t a -> Parser s t a
A choice between parsers. Keep only the first success.
tok :: (Eq t) => t -> Parser s (p, t) t
Deliver the first token if it equals the argument.
nottok :: (Eq t) => [t] -> Parser s (p, t) t
Deliver the first token if it does not equal the argument.
many :: Parser s t a -> Parser s t [a]
Deliver zero or more values of a.
many1 :: Parser s t a -> Parser s t [a]
Deliver one or more values of a.
sepby :: Parser s t a -> Parser s t b -> Parser s t [a]
Deliver zero or more values of a separated by b's.
sepby1 :: Parser s t a -> Parser s t b -> Parser s t [a]
Deliver one or more values of a separated by b's.
chainl :: Parser s t a -> Parser s t (a -> a -> a) -> a -> Parser s t a
chainl1 :: Parser s t a -> Parser s t (a -> a -> a) -> Parser s t a
chainr :: Parser s t a -> Parser s t (a -> a -> a) -> a -> Parser s t a
chainr1 :: Parser s t a -> Parser s t (a -> a -> a) -> Parser s t a
ops :: [(Parser s t a, b)] -> Parser s t b
bracket :: (Show p, Show t) => Parser s (p, t) a -> Parser s (p, t) b -> Parser s (p, t) c -> Parser s (p, t) b
Error handling
elserror :: (Show p, Show t) => Parser s (p, t) a -> String -> Parser s (p, t) a
If the parser fails, halt with an error message.
State handling
stupd :: (s -> s) -> Parser s t ()
Update the internal state.
stquery :: (s -> a) -> Parser s t a
Query the internal state.
stget :: Parser s t s
Deliver the entire internal state.
Re-parsing
reparse :: [t] -> Parser s t ()
This is useful for recursively expanding macros. When the user-parser recognises a macro use, it can lookup the macro expansion from the parse state, lex it, and then stuff the lexed expansion back down into the parser.
Produced by Haddock version 0.4