pub enum GrammarRule<K: TokenKind, R: RuleId> {
Sequence(Vec<GrammarRule<K, R>>),
Choice(Vec<GrammarRule<K, R>>),
Optional(Box<GrammarRule<K, R>>),
ZeroOrMore(Box<GrammarRule<K, R>>),
OneOrMore(Box<GrammarRule<K, R>>),
Range {
rule: Box<GrammarRule<K, R>>,
min: usize,
max: usize,
},
PrattExpr(Precedence),
Token(K),
Rule(R),
Conditional {
rule: Box<GrammarRule<K, R>>,
condition: fn(usize) -> bool,
},
NegativeLookahead(Box<GrammarRule<K, R>>),
PositiveLookahead(Box<GrammarRule<K, R>>),
}Expand description
High-level grammar building block.
§Serialization
When the serde feature is enabled, this type implements Serialize and Deserialize.
Note that K and R must also implement these traits for serialization to work.
Variants§
Sequence(Vec<GrammarRule<K, R>>)
Sequence: a b c.
Choice(Vec<GrammarRule<K, R>>)
Choice: a | b | c.
Optional(Box<GrammarRule<K, R>>)
Optional: a?.
ZeroOrMore(Box<GrammarRule<K, R>>)
Zero or more: a*.
OneOrMore(Box<GrammarRule<K, R>>)
One or more: a+.
Range
Range repetition: a{min,max}.
Fields
§
rule: Box<GrammarRule<K, R>>Rule that must repeat.
PrattExpr(Precedence)
Delegate to the Pratt parser for expression parsing.
Token(K)
Terminal token literal.
Rule(R)
Rule reference.
Conditional
Conditional rule that depends on the parser position.
Fields
§
rule: Box<GrammarRule<K, R>>Nested rule to evaluate when the condition succeeds.
NegativeLookahead(Box<GrammarRule<K, R>>)
Negative lookahead: succeeds if the rule does NOT match.
PositiveLookahead(Box<GrammarRule<K, R>>)
Positive lookahead: succeeds if the rule matches, but doesn’t consume input.
Trait Implementations§
Auto Trait Implementations§
impl<K, R> Freeze for GrammarRule<K, R>
impl<K, R> RefUnwindSafe for GrammarRule<K, R>where
K: RefUnwindSafe,
R: RefUnwindSafe,
impl<K, R> Send for GrammarRule<K, R>
impl<K, R> Sync for GrammarRule<K, R>
impl<K, R> Unpin for GrammarRule<K, R>
impl<K, R> UnwindSafe for GrammarRule<K, R>where
K: UnwindSafe,
R: UnwindSafe,
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