From 9ef2d17bcc4ce878c6934eb87c1e2efc59b779ad Mon Sep 17 00:00:00 2001 From: Lancelot Liu Date: Thu, 6 Feb 2025 16:52:57 +0000 Subject: [PATCH] fix: Removes erroneous `next_power` calculation in `do_parse_infix`. --- src/pratt.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/pratt.rs b/src/pratt.rs index 216f72be..fc52e1c8 100644 --- a/src/pratt.rs +++ b/src/pratt.rs @@ -595,12 +595,7 @@ where } }; - let next_power = match assoc { - Associativity::Non(_) => assoc.next_power(), - _ => assoc.right_power(), - }; - - let rhs = match f(inp, next_power) { + let rhs = match f(inp, assoc.right_power()) { Ok(rhs) => rhs, Err(()) => { inp.rewind(pre_op.clone()); @@ -1317,6 +1312,10 @@ mod tests { infix(non(2), just('*'), |l, _, r, _| i(Expr::Mul, l, r)), )) .map(|x| x.to_string()); - assert!(parser.parse("1+2*3*3").has_errors()) + assert_eq!( + parser.parse("1+2*3").into_result(), + Ok("(1 + (2 * 3))".to_string()) + ); + assert!(parser.parse("1+2*3*3").has_errors()); } }