use std::str::FromStr; use parsing_tech::{ Grammar, Generation, }; const SEXP: &'static str = r#" ::= "(" ")"; ::= ; ::= ; ::= " " ; ::= "true"; ::= "false"; "#; const TOM_DICK_AND_HARRY: &'static str = r#" ::= ; ::= " and " ; ::= "tom"; ::= "dick"; ::= "harry"; ::= ; ::= ", " ; "#; const TDH: &'static str = r#" ::= "t"; ::= "d"; ::= "h"; ::= ; ::= "t" ; ::= "d" ; ::= "h" ; ::= "," ; ::= "&t"; ::= "&d"; ::= "&h"; "#; const TDH_LEFT: &'static str = r#" ::= "t"; ::= "d"; ::= "h"; ::= ; ::= "&t"; ::= "&d"; ::= "&h"; ::= "t"; ::= "d"; ::= "h"; ::= ",t"; ::= ",d"; ::= ",h"; "#; const SUM: &'static str = r#" ::= ; ::= " + " ; ::= "0"; ::= "1"; "#; const AB: &'static str = r#" ::= "a" ; ::= "b" ; ::= "a"; ::= "a" ; ::= "b" ; ::= "b"; ::= "b" ; ::= "a" ; "#; const ABC: &'static str = r#" ::= ; ::= ; ::= "a"; ::= "a" ; ::= "bc"; ::= "b" "c"; ::= "ab"; ::= "a" "b"; ::= "c"; ::= "c" ; "#; fn sentences (n: usize, format: &str, start: &str) { let mut gen = Generation::new ( Grammar::from_str (format) .unwrap (), start); println! ("- {}", start); for _ in 0..n { let tree = gen.next_tree () .unwrap (); println! (" {}", tree.to_sentence ()); } } #[test] fn test_generation () { sentences (10, TOM_DICK_AND_HARRY, "tom-dick-and-harry"); sentences (10, TDH, "tdh"); sentences (10, TDH_LEFT, "tdh-left"); sentences (10, SEXP, "sexp"); sentences (10, SEXP, "sexp-list"); sentences (10, SUM, "sum"); sentences (10, AB, "ab"); sentences (10, ABC, "abc"); }