Parser - Synchronize method

This commit is contained in:
Emmanuel BENOîT 2022-12-31 12:27:51 +01:00
parent 32dab4ad27
commit 7b66c35e16

View file

@ -29,6 +29,27 @@ impl Parser {
}
}
/// Synchronize the parser after an error.
fn _synchronize(&mut self) {
self.advance();
while !self.is_at_end() {
if self.previous().token_type == TokenType::Semicolon
|| matches!(
self.peek().token_type,
TokenType::Class
| TokenType::Fun
| TokenType::If
| TokenType::Print
| TokenType::Return
| TokenType::Var
| TokenType::While
)
{
return;
}
}
}
/* ------------------------ *
* RECURSIVE DESCENT PARSER *
* ------------------------ */