Create parsers from grammars statically (at compile time).
- mkStaticParser :: (Typeable a, ToPat t, Token t, Lift t) => Grammar t a -> ExpQ -> ExpQ
- class ToPat a where
- toConstrPat :: (Token t, Lift t) => t -> PatQ
- type ParseResult t a = Either (ParseError t) a
- type Parser t a = [t] -> ParseResult t a
- data ParseError t
- showError :: Show t => ParseError t -> String
- parse :: Show t => Parser t a -> [t] -> a
|:: (Typeable a, ToPat t, Token t, Lift t)|
|=> Grammar t a|
The Template Haskell representation of the grammar
The representation of a parser of type
Make a static parser from a grammar.
g :: Grammar s a gparser = $(mkStaticParser g [|g|])
gparser must be in a different module than
g, due to
Template Haskell restrictions.
The token type of the grammar must also be an instance of
ToPat, and the
result type an instance of
Typeable (the GHC extension
DeriveDataTypeable may be useful for this).
If there are conflicts in the parsing tables, they will be displayed as warnings when compiling the parser.
Make a Template Haskell pattern from a value.
This is used to create a case expression from a parsing table when using
mkStaticParser, and it is thus required that the token type that the
parser is to operate on is an instance of this class.
Automatically create a
ToPat instance which only compares the constructor
of the token type. For example, the pattern yielded from using this on the
Just 3 is the pattern
instance ToPat TokenType where toPat = toConstrPat
The different kinds of errors that can occur
The parser did not get an accepted string of tokens.
This should not happen. Please file a bug report if it does.
Make a prettier error string from a
This shows the position as an index into the input string of tokens, which
may not always be preferable, as that position may differ to the position
in the input if it is first processed by a lexer.
It also shows the expected tokens.