Documentation
Abackus crate adds a layer on top of earlgrey crate to simplify writing a grammar. You can simply use an EBNF style String instead of manually adding rules.
You can describe your grammar like this:
let grammar = r#"
S := S '+' N | N ;
N := '[0-9]' ;
"#;
default
.plug_terminal
.plug_terminal
.into_parser
Instead of the more verbose:
// Gramar: S -> S + N | N; N -> [0-9];
let g = default
.nonterm
.nonterm
.terminal
.terminal
.rule
.rule
.rule
.into_grammar
.unwrap;
new
How it works
Underneath the covers an earlgrey::EarleyParser
is used to build a parser for EBNF grammar. (For details you can check earlgrey/ebnf.rs
). That parser is then used to build a final parser for the grammar provided by the user.
Example
// NOTE: extract from abackus/examples/ebnftree.rs