refactor stack_pop to be simpler
The semantics of this will end up being a little different in that this will now pop first and then match string. However, since we now checkpoint around errors which can allow the parser to continue, practically speaking there is no behavioral difference.
@@ -858,23 +858,12 @@ impl<'i, R: RuleType> ParserState<'i, R> {
/// assert_eq!(result.unwrap().position().pos(), 2);
/// ```
#[inline]
- pub fn stack_pop(self: Box<Self>) -> ParseResult<Box<Self>> {
- let result_state = {
+ pub fn stack_pop(mut self: Box<Self>) -> ParseResult<Box<Self>> {
let string = self.stack
- .peek()
+ .pop()
.expect("pop was called on empty stack")
.as_str();
-
self.match_string(string)
- };
-
- match result_state {
- Ok(mut state) => {
- state.stack.pop();
- Ok(state)
- }
- Err(state) => Err(state)
- }
}
/// Drops the top of the stack and returns `Ok(Box<ParserState>)` if there was a value to
