pub struct PrecClimber<R: Clone + 'static> { /* private fields */ }
👎Deprecated since 2.4.0: Use pest::pratt_parser instead (it is an equivalent which also supports unary prefix/suffix operators). While prec_climber is going to be kept in 2.x minor and patch releases, it may be removed in a future major release.
Expand description

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

👎Deprecated since 2.4.0: Use pest::pratt_parser instead (it is an equivalent which also supports unary prefix/suffix operators). While prec_climber is going to be kept in 2.x minor and patch releases, it may be removed in a future major release.

Creates a new PrecClimber from the Operators contained in ops. Every entry in the Vec has precedence index + 1. In order to have operators with same precedence, they need to be chained with | between them.

Examples
PrecClimber::new(vec![
    Operator::new(Rule::plus, Assoc::Left) | Operator::new(Rule::minus, Assoc::Left),
    Operator::new(Rule::times, Assoc::Left) | Operator::new(Rule::divide, Assoc::Left),
    Operator::new(Rule::power, Assoc::Right)
]);
👎Deprecated since 2.4.0: Use pest::pratt_parser instead (it is an equivalent which also supports unary prefix/suffix operators). While prec_climber is going to be kept in 2.x minor and patch releases, it may be removed in a future major release.

Performs the precedence climbing algorithm on the pairs in a similar manner to map-reduce. Primary pairs are mapped with primary and then reduced to one single result with infix.

Panics

Panics will occur when pairs is 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);

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.