From 491f75f6e977c0d2520c2a405c473e81a2179ca0 Mon Sep 17 00:00:00 2001 From: Sebastian Hugentobler Date: Mon, 10 Feb 2025 14:45:11 +0100 Subject: [PATCH] add synchronize to rust --- rust/rox/src/parser.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/rust/rox/src/parser.rs b/rust/rox/src/parser.rs index dbd8dae..a2b0079 100644 --- a/rust/rox/src/parser.rs +++ b/rust/rox/src/parser.rs @@ -191,6 +191,17 @@ impl Parser { 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.