Skip to content

Commit

Permalink
fix: Removes erroneous next_power calculation in do_parse_infix.
Browse files Browse the repository at this point in the history
  • Loading branch information
lancylot2004 committed Feb 6, 2025
1 parent 258af36 commit 9ef2d17
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/pratt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
}
}

0 comments on commit 9ef2d17

Please sign in to comment.