GrammarBuilder

Struct GrammarBuilder 

Source
pub struct GrammarBuilder<'a> { /* private fields */ }
Expand description

Helper type that constructs a grammar from a set of top-level rules.

A top-level rule defines one or more phrases that can be recognized. The rules contained in or referenced by a top-level rule will not be recognized as phrases, unless they are also added as top-level rules. For example, consider the following top-level rule definition:

Rule::sequence(vec![
    &Rule::text("good"),
    &Rule::choice(vec![
        &Rule::text("morning"),
        &Rule::text("evening"),
    ])
])

Given this rule, the engine will only recognize the phrases “good morning” and “good evening”, but not “good”, “morning”, or “evening”.

Implementations§

Source§

impl<'a> GrammarBuilder<'a>

Source

pub fn clear(&mut self) -> &mut Self

Clears all the added rules.

Source

pub fn add_rule(&mut self, rule: &'a Rule<'a>) -> &mut Self

Adds an unnamed top-level rule to the grammar.

Source

pub fn add_named_rule<S: Into<Cow<'a, str>>>( &mut self, name: S, rule: &'a Rule<'a>, ) -> &mut Self

Adds a top-level rule with the given name to the grammar. The name can be used to enable or disable the rule.

Source

pub fn build(&mut self) -> Result<Grammar>

Builds the grammar from the given rules and loads it into the recognition context. The newly loaded grammar must be enabled before the engine will start recognizing phrases from it.

Auto Trait Implementations§

§

impl<'a> Freeze for GrammarBuilder<'a>

§

impl<'a> RefUnwindSafe for GrammarBuilder<'a>

§

impl<'a> Send for GrammarBuilder<'a>

§

impl<'a> Sync for GrammarBuilder<'a>

§

impl<'a> Unpin for GrammarBuilder<'a>

§

impl<'a> UnwindSafe for GrammarBuilder<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.