Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- type Nt = Text
- data Prod t = Prod Nt (Symbols t)
- type Prods t = [Prod t]
- type Grammar t = (Nt, Prods t)
- data Slot t = Slot Nt [Symbol t] [Symbol t]
- data Symbol t
- type Symbols t = [Symbol t]
- data Token
- type Tokens = [Token]
- class (Ord a, Eq a, Show a) => Parseable a where
- class SubsumesToken a where
- unlexTokens :: [Token] -> String
- unlexToken :: Token -> String
- isNt :: Symbol t -> Bool
- isTerm :: Symbol t -> Bool
Documentation
A production binds a nonterminal identifier (left-hand side) to a list of symbols (the right-hand side of the production).
A grammar slot acts as a label to identify progress of matching a production. As such, a slot is a Prod with its right-hand side split in two: a part before and a part after 'the dot'. The dot indicates which part of the right-hand side has been processed thus far.
A Symbol
is either a nonterminal or a terminal,
where a terminal contains some arbitrary token.
A datatype for representing tokens with some builtins and an aribitrary Token constructor. This datatype stores (optional) lexemes.
Char Char | |
Keyword String | |
EOS | |
Epsilon | |
IntLit (Maybe Int) | |
FloatLit (Maybe Double) | |
BoolLit (Maybe Bool) | |
StringLit (Maybe String) | |
CharLit (Maybe Char) | |
IDLit (Maybe String) | |
AltIDLit (Maybe String) | alternative identifiers, for example functions vs. constructors (as in Haskell). |
Token String (Maybe String) |
class (Ord a, Eq a, Show a) => Parseable a where Source #
Class that captures elements of an input string (tokens).
Both eos
and eps
must be distinct from eachother and from all
tokens in the input string.
The show instance is required to throw error messages.
matches :: a -> a -> Bool Source #
This function is used for matching grammar tokens and input tokens. Override this method if, for example, your input tokens store lexemes while the grammar tokens do not
This function pretty-prints the Parseable type by displaying its lexeme.
Default implementation is show
, which should be replaced for prettier error messages.
class SubsumesToken a where Source #
Class whose members are super-types of Token
.
unlexTokens :: [Token] -> String Source #
Pretty-prints a list of Token
s as a concatenation of their lexemes.
unlexToken :: Token -> String Source #