Proper precedence history in math (#1966)

This commit is contained in:
Jonathan Turner 2020-06-11 10:17:08 -07:00 committed by GitHub
parent a3e1a3f266
commit 982f067d0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View File

@ -84,6 +84,18 @@ fn division_of_ints2() {
assert_eq!(actual.out, "0.25");
}
#[test]
fn proper_precedence_history() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
= 2 / 2 / 2 + 1
"#
));
assert_eq!(actual.out, "1.5");
}
#[test]
fn parens_precedence() {
let actual = nu!(

View File

@ -861,10 +861,8 @@ fn parse_math_expression(
shorthand_mode: bool,
) -> (usize, SpannedExpression, Option<ParseError>) {
// Precedence parsing is included
// Some notes:
// * 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
// * parens are handled earlier, so they're not handled explicitly here
// 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;
@ -948,6 +946,7 @@ fn parse_math_expression(
}
working_exprs.push((None, op));
working_exprs.push(rhs_working_expr);
prec.push(next_prec);
}
idx += 1;