Module gcode

Module gcode 

Source
Expand description

Generate source code from a set of rules

example

extern crate dynparser;
use dynparser::{peg, rules_from_peg};

fn main() {
    let rules = rules_from_peg(
        r#"

            main            =   as / a  bs

            as              =   a+

            a               =   'a'

            bs              =   'b'+

"#,
    ).map_err(|e| {
        println!("{}", e);
        panic!("FAIL");
    })
        .unwrap();

    println!("{}", peg::gcode::rust_from_rules(&rules))
}

The parser itself uses a peg grammar and generate the rules with this function

The rules code generated by this program will be

     "as" => rep!(ref_rule!("a"), 1)
   , "a" => lit!("a")
   , "main" => or!(ref_rule!("as"), and!(ref_rule!("a"), ref_rule!("bs")))
   , "bs" => rep!(lit!("b"), 1)

Functions§

rust_from_rules
Generate a string with rust code from a expression::SetOfRules