Documentation
Earlgrey is a crate for building parsers that can understand context-free grammars.
How to use it
Parsing stage:
- First you need to define a grammar using
GrammarBuilder
to define terminals and rules. - Then build an
EarleyParser
for that grammar and callparse
on some input.
Invoking the parser on some input returns an opaque type (list of Earley items) that encodes all possible trees. If the grammar is unambiguous this should represent a single tree.
Evaluating the result:
You need an EarleyForest
that will walk through all resulting parse trees and act on them.
- To build this you provide a function that given a terminal produces an AST node.
- Then you define semantic actions to evaluate how to interpret each rule in the grammar.
Example
A toy parser that can understand sums.