Portability | non-portable (uses rank-2 types) |
---|---|
Stability | provisional |
Maintainer | stefan@cs.uu.nl |
Safe Haskell | Safe-Inferred |
CCO.Parsing
Contents
Description
A library of parser combinators that expose their functionality through an
Applicative
interface.
Based on work by Doaitse Swierstra.
- class Symbol s where
- describe :: s -> String -> String
- data Parser s a
- satisfy :: Symbol s => (s -> Bool) -> Parser s s
- eof :: Symbol s => Parser s ()
- sourcePos :: Parser s SourcePos
- lexeme :: Parser s String
- (<!>) :: Parser s a -> String -> Parser s a
- choice :: Symbol s => [Parser s a] -> Parser s a
- opt :: Symbol s => Parser s a -> a -> Parser s a
- chainl :: Symbol s => Parser s (a -> a -> a) -> Parser s a -> Parser s a
- chainr :: Symbol s => Parser s (a -> a -> a) -> Parser s a -> Parser s a
- manySepBy :: Symbol s => Parser s b -> Parser s a -> Parser s [a]
- someSepBy :: Symbol s => Parser s b -> Parser s a -> Parser s [a]
- parse :: Parser s a -> Symbols s -> Feedback (a, Symbols s)
- parse_ :: Lexer s -> Parser s a -> Source -> String -> Feedback a
Symbols
The class of types that describe input symbols.
A minimal complete definition must supply the method describe
.
Methods
describe :: s -> String -> StringSource
Retrieves a textual description from a value that describes a symbol and the lexeme that constitutes the symbol.
Instances
Symbol Char |
Parsers
The type of parsers that consume symbols described by tokens of type s
and produces values of type a
.
satisfy :: Symbol s => (s -> Bool) -> Parser s sSource
Produces a Parser
that recognises a single symbol satisfying a given
predicate.
lexeme :: Parser s StringSource
A Parser
that produces the next lexeme in the input (without consuming
the associated symbol).
Fails if the end of input has been reached.
(<!>) :: Parser s a -> String -> Parser s aSource
Labels a Parser
with a description of the grammar production it is
associated with.
Used to produce more informative error messages.
Derived combinators
opt :: Symbol s => Parser s a -> a -> Parser s aSource
Produces a Parser
that tries to parse its input with a given argument
chainl :: Symbol s => Parser s (a -> a -> a) -> Parser s a -> Parser s aSource
Produces a Parser
that parses one or more elements chained by a
left-associative operator.
chainr :: Symbol s => Parser s (a -> a -> a) -> Parser s a -> Parser s aSource
Produces a Parser
that parses one or more elements chained by a
right-associative operator.
manySepBy :: Symbol s => Parser s b -> Parser s a -> Parser s [a]Source
Produces a Parser
that parses zero or more elements separated by
specified separator.
someSepBy :: Symbol s => Parser s b -> Parser s a -> Parser s [a]Source
Produces a Parser
that parses one or more elements separated by
specified separator.