pub trait Pratt<L: Language> {
// Required methods
fn primary<'a, S: Source + ?Sized>(
&self,
state: &mut ParserState<'a, L, S>,
) -> &'a GreenNode<'a, L>;
fn infix<'a, S: Source + ?Sized>(
&self,
state: &mut ParserState<'a, L, S>,
left: &'a GreenNode<'a, L>,
min_precedence: u8,
) -> Option<&'a GreenNode<'a, L>>;
// Provided method
fn prefix<'a, S: Source + ?Sized>(
&self,
state: &mut ParserState<'a, L, S>,
) -> &'a GreenNode<'a, L> { ... }
}Expand description
A specification for a Pratt parser.
Users implement this trait to define the grammar rules for expressions. Using a trait allows the compiler to optimize operator lookups using match statements.
Required Methods§
Sourcefn primary<'a, S: Source + ?Sized>(
&self,
state: &mut ParserState<'a, L, S>,
) -> &'a GreenNode<'a, L>
fn primary<'a, S: Source + ?Sized>( &self, state: &mut ParserState<'a, L, S>, ) -> &'a GreenNode<'a, L>
Parses a primary expression (e.g., literals, identifiers, group).
Sourcefn infix<'a, S: Source + ?Sized>(
&self,
state: &mut ParserState<'a, L, S>,
left: &'a GreenNode<'a, L>,
min_precedence: u8,
) -> Option<&'a GreenNode<'a, L>>
fn infix<'a, S: Source + ?Sized>( &self, state: &mut ParserState<'a, L, S>, left: &'a GreenNode<'a, L>, min_precedence: u8, ) -> Option<&'a GreenNode<'a, L>>
Handles infix and postfix operators.
Should return Some(new_node) if an operator was parsed, or None if no operator matches
or its precedence is lower than min_precedence.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.