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,35 +2916,35 @@ pub fn parse_math_expression(
|
|||||||
let (rhs, err) = parse_value(working_set, spans[idx], &SyntaxShape::Any);
|
let (rhs, err) = parse_value(working_set, spans[idx], &SyntaxShape::Any);
|
||||||
error = error.or(err);
|
error = error.or(err);
|
||||||
|
|
||||||
if op_prec <= last_prec {
|
if op_prec <= last_prec && expr_stack.len() > 1 {
|
||||||
while expr_stack.len() > 1 {
|
// Collapse the right associated operations first
|
||||||
// Collapse the right associated operations first
|
// so that we can get back to a stack with a lower precedence
|
||||||
// so that we can get back to a stack with a lower precedence
|
let mut rhs = expr_stack
|
||||||
let mut rhs = expr_stack
|
.pop()
|
||||||
.pop()
|
.expect("internal error: expression stack empty");
|
||||||
.expect("internal error: expression stack empty");
|
let mut op = expr_stack
|
||||||
let mut op = expr_stack
|
.pop()
|
||||||
.pop()
|
.expect("internal error: expression stack empty");
|
||||||
.expect("internal error: expression stack empty");
|
|
||||||
let mut lhs = expr_stack
|
|
||||||
.pop()
|
|
||||||
.expect("internal error: expression stack empty");
|
|
||||||
|
|
||||||
if let Some(row_var_id) = lhs_row_var_id {
|
let mut lhs = expr_stack
|
||||||
expand_to_cell_path(working_set, &mut lhs, row_var_id);
|
.pop()
|
||||||
}
|
.expect("internal error: expression stack empty");
|
||||||
|
|
||||||
let (result_ty, err) = math_result_type(working_set, &mut lhs, &mut op, &mut rhs);
|
if let Some(row_var_id) = lhs_row_var_id {
|
||||||
error = error.or(err);
|
expand_to_cell_path(working_set, &mut lhs, row_var_id);
|
||||||
|
|
||||||
let op_span = span(&[lhs.span, rhs.span]);
|
|
||||||
expr_stack.push(Expression {
|
|
||||||
expr: Expr::BinaryOp(Box::new(lhs), Box::new(op), Box::new(rhs)),
|
|
||||||
span: op_span,
|
|
||||||
ty: result_ty,
|
|
||||||
custom_completion: None,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let (result_ty, err) = math_result_type(working_set, &mut lhs, &mut op, &mut rhs);
|
||||||
|
error = error.or(err);
|
||||||
|
|
||||||
|
let op_span = span(&[lhs.span, rhs.span]);
|
||||||
|
expr_stack.push(Expression {
|
||||||
|
expr: Expr::BinaryOp(Box::new(lhs), Box::new(op), Box::new(rhs)),
|
||||||
|
span: op_span,
|
||||||
|
ty: result_ty,
|
||||||
|
custom_completion: None,
|
||||||
|
});
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
expr_stack.push(op);
|
expr_stack.push(op);
|
||||||
expr_stack.push(rhs);
|
expr_stack.push(rhs);
|
||||||
|
@ -844,3 +844,8 @@ fn update_cell_path_1() -> TestResult {
|
|||||||
fn range_and_reduction() -> TestResult {
|
fn range_and_reduction() -> TestResult {
|
||||||
run_test(r#"1..6..36 | math sum"#, "148")
|
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