Function mo::compile_grammar [−][src]
pub fn compile_grammar(
grammar: String
) -> Result<Grammar, Vec<HashMap<String, String>>>
Compile a grammar string and creates a HashMap
with rules found as keys and their components (AST) as entries
In this step, the grammar is validated with the pest reference grammar, and the built-in rules are replaced for their equivalents
use mo::compile_grammar; // Grammar string let mut grammar = r#" language = {"Rust" | "Python" | "Go" | "Java" | "PHP" | "Haskell"} one = {"1"} daysNumber = {one ~ " day" | !one ~ ASCII_NONZERO_DIGIT ~ " days"} sentence = {"I have been programming in " ~ language ~ " for " ~ daysNumber ~ "."} "#; // Generate the ast let grammar_ast = compile_grammar(grammar.to_string()); println!("{:?}", grammar_ast);