mirror of
https://github.com/nushell/nushell.git
synced 2024-11-25 01:43:47 +01:00
Proper precedence history in math (#1966)
This commit is contained in:
parent
a3e1a3f266
commit
982f067d0e
@ -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!(
|
||||
|
@ -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,
|
||||
// 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
|
||||
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user