Struct PrecClimber
struct PrecClimber<R: Clone + 'static> { ... }
List of operators and precedences, which can perform precedence climbing on infix
expressions contained in a Pairs. The token pairs contained in the Pairs should start
with a primary pair and then alternate between an operator and a primary.
Implementations
impl<R: RuleType> PrecClimber<R>
fn new(ops: Vec<Operator<R>>) -> PrecClimber<R>Creates a new
PrecClimberfrom theOperators contained inops. Every entry in theVechas precedence index + 1. In order to have operators with same precedence, they need to be chained with|between them.Examples
# use ; # # # # new;fn climb<'i, P, F, G, T>(self: &Self, pairs: P, primary: F, infix: G) -> T where P: Iterator<Item = Pair<'i, R>>, F: FnMut(Pair<'i, R>) -> T, G: FnMut(T, Pair<'i, R>, T) -> TPerforms the precedence climbing algorithm on the
pairsin a similar manner to map-reduce. Primary pairs are mapped withprimaryand then reduced to one single result withinfix.Panics
Panics will occur when
pairsis empty or when the alternating primary, operator, primary order is not respected.Examples
let primary = |pair| { consume(pair, climber) }; let infix = |lhs: i32, op: Pair<Rule>, rhs: i32| { match op.rule() { Rule::plus => lhs + rhs, Rule::minus => lhs - rhs, Rule::times => lhs * rhs, Rule::divide => lhs / rhs, Rule::power => lhs.pow(rhs as u32), _ => unreachable!() } }; let result = climber.climb(pairs, primary, infix);
impl<R> Freeze for PrecClimber<R>
impl<R> RefUnwindSafe for PrecClimber<R>
impl<R> Send for PrecClimber<R>
impl<R> Sync for PrecClimber<R>
impl<R> Unpin for PrecClimber<R>
impl<R> UnsafeUnpin for PrecClimber<R>
impl<R> UnwindSafe for PrecClimber<R>
impl<R: $crate::fmt::Debug + Clone + 'static> Debug for PrecClimber<R>
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl<T> Any for PrecClimber<R>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for PrecClimber<R>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for PrecClimber<R>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> From for PrecClimber<R>
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into for PrecClimber<R>
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for PrecClimber<R>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for PrecClimber<R>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>