fn parse_math_expression(
    incoming_idx: usize,
    lite_args: &[Spanned<String>],
    registry: &dyn SignatureRegistry,
    shorthand_mode: bool,
) -> (usize, SpannedExpression, Option<ParseError>) {
    // Precedence parsing is included
    // Short_hand mode means that the left-hand side of an expression can point to a column-path. To make this possible,
    //   we parse as normal, but then go back and when we detect a left-hand side, reparse that value if it's a string

    let mut idx = 0;
    let mut error = None;

    let mut working_exprs = vec![];
    let mut prec = vec![];

    let (lhs_working_expr, err) =
        parse_possibly_parenthesized(&lite_args[idx], registry, shorthand_mode);

    if error.is_none() {
        error = err;
    }
    working_exprs.push(lhs_working_expr);

    idx += 1;

    prec.push(0);

    while idx < lite_args.len() {
        let (op, err) = parse_arg(SyntaxShape::Operator, registry, &lite_args[idx]);
        if error.is_none() {
            error = err;
        }
        idx += 1;

        if idx < lite_args.len() {
            trace!(
                "idx: {} working_exprs: {:#?} prec: {:?}",
                idx,
                working_exprs,
                prec
            );

            let (rhs_working_expr, err) =
                parse_possibly_parenthesized(&lite_args[idx], registry, shorthand_mode);

            if error.is_none() {
                error = err;
            }

            let next_prec = op.precedence();

            if !prec.is_empty() && next_prec > *prec.last().expect("this shouldn't happen") {
                prec.push(next_prec);
                working_exprs.push((None, op));
                working_exprs.push(rhs_working_expr);
            } else {
                while !prec.is_empty()
                    && *prec.last().expect("This shouldn't happen") >= next_prec
                    && next_prec > 0 // Not garbage
                    && working_exprs.len() >= 3
                {
                    // Pop 3 and create and expression, push and repeat
                    trace!(
                        "idx: {} working_exprs: {:#?} prec: {:?}",
                        idx,
                        working_exprs,
                        prec
                    );
                    let (_, right) = working_exprs.pop().expect("This shouldn't be possible");
                    let (_, op) = working_exprs.pop().expect("This shouldn't be possible");
                    let (orig_left, left) =
                        working_exprs.pop().expect("This shouldn't be possible");

                    // If we're in shorthand mode, we need to reparse the left-hand side if possibe
                    let (left, err) = shorthand_reparse(left, orig_left, registry, shorthand_mode);
                    if error.is_none() {
                        error = err;
                    }

                    let span = Span::new(left.span.start(), right.span.end());
                    working_exprs.push((
                        None,
                        SpannedExpression {
                            expr: Expression::Binary(Box::new(Binary { left, op, right })),
                            span,
                        },
                    ));
                    prec.pop();
                }
                working_exprs.push((None, op));
                working_exprs.push(rhs_working_expr);
                prec.push(next_prec);
            }

            idx += 1;
        } else {
            if error.is_none() {
                error = Some(ParseError::argument_error(
                    lite_args[idx - 1].clone(),
                    ArgumentError::MissingMandatoryPositional("right hand side".into()),
                ));
            }
            working_exprs.push((None, garbage(op.span)));
            working_exprs.push((None, garbage(op.span)));
            prec.push(0);
        }
    }

    while working_exprs.len() >= 3 {
        // Pop 3 and create and expression, push and repeat
        let (_, right) = working_exprs.pop().expect("This shouldn't be possible");
        let (_, op) = working_exprs.pop().expect("This shouldn't be possible");
        let (orig_left, left) = working_exprs.pop().expect("This shouldn't be possible");

        let (left, err) = shorthand_reparse(left, orig_left, registry, shorthand_mode);
        if error.is_none() {
            error = err;
        }

        let span = Span::new(left.span.start(), right.span.end());
        working_exprs.push((
            None,
            SpannedExpression {
                expr: Expression::Binary(Box::new(Binary { left, op, right })),
                span,
            },
        ));
    }

    let (orig_left, left) = working_exprs.pop().expect("This shouldn't be possible");
    let (left, err) = shorthand_reparse(left, orig_left, registry, shorthand_mode);
    if error.is_none() {
        error = err;
    }

    (incoming_idx + idx, left, error)
}
/// Handle parsing math expressions, complete with working with the precedence of the operators
Handle parsing math expressions, complete with working with the precedence of the operators
Handle parsing math expressions complete with working with the precedence of the operators
fn parse_math_expression(
    incoming_idx: usize,
    lite_args: &[Spanned<String>],
    registry: &dyn SignatureRegistry,
    shorthand_mode: bool,
) -> (usize, SpannedExpression, Option<ParseError>) {
    // Precedence parsing is included
    // Short_hand mode means that the left-hand side of an expression can point to a column-path. To make this possible,
    //   we parse as normal, but then go back and when we detect a left-hand side, reparse that value if it's a string
    let mut idx = 0;
    let mut error = None;
    let mut working_exprs = vec![];
    let mut prec = vec![];
    let (lhs_working_expr, err) =
        parse_possibly_parenthesized(&lite_args[idx], registry, shorthand_mode);
    if error.is_none() {
        error = err;
    }
    working_exprs.push(lhs_working_expr);
    idx += 1;
    prec.push(0);
    while idx < lite_args.len() {
        let (op, err) = parse_arg(SyntaxShape::Operator, registry, &lite_args[idx]);
        if error.is_none() {
            error = err;
        }
        idx += 1;
        if idx < lite_args.len() {
            trace!(
                "idx: {} working_exprs: {:#?} prec: {:?}",
                idx,
                working_exprs,
                prec
            );
            let (rhs_working_expr, err) =
                parse_possibly_parenthesized(&lite_args[idx], registry, shorthand_mode);
            if error.is_none() {
                error = err;
            }
            let next_prec = op.precedence();
            if !prec.is_empty() && next_prec > *prec.last().expect("this shouldn't happen") {
                prec.push(next_prec);
                working_exprs.push((None, op));
                working_exprs.push(rhs_working_expr);
            } else {
                while !prec.is_empty()
                    && *prec.last().expect("This shouldn't happen") >= next_prec
                    && next_prec > 0 // Not garbage
                    && working_exprs.len() >= 3
                {
                    // Pop 3 and create and expression, push and repeat
                    trace!(
                        "idx: {} working_exprs: {:#?} prec: {:?}",
                        idx,
                        working_exprs,
                        prec
                    );
                    let (_, right) = working_exprs.pop().expect("This shouldn't be possible");
                    let (_, op) = working_exprs.pop().expect("This shouldn't be possible");
                    let (orig_left, left) =
                        working_exprs.pop().expect("This shouldn't be possible");
                    // If we're in shorthand mode, we need to reparse the left-hand side if possibe
                    let (left, err) = shorthand_reparse(left, orig_left, registry, shorthand_mode);
                    if error.is_none() {
                        error = err;
                    }
                    let span = Span::new(left.span.start(), right.span.end());
                    working_exprs.push((
                        None,
                        SpannedExpression {
                            expr: Expression::Binary(Box::new(Binary { left, op, right })),
                            span,
                        },
                    ));
                    prec.pop();
                }
                working_exprs.push((None, op));
                working_exprs.push(rhs_working_expr);
                prec.push(next_prec);
            }
            idx += 1;
        } else {
            if error.is_none() {
                error = Some(ParseError::argument_error(
                    lite_args[idx - 1].clone(),
                    ArgumentError::MissingMandatoryPositional("right hand side".into()),
                ));
            }
            working_exprs.push((None, garbage(op.span)));
            working_exprs.push((None, garbage(op.span)));
            prec.push(0);
        }
    }
    while working_exprs.len() >= 3 {
        // Pop 3 and create and expression, push and repeat
        let (_, right) = working_exprs.pop().expect("This shouldn't be possible");
        let (_, op) = working_exprs.pop().expect("This shouldn't be possible");
        let (orig_left, left) = working_exprs.pop().expect("This shouldn't be possible");
        let (left, err) = shorthand_reparse(left, orig_left, registry, shorthand_mode);
        if error.is_none() {
            error = err;
        }
        let span = Span::new(left.span.start(), right.span.end());
        working_exprs.push((
            None,
            SpannedExpression {
                expr: Expression::Binary(Box::new(Binary { left, op, right })),
                span,
            },
        ));
    }
    let (orig_left, left) = working_exprs.pop().expect("This shouldn't be possible");
    let (left, err) = shorthand_reparse(left, orig_left, registry, shorthand_mode);
    if error.is_none() {
        error = err;
    }
    (incoming_idx + idx, left, error)
}
fn parse_math_expression ( incoming_idx : usize , lite_args : & [ Spanned < String > ] , registry : & dyn SignatureRegistry , shorthand_mode : bool , ) -> ( usize , SpannedExpression , Option < ParseError > ) { // Precedence parsing is included // Short_hand mode means that the left-hand side of an expression can point to a column-path. To make this possible, //   we parse as normal, but then go back and when we detect a left-hand side, reparse that value if it's a string let mut idx = 0 ; let mut error = None ; let mut working_exprs = vec ! [ ] ; let mut prec = vec ! [ ] ; let ( lhs_working_expr , err ) = parse_possibly_parenthesized ( & lite_args [ idx ] , registry , shorthand_mode ) ; if error . is_none ( ) { error = err ; } working_exprs . push ( lhs_working_expr ) ; idx += 1 ; prec . push ( 0 ) ; while idx < lite_args . len ( ) { let ( op , err ) = parse_arg ( SyntaxShape :: Operator , registry , & lite_args [ idx ] ) ; if error . is_none ( ) { error = err ; } idx += 1 ; if idx < lite_args . len ( ) { trace ! ( " " idx working_exprs prec ) ; let ( rhs_working_expr , err ) = parse_possibly_parenthesized ( & lite_args [ idx ] , registry , shorthand_mode ) ; if error . is_none ( ) { error = err ; } let next_prec = op . precedence ( ) ; if ! prec . is_empty ( ) && next_prec > * prec . last ( ) . expect ( " " ) { prec . push ( next_prec ) ; working_exprs . push ( ( None , op ) ) ; working_exprs . push ( rhs_working_expr ) ; } else { while ! prec . is_empty ( ) && * prec . last ( ) . expect ( " " ) >= next_prec && next_prec > 0 // Not garbage && working_exprs . len ( ) >= 3 { // Pop 3 and create and expression, push and repeat trace ! ( " " idx working_exprs prec ) ; let ( _ , right ) = working_exprs . pop ( ) . expect ( " " ) ; let ( _ , op ) = working_exprs . pop ( ) . expect ( " " ) ; let ( orig_left , left ) = working_exprs . pop ( ) . expect ( " " ) ; // If we're in shorthand mode, we need to reparse the left-hand side if possibe let ( left , err ) = shorthand_reparse ( left , orig_left , registry , shorthand_mode ) ; if error . is_none ( ) { error = err ; } let span = Span :: new ( left . span . start ( ) , right . span . end ( ) ) ; working_exprs . push ( ( None , SpannedExpression { expr : Expression :: Binary ( Box :: new ( Binary { left , op , right } ) ) , span , } , ) ) ; prec . pop ( ) ; } working_exprs . push ( ( None , op ) ) ; working_exprs . push ( rhs_working_expr ) ; prec . push ( next_prec ) ; } idx += 1 ; } else { if error . is_none ( ) { error = Some ( ParseError :: argument_error ( lite_args [ idx - 1 ] . clone ( ) , ArgumentError :: MissingMandatoryPositional ( " " . into ( ) ) , ) ) ; } working_exprs . push ( ( None , garbage ( op . span ) ) ) ; working_exprs . push ( ( None , garbage ( op . span ) ) ) ; prec . push ( 0 ) ; } } while working_exprs . len ( ) >= 3 { // Pop 3 and create and expression, push and repeat let ( _ , right ) = working_exprs . pop ( ) . expect ( " " ) ; let ( _ , op ) = working_exprs . pop ( ) . expect ( " " ) ; let ( orig_left , left ) = working_exprs . pop ( ) . expect ( " " ) ; let ( left , err ) = shorthand_reparse ( left , orig_left , registry , shorthand_mode ) ; if error . is_none ( ) { error = err ; } let span = Span :: new ( left . span . start ( ) , right . span . end ( ) ) ; working_exprs . push ( ( None , SpannedExpression { expr : Expression :: Binary ( Box :: new ( Binary { left , op , right } ) ) , span , } , ) ) ; } let ( orig_left , left ) = working_exprs . pop ( ) . expect ( " " ) ; let ( left , err ) = shorthand_reparse ( left , orig_left , registry , shorthand_mode ) ; if error . is_none ( ) { error = err ; } ( incoming_idx + idx , left , error ) }
Handle parsing math expressions, complete with working with the precedence of the operators
Handle parsing math expressions complete with working with the precedence of the operators
incoming_idx
usize
lite_args
&[Spanned<String>]
registry
&dyn SignatureRegistry
shorthand_mode
bool
incoming_idx
usize
lite_args
&[Spanned<String>]
registry
&dyn SignatureRegistry
shorthand_mode
bool