RuleArena

Struct RuleArena 

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

Allocation arena for grammar rules.

Provides an easy way to allocate Rule instances while building a grammar. All of the rules owned by the arena will be dropped when the arena itself is dropped.

Implementations§

Source§

impl<'a> RuleArena<'a>

Source

pub fn new() -> Self

Construct a new arena.

Source

pub fn alloc(&self, rule: Rule<'a>) -> &Rule<'a>

Take ownership of a constructed rule and keep it until the arena is destroyed.

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Auto Trait Implementations§

§

impl<'a> !Freeze for RuleArena<'a>

§

impl<'a> !RefUnwindSafe for RuleArena<'a>

§

impl<'a> Send for RuleArena<'a>

§

impl<'a> !Sync for RuleArena<'a>

§

impl<'a> Unpin for RuleArena<'a>

§

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