Skip to content

Commit

Permalink
rename unwind_operators_stack -> unwind_operators_stack_to
Browse files Browse the repository at this point in the history
  • Loading branch information
39555 committed Nov 16, 2024
1 parent 6a488c2 commit ebddbb8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/combinator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ mod multi;
mod parser;
mod sequence;

mod shunting_yard;

#[cfg(test)]
mod tests;

Expand Down
8 changes: 4 additions & 4 deletions src/combinator/shunting_yard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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
// }
Expand Down Expand Up @@ -140,7 +141,7 @@ fn evaluate<Operand>(stack: &mut Vec<Operand>, op: Operator<'_, Operand>) {
};
}

fn unwind_operators_stack<Operand>(
fn unwind_operators_stack_to<Operand>(
current_left_power: usize,
value_stack: &mut Vec<Operand>,
operator_stack: &mut Vec<Operator<'_, Operand>>,
Expand All @@ -165,7 +166,6 @@ mod tests {
use super::*;

fn parser(i: &mut &str) -> PResult<i32> {
// TODO: how to elide the closure type without ugly `as _`
precedence(
trace(
"operand",
Expand Down

0 comments on commit ebddbb8

Please sign in to comment.