Copyright | (c) 2008 Utrecht University |
---|---|
License | All rights reserved |
Maintainer | stefan@cs.uu.nl |
Stability | provisional |
Portability | non-portable (uses rank-2 types) |
Safe Haskell | Safe |
Language | Haskell98 |
CCO.Parsing
Description
A library of parser combinators that expose their functionality through an
Applicative
interface.
Based on work by Doaitse Swierstra.
- class Symbol s where
- 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
.
Parsers
The type of parsers that consume symbols described by tokens of type s
and produces values of type a
.
Instances
Functor (Parser s) Source | |
Applicative (Parser s) Source | |
Symbol s => Alternative (Parser s) Source |
satisfy :: Symbol s => (s -> Bool) -> Parser s s Source
Produces a Parser
that recognises a single symbol satisfying a given
predicate.
lexeme :: Parser s String Source
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 a infixl 2 Source
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 a infixl 3 Source
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 a Source
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 a Source
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.