Rule

Enum Rule 

Source
pub enum Rule<'a> {
    Text(Cow<'a, str>),
    Choice(Cow<'a, [&'a Rule<'a>]>),
    Sequence(Cow<'a, [&'a Rule<'a>]>),
    Repeat(RepeatRange, &'a Rule<'a>),
    Semantic(SemanticValue<Cow<'a, str>>, &'a Rule<'a>),
}
Expand description

A rule that defines one or more phrases or fragments that can be recognized by the engine.

Variants§

§

Text(Cow<'a, str>)

A sequence of words

§

Choice(Cow<'a, [&'a Rule<'a>]>)

A set of rules to choose from

§

Sequence(Cow<'a, [&'a Rule<'a>]>)

A sequence of rules that must be recognized in order

§

Repeat(RepeatRange, &'a Rule<'a>)

A rule repeated a certain number of times

§

Semantic(SemanticValue<Cow<'a, str>>, &'a Rule<'a>)

A rule that will produce a node in the semantic tree when recognized

Implementations§

Source§

impl<'a> Rule<'a>

Source

pub fn text<T: Into<Cow<'a, str>>>(text: T) -> Self

Creates a rule that defines a sequence of words to be recognized.

Source

pub fn choice<L: Into<Cow<'a, [&'a Rule<'a>]>>>(options: L) -> Self

Creates a rule that defines a set of alternatives to choose from.

Source

pub fn sequence<L: Into<Cow<'a, [&'a Rule<'a>]>>>(parts: L) -> Self

Creates a rule the defines a sequence of sub-rules that must be recognized in order.

Source

pub fn repeat<R: Into<RepeatRange>>(times: R, target: &'a Rule<'a>) -> Self

Creates a rule that recognizes a sub-rule repeated a certain number of times.

Source

pub fn semantic<V: Into<SemanticValue<Cow<'a, str>>>>( value: V, target: &'a Rule<'a>, ) -> Self

Creates a rule that produces a node in the resulting semantic tree when the given sub-rule is recognized.

Trait Implementations§

Source§

impl<'a> Debug for Rule<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Rule<'a>

§

impl<'a> RefUnwindSafe for Rule<'a>

§

impl<'a> Send for Rule<'a>

§

impl<'a> Sync for Rule<'a>

§

impl<'a> Unpin for Rule<'a>

§

impl<'a> UnwindSafe for Rule<'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.