diff --git a/takolib/src/parser/mod.rs b/takolib/src/parser/mod.rs index 544baa55..88ee47be 100644 --- a/takolib/src/parser/mod.rs +++ b/takolib/src/parser/mod.rs @@ -175,8 +175,7 @@ impl<'src, 'toks, T: Iterator> ParseState<'src, 'toks, T> { ) -> Result { let tk = self.peek()?; let res = test(tk)?; - self.token() - .expect("Internal error: Token missing after check"); + let Some(_) = self.token() else { unreachable!() }; Ok(res) } fn token_of_type(&mut self, expected: TokenType) -> Result { @@ -579,9 +578,9 @@ impl<'src, 'toks, T: Iterator> ParseState<'src, 'toks, T> { break; } trace!("Continuing Expr: {left:?} sym: {symbol:?} inside binding: {binding:?}"); + let token = self.token().expect("Internal error"); + let location = token.location(); if symbol == Symbol::OpenParen { - let token = self.token().expect("Internal error"); - let location = token.location(); // Require an 'apply' to balance it's parens. let mut args = vec![]; let mut _has_non_bind_args = false; @@ -593,9 +592,7 @@ impl<'src, 'toks, T: Iterator> ParseState<'src, 'toks, T> { left = self.ast.add_call(Call { inner: left, args }, location); } else { // TODO: Check that this is the right kind of operator. - let token = self.token().expect("Internal error"); let right = self.expr(symbol)?; - let location = token.location(); left = self.ast.add_op( Op { op: symbol,