diff --git a/src/parser.rs b/src/parser.rs index 5df20d1..5fdb0a6 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -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 * * ------------------------ */