Fix precedence parse (#298)

This commit is contained in:
JT 2021-11-06 20:31:28 +13:00 committed by GitHub
parent d401ed64ed
commit 6c31377c21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 26 deletions

View File

@ -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);

View File

@ -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")
}