Rule

Struct Rule 

Source
pub struct Rule {
    pub name: String,
    pub hook: Option<Hook>,
    pub value: RuleValue,
}
Expand description

Definition for a rule (a.k.a. derivation)

A rule is a derivation step that can be used to generate the Abstract Syntax Tree (AST).

There are two types of derivations:

  • Union: a union of derivations. The first derivation that succeeds is used. For example: rule Biz = Foo | Bar, where Foo and Bar are also defined by the keyword rule The AST generator will try to derive Foo first, and if it fails, it will try to derive Bar.
  • Derivation: Derive into smaller rules. Each part is represented by a parameter analogous to a function parameter. For example: rule Foo(bat: Bar, baz: Baz);, where Bar and Baz are also defined by the keyword rule The AST generator will derive Bar and Baz in order, and then combine them into a Foo AST node.

With Union rules, only other rules can be specified as part of the union. With derivation rules, token types can also be specified.

Fields§

§name: String

Name of the rule. The AST and PT generated types depend on this name.

§hook: Option<Hook>

Optional parser hook

§value: RuleValue

Value of the rule

Implementations§

Source§

impl Rule

Source

pub fn struct_name(&self) -> String

Get the base name of the struct for this rule, which is the UpperCamelCase of the name

Trait Implementations§

Source§

impl Clone for Rule

Source§

fn clone(&self) -> Rule

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Rule

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Rule

§

impl RefUnwindSafe for Rule

§

impl Send for Rule

§

impl Sync for Rule

§

impl Unpin for Rule

§

impl UnwindSafe for Rule

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.