add synchronize to rust

This commit is contained in:
Sebastian Hugentobler 2025-02-10 14:45:11 +01:00
parent ae959f7768
commit 491f75f6e9

View File

@ -191,6 +191,17 @@ impl Parser {
Err(ParserError::ExpressionExpected(prev.line)) Err(ParserError::ExpressionExpected(prev.line))
} }
} }
fn synchronize(&mut self) {
let _ = self.advance();
while !self.is_at_end()
&& self.previous().unwrap().token_type != Semicolon
&& !&[Class, Fun, Var, For, If, While, Print, Return]
.contains(&self.current_token.token_type)
{
let _ = self.advance();
}
}
} }
/// Try to parse the provided tokens into an AST. /// Try to parse the provided tokens into an AST.