pub struct Grammar { /* fields omitted */ }
A Grammar is comprised of any number of Productions
Construct an Grammar
from Production
s
Add Production
to the Grammar
Remove Production
from the Grammar
Get iterator of the Grammar
's Production
s
Get mutable iterator of the Grammar
's Production
s
Generate a random sentence from self and seed for random.
Use if interested in reproducing the output generated.
Begins from lhs of first production.
extern crate bnf;
extern crate rand;
use rand::{SeedableRng, StdRng};
use bnf::Grammar;
fn main() {
let input =
"<dna> ::= <base> | <base> <dna>
<base> ::= \"A\" | \"C\" | \"G\" | \"T\"";
let grammar = Grammar::from_str(input).unwrap();
let seed: &[_] = &[1,2,3,4];
let mut rng: StdRng = SeedableRng::from_seed(seed);
let sentence = grammar.generate_seeded(&mut rng);
match sentence {
Ok(s) => println!("random sentence: {}", s),
Err(e) => println!("something went wrong: {}!", e)
}
}
Generate a random sentence from self.
Begins from lhs of first production.
extern crate bnf;
use bnf::Grammar;
fn main() {
let input =
"<dna> ::= <base> | <base> <dna>
<base> ::= \"A\" | \"C\" | \"G\" | \"T\"";
let grammar = Grammar::from_str(input).unwrap();
let sentence = grammar.generate();
match sentence {
Ok(s) => println!("random sentence: {}", s),
Err(e) => println!("something went wrong: {}!", e)
}
}
This method tests for self
and other
values to be equal, and is used by ==
. Read more
This method tests for !=
.
Performs copy-assignment from source
. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
The associated error which can be returned from parsing.
Parses a string s
to return a value of this type. Read more
Creates owned data from borrowed data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String
. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static