pub struct ConstPrattParser<R: RuleType + 'static, const N: usize> { /* private fields */ }Expand description
A Pratt parser that can be built in a const context and stored in static
memory.
It is functionally equivalent to PrattParser, but it is constructed from
a static array of Ops rather than the chained .op(...) builder.
Implementations§
Source§impl<R: RuleType + 'static, const N: usize> ConstPrattParser<R, N>
impl<R: RuleType + 'static, const N: usize> ConstPrattParser<R, N>
Sourcepub const fn new_const(ops: [(Op<R>, bool); N]) -> Self
pub const fn new_const(ops: [(Op<R>, bool); N]) -> Self
Create a ConstPrattParser from a static array of ([Op], bool)
pairs.
Just like PrattParser::op, but for use in a const context. The
bool in each pair tells whether the operator starts a new precedence
level (true) or shares the previous operator’s level (false).
Levels are ordered from lowest to highest precedence; the first
operator must start a new level (true).
§Example
static PRATT: ConstPrattParser<Rule, 7> = ConstPrattParser::new_const([
(Op::infix(Rule::add, Assoc::Left), true), // lowest precedence
(Op::infix(Rule::sub, Assoc::Left), false), // same precedence as add
(Op::infix(Rule::mul, Assoc::Left), true), // next precedence level
(Op::infix(Rule::div, Assoc::Left), false), // same precedence as mul
(Op::infix(Rule::pow, Assoc::Right), true),
(Op::prefix(Rule::neg), true),
(Op::postfix(Rule::fac), true), // highest precedence
]);Sourcepub fn map_primary<'pratt, 'a, 'i, X, T>(
&'pratt self,
primary: X,
) -> PrattParserMap<'pratt, 'a, 'i, R, X, T, Self>
pub fn map_primary<'pratt, 'a, 'i, X, T>( &'pratt self, primary: X, ) -> PrattParserMap<'pratt, 'a, 'i, R, X, T, Self>
Maps primary expressions with a closure primary.
Auto Trait Implementations§
impl<R, const N: usize> Freeze for ConstPrattParser<R, N>
impl<R, const N: usize> RefUnwindSafe for ConstPrattParser<R, N>
impl<R, const N: usize> Send for ConstPrattParser<R, N>
impl<R, const N: usize> Sync for ConstPrattParser<R, N>
impl<R, const N: usize> Unpin for ConstPrattParser<R, N>
impl<R, const N: usize> UnsafeUnpin for ConstPrattParser<R, N>
impl<R, const N: usize> UnwindSafe for ConstPrattParser<R, N>
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