Struct bnf::Grammar
[−]
[src]
pub struct Grammar { /* fields omitted */ }
A Grammar is comprised of any number of Productions
Methods
impl Grammar
[src]
fn new() -> Grammar
[src]
Construct a new Grammar
fn from_parts(v: Vec<Production>) -> Grammar
[src]
Construct an Grammar
from Production
s
fn from_str(s: &str) -> Result<Self, Error>
[src]
fn add_production(&mut self, prod: Production)
[src]
Add Production
to the Grammar
fn remove_production(&mut self, prod: &Production) -> Option<Production>
[src]
Remove Production
from the Grammar
fn productions_iter(&self) -> Iter
[src]
Get iterator of the Grammar
's Production
s
fn productions_iter_mut(&mut self) -> IterMut
[src]
Get mutable iterator of the Grammar
's Production
s
fn generate_seeded(&self, rng: &mut StdRng) -> Result<String, Error>
[src]
Generate a random sentence from self and seed for random. Use if interested in reproducing the output generated. Begins from lhs of first production.
Example
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) } }
fn generate(&self) -> Result<String, Error>
[src]
Generate a random sentence from self. Begins from lhs of first production.
Example
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) } }
Trait Implementations
impl PartialEq for Grammar
[src]
fn eq(&self, __arg_0: &Grammar) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Grammar) -> bool
[src]
This method tests for !=
.
impl Debug for Grammar
[src]
impl Clone for Grammar
[src]
fn clone(&self) -> Grammar
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Display for Grammar
[src]
fn fmt(&self, f: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more