Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data Grammar n t c = Grammar {}
- mkGrammar :: (Ord n, Bounded n, Enum n) => (n -> [Rule n t]) -> (t -> c -> Bool) -> Grammar n t c
- nullableSymbols :: Ord n => (n -> [Rule n t]) -> [n] -> Set n
- type Rule n t = [Atom n t]
- data Atom n t
- data RuleId n = RuleId n Int
- data Item n t = Item (RuleId n) [Atom n t] Int
- data S n t = S {}
- emptyS :: S n t
- initialS :: (Ord n, Ord t) => Grammar n t c -> n -> S n t
- newItems :: Ord n => Grammar n t c -> Int -> n -> [Item n t]
- allItemSets :: S n t -> Seq (Set (Item n t))
- type Parser n t = State (S n t)
- next :: Parser n t ()
- addItemCurr :: (Ord n, Ord t) => Item n t -> Parser n t ()
- lookupItemSet :: Int -> Parser n t (Set (Item n t))
- addItemNext :: (Ord n, Ord t) => Item n t -> Parser n t ()
- stepItem :: (Ord n, Ord t) => Grammar n t c -> Maybe c -> Item n t -> Parser n t ()
- step :: (Ord n, Ord t) => Grammar n t c -> Maybe c -> Parser n t ()
- steps :: (Ord n, Ord t) => Grammar n t c -> [c] -> Parser n t ()
- data Seq1 a = (Seq a) ::> a
- preparse :: (Ord n, Ord t) => Grammar n t c -> n -> [c] -> Seq1 (Set (Item n t))
- accepts :: (Ord n, Ord t) => Grammar n t c -> n -> [c] -> Bool
Documentation
Grammars with non-terminal symbols n
, terminal symbols t
, and tokens c
.
A grammar defines a language, which is a set of sequences of tokens c
.
Two basic choices for t
and c
are:
t =
andCharT
c = Char
, with
: then the inputmatch
=matchCharT
[c]
is aString
.t = String
andc = String
, with
: then the inputmatch
= (==)[c]
is a[String]
, which can be produced usingwords
; just remember to put spaces around operators and parentheses.
See also examples in Little.Earley.Examples.
Grammar | |
|
mkGrammar :: (Ord n, Bounded n, Enum n) => (n -> [Rule n t]) -> (t -> c -> Bool) -> Grammar n t c Source #
Construct a grammar given the fields rules
and match
,
implicitly populating isNullable
.
nullableSymbols :: Ord n => (n -> [Rule n t]) -> [n] -> Set n Source #
Compute the set of non-terminal symbols which may expand to the empty string, given an enumeration of all non-terminal symbols.
An atom is either a non-terminal or a terminal.
A rule can be identified by a non-terminal and an index into all of the associated rules of that non-terminal.