Skip to main content

ConstPrattParser

Struct ConstPrattParser 

Source
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>

Source

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
]);
Source

pub fn map_primary<'pratt, 'a, 'i, X, T>( &'pratt self, primary: X, ) -> PrattParserMap<'pratt, 'a, 'i, R, X, T, Self>
where X: FnMut(Pair<'i, R>) -> T, R: 'pratt,

Maps primary expressions with a closure primary.

Auto Trait Implementations§

§

impl<R, const N: usize> Freeze for ConstPrattParser<R, N>
where [(R, Affix, u32); N]: Freeze,

§

impl<R, const N: usize> RefUnwindSafe for ConstPrattParser<R, N>
where [(R, Affix, u32); N]: RefUnwindSafe,

§

impl<R, const N: usize> Send for ConstPrattParser<R, N>
where [(R, Affix, u32); N]: Send,

§

impl<R, const N: usize> Sync for ConstPrattParser<R, N>
where [(R, Affix, u32); N]: Sync,

§

impl<R, const N: usize> Unpin for ConstPrattParser<R, N>
where [(R, Affix, u32); N]: Unpin,

§

impl<R, const N: usize> UnsafeUnpin for ConstPrattParser<R, N>
where [(R, Affix, u32); N]: UnsafeUnpin,

§

impl<R, const N: usize> UnwindSafe for ConstPrattParser<R, N>
where [(R, Affix, u32); N]: UnwindSafe,

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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.