From ebddbb8a04568b348a02ed08cff8fa97a8982bcf Mon Sep 17 00:00:00 2001 From: Igor Date: Sat, 16 Nov 2024 13:30:42 +0400 Subject: [PATCH] rename `unwind_operators_stack` -> `unwind_operators_stack_to` --- src/combinator/mod.rs | 2 ++ src/combinator/shunting_yard.rs | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/combinator/mod.rs b/src/combinator/mod.rs index df791ada..ec3d401a 100644 --- a/src/combinator/mod.rs +++ b/src/combinator/mod.rs @@ -166,6 +166,8 @@ mod multi; mod parser; mod sequence; +mod shunting_yard; + #[cfg(test)] mod tests; diff --git a/src/combinator/shunting_yard.rs b/src/combinator/shunting_yard.rs index e109b189..934aff5b 100644 --- a/src/combinator/shunting_yard.rs +++ b/src/combinator/shunting_yard.rs @@ -76,7 +76,7 @@ where // Postfix unary operators if let Some((lpower, op)) = opt(postfix.by_ref()).parse_next(i)? { - unwind_operators_stack(lpower, &mut value_stack, &mut operator_stack); + unwind_operators_stack_to(lpower, &mut value_stack, &mut operator_stack); // postfix operators are never put in pending state in `operator_stack` // TODO: confirm that `expect` is valid for all invariants @@ -87,7 +87,7 @@ where // Infix binary operators if let Some((lpower, rpower, op)) = opt(infix.by_ref()).parse_next(i)? { - unwind_operators_stack(lpower, &mut value_stack, &mut operator_stack); + unwind_operators_stack_to(lpower, &mut value_stack, &mut operator_stack); operator_stack.push(Operator::Binary(lpower, rpower, op)); waiting_operand = true; continue 'parse; @@ -101,6 +101,7 @@ where while let Some(op) = operator_stack.pop() { evaluate(&mut value_stack, op); } + // TODO: when it can happen? // if eval_stack.len() > 1 { // // Error: value left on stack // } @@ -140,7 +141,7 @@ fn evaluate(stack: &mut Vec, op: Operator<'_, Operand>) { }; } -fn unwind_operators_stack( +fn unwind_operators_stack_to( current_left_power: usize, value_stack: &mut Vec, operator_stack: &mut Vec>, @@ -165,7 +166,6 @@ mod tests { use super::*; fn parser(i: &mut &str) -> PResult { - // TODO: how to elide the closure type without ugly `as _` precedence( trace( "operand",