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 keywordruleThe AST generator will try to deriveFoofirst, and if it fails, it will try to deriveBar. - 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 keywordruleThe 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: StringName of the rule. The AST and PT generated types depend on this name.
hook: Option<Hook>Optional parser hook
value: RuleValueValue of the rule
Implementations§
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more