#![feature(proc_macro_non_items)] use parsing::{ grammar, Grammar, Rule, Token, Generation, }; fn print_next_sentences (n: usize, grammar: Grammar) { let mut generation = Generation::new (grammar, "Start"); for _ in 0..n { let sentence = generation .next_sentence () .unwrap (); println! ("{}", sentence); } } #[test] fn test_next_sentence () { print_next_sentences (100, grammar! { Start -> Sentence; Sentence -> Name | List " and " Name; Name -> "tom" | "dick" | "harry"; List -> Name | Name ", " List; }); print_next_sentences (100, grammar! { Start -> S; S -> "abc" | "a" S Q; "b" Q "c" -> "bbcc"; "c" Q -> Q "c"; }); print_next_sentences (100, grammar! { Start -> Moves; // circle-movements-for-manhattan-turtle Moves -> "north " Moves "south " | "east " Moves "west " | ε; ε -> ; // the following are just // swapping pathes generated by the above rule "north east " -> "east north "; "north south " -> "south north "; "north west " -> "west north "; "east north " -> "north east "; "east south " -> "south east "; "east west " -> "west east "; "south north " -> "north south "; "south east " -> "east south "; "south west " -> "west south "; "west north " -> "north west "; "west east " -> "east west "; "west south " -> "south west "; }); }