fn build_formula_with_climber(
    expression: pest::iterators::Pairs<Rule>,
    f: Option<&impl Fn(String, Vec<f32>) -> types::Value>,
) -> types::Formula {
    let climber = PrecClimber::new(vec![
        Operator::new(Rule::concat, Assoc::Left),
        Operator::new(Rule::equal, Assoc::Left) | Operator::new(Rule::not_equal, Assoc::Left),
        Operator::new(Rule::greater, Assoc::Left)
            | Operator::new(Rule::less, Assoc::Left)
            | Operator::new(Rule::greater_or_equal, Assoc::Left)
            | Operator::new(Rule::less_or_equal, Assoc::Left),
        Operator::new(Rule::add, Assoc::Left) | Operator::new(Rule::subtract, Assoc::Left),
        Operator::new(Rule::multiply, Assoc::Left) | Operator::new(Rule::divide, Assoc::Left),
        Operator::new(Rule::power, Assoc::Right),
    ]);
    climber.climb(
        expression,
        |pair: pest::iterators::Pair<Rule>| match pair.as_rule() {
            Rule::number => build_formula_number(pair),
            Rule::string_double_quote => build_formula_string_double_quote(pair),
            Rule::string_single_quote => build_formula_string_single_quote(pair),
            Rule::t => build_formula_boolean(true),
            Rule::f => build_formula_boolean(false),
            Rule::abs => build_formula_unary_operator(Rule::abs, pair, f),
            Rule::sum => build_formula_collective_operator(Rule::sum, pair, f),
            Rule::product => build_formula_collective_operator(Rule::product, pair, f),
            Rule::average => build_formula_collective_operator(Rule::average, pair, f),
            Rule::or => build_formula_collective_operator(Rule::or, pair, f),
            Rule::and => build_formula_collective_operator(Rule::and, pair, f),
            Rule::xor => build_formula_collective_operator(Rule::xor, pair, f),
            Rule::not => build_formula_unary_operator(Rule::not, pair, f),
            Rule::reference => build_formula_reference(pair),
            Rule::iterator => build_formula_iterator(pair, f),
            Rule::negate => build_formula_unary_operator(Rule::negate, pair, f),
            Rule::expr => build_formula_with_climber(pair.into_inner(), f),
            Rule::days => build_formula_collective_operator(Rule::days, pair, f),
            Rule::right => build_formula_collective_operator(Rule::right, pair, f),
            Rule::left => build_formula_collective_operator(Rule::left, pair, f),
            Rule::custom_function => build_formula_custom_function(pair, f),
            _ => unreachable!(),
        },
        |lhs: types::Formula, op: pest::iterators::Pair<Rule>, rhs: types::Formula| match op
            .as_rule()
        {
            Rule::add => build_formula_binary_operator(Rule::add, lhs, rhs),
            Rule::subtract => build_formula_binary_operator(Rule::subtract, lhs, rhs),
            Rule::multiply => build_formula_binary_operator(Rule::multiply, lhs, rhs),
            Rule::divide => build_formula_binary_operator(Rule::divide, lhs, rhs),
            Rule::power => build_formula_binary_operator(Rule::power, lhs, rhs),
            Rule::concat => build_formula_binary_operator(Rule::concat, lhs, rhs),
            Rule::equal => build_formula_binary_operator(Rule::equal, lhs, rhs),
            Rule::not_equal => build_formula_binary_operator(Rule::not_equal, lhs, rhs),
            Rule::greater => build_formula_binary_operator(Rule::greater, lhs, rhs),
            Rule::less => build_formula_binary_operator(Rule::less, lhs, rhs),
            Rule::greater_or_equal => {
                build_formula_binary_operator(Rule::greater_or_equal, lhs, rhs)
            }
            Rule::less_or_equal => build_formula_binary_operator(Rule::less_or_equal, lhs, rhs),
            _ => unreachable!(),
        },
    )
}
/// Builds Formula Enum using a `pest-PrecClimber`.
Builds Formula Enum using a `pest-PrecClimber`.
Builds Formula Enum using a ` pest - PrecClimber ` .
fn build_formula_with_climber(
    expression: pest::iterators::Pairs<Rule>,
    f: Option<&impl Fn(String, Vec<f32>) -> types::Value>,
) -> types::Formula {
    let climber = PrecClimber::new(vec![
        Operator::new(Rule::concat, Assoc::Left),
        Operator::new(Rule::equal, Assoc::Left) | Operator::new(Rule::not_equal, Assoc::Left),
        Operator::new(Rule::greater, Assoc::Left)
            | Operator::new(Rule::less, Assoc::Left)
            | Operator::new(Rule::greater_or_equal, Assoc::Left)
            | Operator::new(Rule::less_or_equal, Assoc::Left),
        Operator::new(Rule::add, Assoc::Left) | Operator::new(Rule::subtract, Assoc::Left),
        Operator::new(Rule::multiply, Assoc::Left) | Operator::new(Rule::divide, Assoc::Left),
        Operator::new(Rule::power, Assoc::Right),
    ]);
    climber.climb(
        expression,
        |pair: pest::iterators::Pair<Rule>| match pair.as_rule() {
            Rule::number => build_formula_number(pair),
            Rule::string_double_quote => build_formula_string_double_quote(pair),
            Rule::string_single_quote => build_formula_string_single_quote(pair),
            Rule::t => build_formula_boolean(true),
            Rule::f => build_formula_boolean(false),
            Rule::abs => build_formula_unary_operator(Rule::abs, pair, f),
            Rule::sum => build_formula_collective_operator(Rule::sum, pair, f),
            Rule::product => build_formula_collective_operator(Rule::product, pair, f),
            Rule::average => build_formula_collective_operator(Rule::average, pair, f),
            Rule::or => build_formula_collective_operator(Rule::or, pair, f),
            Rule::and => build_formula_collective_operator(Rule::and, pair, f),
            Rule::xor => build_formula_collective_operator(Rule::xor, pair, f),
            Rule::not => build_formula_unary_operator(Rule::not, pair, f),
            Rule::reference => build_formula_reference(pair),
            Rule::iterator => build_formula_iterator(pair, f),
            Rule::negate => build_formula_unary_operator(Rule::negate, pair, f),
            Rule::expr => build_formula_with_climber(pair.into_inner(), f),
            Rule::days => build_formula_collective_operator(Rule::days, pair, f),
            Rule::right => build_formula_collective_operator(Rule::right, pair, f),
            Rule::left => build_formula_collective_operator(Rule::left, pair, f),
            Rule::custom_function => build_formula_custom_function(pair, f),
            _ => unreachable!(),
        },
        |lhs: types::Formula, op: pest::iterators::Pair<Rule>, rhs: types::Formula| match op
            .as_rule()
        {
            Rule::add => build_formula_binary_operator(Rule::add, lhs, rhs),
            Rule::subtract => build_formula_binary_operator(Rule::subtract, lhs, rhs),
            Rule::multiply => build_formula_binary_operator(Rule::multiply, lhs, rhs),
            Rule::divide => build_formula_binary_operator(Rule::divide, lhs, rhs),
            Rule::power => build_formula_binary_operator(Rule::power, lhs, rhs),
            Rule::concat => build_formula_binary_operator(Rule::concat, lhs, rhs),
            Rule::equal => build_formula_binary_operator(Rule::equal, lhs, rhs),
            Rule::not_equal => build_formula_binary_operator(Rule::not_equal, lhs, rhs),
            Rule::greater => build_formula_binary_operator(Rule::greater, lhs, rhs),
            Rule::less => build_formula_binary_operator(Rule::less, lhs, rhs),
            Rule::greater_or_equal => {
                build_formula_binary_operator(Rule::greater_or_equal, lhs, rhs)
            }
            Rule::less_or_equal => build_formula_binary_operator(Rule::less_or_equal, lhs, rhs),
            _ => unreachable!(),
        },
    )
}
fn build_formula_with_climber ( expression : pest :: iterators :: Pairs < Rule > , f : Option < & impl Fn ( String , Vec < f32 > ) -> types :: Value > , ) -> types :: Formula { let climber = PrecClimber :: new ( vec ! [ Operator new ( Rule concat Assoc Left ) Operator new ( Rule equal Assoc Left ) Operator new ( Rule not_equal Assoc Left ) Operator new ( Rule greater Assoc Left ) Operator new ( Rule less Assoc Left ) Operator new ( Rule greater_or_equal Assoc Left ) Operator new ( Rule less_or_equal Assoc Left ) Operator new ( Rule add Assoc Left ) Operator new ( Rule subtract Assoc Left ) Operator new ( Rule multiply Assoc Left ) Operator new ( Rule divide Assoc Left ) Operator new ( Rule power Assoc Right ) ] ) ; climber . climb ( expression , | pair : pest :: iterators :: Pair < Rule > | match pair . as_rule ( ) { Rule :: number => build_formula_number ( pair ) , Rule :: string_double_quote => build_formula_string_double_quote ( pair ) , Rule :: string_single_quote => build_formula_string_single_quote ( pair ) , Rule :: t => build_formula_boolean ( true ) , Rule :: f => build_formula_boolean ( false ) , Rule :: abs => build_formula_unary_operator ( Rule :: abs , pair , f ) , Rule :: sum => build_formula_collective_operator ( Rule :: sum , pair , f ) , Rule :: product => build_formula_collective_operator ( Rule :: product , pair , f ) , Rule :: average => build_formula_collective_operator ( Rule :: average , pair , f ) , Rule :: or => build_formula_collective_operator ( Rule :: or , pair , f ) , Rule :: and => build_formula_collective_operator ( Rule :: and , pair , f ) , Rule :: xor => build_formula_collective_operator ( Rule :: xor , pair , f ) , Rule :: not => build_formula_unary_operator ( Rule :: not , pair , f ) , Rule :: reference => build_formula_reference ( pair ) , Rule :: iterator => build_formula_iterator ( pair , f ) , Rule :: negate => build_formula_unary_operator ( Rule :: negate , pair , f ) , Rule :: expr => build_formula_with_climber ( pair . into_inner ( ) , f ) , Rule :: days => build_formula_collective_operator ( Rule :: days , pair , f ) , Rule :: right => build_formula_collective_operator ( Rule :: right , pair , f ) , Rule :: left => build_formula_collective_operator ( Rule :: left , pair , f ) , Rule :: custom_function => build_formula_custom_function ( pair , f ) , _ => unreachable ! ( ) , } , | lhs : types :: Formula , op : pest :: iterators :: Pair < Rule > , rhs : types :: Formula | match op . as_rule ( ) { Rule :: add => build_formula_binary_operator ( Rule :: add , lhs , rhs ) , Rule :: subtract => build_formula_binary_operator ( Rule :: subtract , lhs , rhs ) , Rule :: multiply => build_formula_binary_operator ( Rule :: multiply , lhs , rhs ) , Rule :: divide => build_formula_binary_operator ( Rule :: divide , lhs , rhs ) , Rule :: power => build_formula_binary_operator ( Rule :: power , lhs , rhs ) , Rule :: concat => build_formula_binary_operator ( Rule :: concat , lhs , rhs ) , Rule :: equal => build_formula_binary_operator ( Rule :: equal , lhs , rhs ) , Rule :: not_equal => build_formula_binary_operator ( Rule :: not_equal , lhs , rhs ) , Rule :: greater => build_formula_binary_operator ( Rule :: greater , lhs , rhs ) , Rule :: less => build_formula_binary_operator ( Rule :: less , lhs , rhs ) , Rule :: greater_or_equal => { build_formula_binary_operator ( Rule :: greater_or_equal , lhs , rhs ) } Rule :: less_or_equal => build_formula_binary_operator ( Rule :: less_or_equal , lhs , rhs ) , _ => unreachable ! ( ) , } , ) }
Builds Formula Enum using a `pest-PrecClimber`.
Builds Formula Enum using a ` pest - PrecClimber ` .
expression
pest::iterators::Pairs<Rule>
f
Option<&impl Fn(String, Vec<f32>) -> types::Value>