Skip to content

Commit

Permalink
Clean up inefficient token handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Cypher1 committed May 16, 2024
1 parent 9d1183f commit ca3dd1d
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions takolib/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ impl<'src, 'toks, T: Iterator<Item = &'toks Token>> ParseState<'src, 'toks, T> {
) -> Result<OnTok, ParseError> {
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<Token, ParseError> {
Expand Down Expand Up @@ -579,9 +578,9 @@ impl<'src, 'toks, T: Iterator<Item = &'toks Token>> 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;
Expand All @@ -593,9 +592,7 @@ impl<'src, 'toks, T: Iterator<Item = &'toks Token>> 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,
Expand Down

0 comments on commit ca3dd1d

Please sign in to comment.