mirror of
https://github.com/nushell/nushell.git
synced 2025-01-03 13:00:08 +01:00
Fix precedence parse (#298)
This commit is contained in:
parent
d401ed64ed
commit
6c31377c21
@ -2916,8 +2916,7 @@ pub fn parse_math_expression(
|
||||
let (rhs, err) = parse_value(working_set, spans[idx], &SyntaxShape::Any);
|
||||
error = error.or(err);
|
||||
|
||||
if op_prec <= last_prec {
|
||||
while expr_stack.len() > 1 {
|
||||
if op_prec <= last_prec && expr_stack.len() > 1 {
|
||||
// Collapse the right associated operations first
|
||||
// so that we can get back to a stack with a lower precedence
|
||||
let mut rhs = expr_stack
|
||||
@ -2926,6 +2925,7 @@ pub fn parse_math_expression(
|
||||
let mut op = expr_stack
|
||||
.pop()
|
||||
.expect("internal error: expression stack empty");
|
||||
|
||||
let mut lhs = expr_stack
|
||||
.pop()
|
||||
.expect("internal error: expression stack empty");
|
||||
@ -2944,7 +2944,7 @@ pub fn parse_math_expression(
|
||||
ty: result_ty,
|
||||
custom_completion: None,
|
||||
});
|
||||
}
|
||||
// }
|
||||
}
|
||||
expr_stack.push(op);
|
||||
expr_stack.push(rhs);
|
||||
|
@ -844,3 +844,8 @@ fn update_cell_path_1() -> TestResult {
|
||||
fn range_and_reduction() -> TestResult {
|
||||
run_test(r#"1..6..36 | math sum"#, "148")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn precedence_of_or_groups() -> TestResult {
|
||||
run_test(r#"4 mod 3 == 0 || 5 mod 5 == 0"#, "true")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user