Macro tracery::grammar[][src]

macro_rules! grammar {
    ($($input: tt)+) => { ... };
}

Convenience macro that allows for shorthand creation of Grammars.

Accepts input in the form "key" => [ "list", "of", "rules" ] or, in the case of a key having only one rule, "key" => "rule". Equivalent to manually building a map and then calling Grammar::from_map

Returns

Result<Grammar, Error>

Example

// Declare the grammar
let g = grammar! {
    "origin" => "#tool# is #description#!",
    "tool" => "tracery",
    "description" => [ "fun", "awesome" ]
}?;

// Randomly produce the string "tracery is fun!" or "tracery is awesome!"
g.flatten(&mut rand::thread_rng())?;