[−][src]Struct bnf::Grammar
A Grammar is comprised of any number of Productions
Methods
impl Grammar
[src]
pub fn new() -> Grammar
[src]
Construct a new Grammar
pub fn from_parts(v: Vec<Production>) -> Grammar
[src]
Construct an Grammar
from Production
s
pub fn add_production(&mut self, prod: Production)
[src]
Add Production
to the Grammar
pub fn remove_production(&mut self, prod: &Production) -> Option<Production>
[src]
Remove Production
from the Grammar
pub fn productions_iter(&self) -> Iter
[src]
Get iterator of the Grammar
's Production
s
pub fn productions_iter_mut(&mut self) -> IterMut
[src]
Get mutable iterator of the Grammar
's Production
s
pub 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 = input.parse().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) } }
pub 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 = input.parse().unwrap(); let sentence = grammar.generate(); match sentence { Ok(s) => println!("random sentence: {}", s), Err(e) => println!("something went wrong: {}!", e) } }
Trait Implementations
impl Clone for Grammar
[src]
impl Default for Grammar
[src]
impl Eq for Grammar
[src]
impl PartialEq<Grammar> for Grammar
[src]
impl Display for Grammar
[src]
impl Debug for Grammar
[src]
impl FromStr for Grammar
[src]
type Err = Error
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self, Self::Err>
[src]
impl Hash for Grammar
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl StructuralPartialEq for Grammar
[src]
impl StructuralEq for Grammar
[src]
Auto Trait Implementations
impl Send for Grammar
impl Sync for Grammar
impl Unpin for Grammar
impl UnwindSafe for Grammar
impl RefUnwindSafe for Grammar
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,