Earlgrey is a crate for building parsers that can understand context-free grammars.
How to use it
- First you need to define a grammar using
GrammarBuilderto define terminals and rules.
- Then build an
EarleyParserfor that grammar and call
parseon 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.
A toy parser that can understand sums.