diff --git a/Cargo.toml b/Cargo.toml index 3d77ed7..ad3a18e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ getset = "0.1.2" mlua = { version = "0.9.7", features = ["lua54", "vendored"], optional = true } path-absolutize = "3.1.1" serde = { version = "1.0.197", features = ["derive", "rc"], optional = true } -shulkerbox = { git = "https://github.com/moritz-hoelting/shulkerbox", default-features = false, optional = true, rev = "e31f9f904a5f5905e912907d988c189ffc8cf313" } +shulkerbox = { git = "https://github.com/moritz-hoelting/shulkerbox", default-features = false, optional = true, rev = "7efe73eb80fb66d3d9eb67eeb7bcb10727462956" } strum = { version = "0.26.2", features = ["derive"] } strum_macros = "0.26.2" thiserror = "1.0.58" diff --git a/src/base/diagnostic.rs b/src/base/diagnostic.rs index eea017d..1b1a4a3 100644 --- a/src/base/diagnostic.rs +++ b/src/base/diagnostic.rs @@ -1,7 +1,9 @@ /// Represents a trait responsible for handling diagnostics in the interpreter. pub trait Handler { /// Receive an error and handles it. - fn receive(&self, error: T); + fn receive>(&self, error: E); + /// Returns whether the handler has received any error. + fn has_received(&self) -> bool; } /// Is a struct that implements [`Handler`] trait by doing nothing with the errors. @@ -9,5 +11,8 @@ pub trait Handler { pub struct DummyHandler; impl Handler for DummyHandler { - fn receive(&self, _error: T) {} + fn receive>(&self, _error: E) {} + fn has_received(&self) -> bool { + false + } } diff --git a/src/lexical/token.rs b/src/lexical/token.rs index 29fef4e..713d2d3 100644 --- a/src/lexical/token.rs +++ b/src/lexical/token.rs @@ -492,12 +492,9 @@ impl Token { } .into()) } else { - handler.receive( - UnterminatedDelimitedComment { - span: Span::new(iter.source_file().clone(), start, start + 2).unwrap(), - } - .into(), - ); + handler.receive(UnterminatedDelimitedComment { + span: Span::new(iter.source_file().clone(), start, start + 2).unwrap(), + }); return Err(TokenizeError::FatalLexicalError); } } diff --git a/src/lexical/token_stream.rs b/src/lexical/token_stream.rs index 5dac97e..21c1f12 100644 --- a/src/lexical/token_stream.rs +++ b/src/lexical/token_stream.rs @@ -92,7 +92,7 @@ impl TokenStream { fn handle_popped_token( tokens: &mut Vec, popped_token: Token, - handler: &dyn Handler, + handler: &impl Handler, ) -> Option { match popped_token { Token::Punctuation(punc) if punc.punctuation == '{' => { @@ -116,7 +116,7 @@ impl TokenStream { tokens: &mut Vec, open: Punctuation, delimiter: Delimiter, - handler: &dyn Handler, + handler: &impl Handler, ) -> Option { let mut token_trees = Vec::new(); diff --git a/src/lib.rs b/src/lib.rs index 4f93630..9177dab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -107,9 +107,13 @@ impl Printer { } } -impl Handler for Printer { - fn receive(&self, error: E) { - eprintln!("{error}"); +impl Handler for Printer { + fn receive>(&self, error: E) { + eprintln!("{}", error.into()); self.printed.set(true); } + + fn has_received(&self) -> bool { + self.printed.get() + } } diff --git a/src/syntax/parser.rs b/src/syntax/parser.rs index 6e3f1c4..e66a917 100644 --- a/src/syntax/parser.rs +++ b/src/syntax/parser.rs @@ -42,7 +42,7 @@ impl<'a> Parser<'a> { &mut self, delimiter: Delimiter, f: impl FnOnce(&mut Self) -> Option, - handler: &dyn Handler, + handler: &impl Handler, ) -> Option> { self.current_frame.stop_at_significant(); let raw_token_tree = self diff --git a/src/syntax/syntax_tree/program.rs b/src/syntax/syntax_tree/program.rs index 5da2935..6389c77 100644 --- a/src/syntax/syntax_tree/program.rs +++ b/src/syntax/syntax_tree/program.rs @@ -102,13 +102,10 @@ impl<'a> Parser<'a> { }) } unexpected => { - handler.receive( - UnexpectedSyntax { - expected: SyntaxKind::Keyword(KeywordKind::Namespace), - found: unexpected.into_token(), - } - .into(), - ); + handler.receive(UnexpectedSyntax { + expected: SyntaxKind::Keyword(KeywordKind::Namespace), + found: unexpected.into_token(), + }); None } }?; diff --git a/src/syntax/syntax_tree/statement/execute_block.rs b/src/syntax/syntax_tree/statement/execute_block.rs index 5e79010..86ff1f2 100644 --- a/src/syntax/syntax_tree/statement/execute_block.rs +++ b/src/syntax/syntax_tree/statement/execute_block.rs @@ -775,13 +775,10 @@ impl<'a> Parser<'a> { handler, ), unexpected => { - handler.receive( - UnexpectedSyntax { - expected: SyntaxKind::Punctuation('('), - found: unexpected.into_token(), - } - .into(), - ); + handler.receive(UnexpectedSyntax { + expected: SyntaxKind::Punctuation('('), + found: unexpected.into_token(), + }); None } }?; @@ -795,13 +792,10 @@ impl<'a> Parser<'a> { // unexpected unexpected => { - handler.receive( - UnexpectedSyntax { - expected: SyntaxKind::ExecuteBlock, - found: unexpected.into_token(), - } - .into(), - ); + handler.receive(UnexpectedSyntax { + expected: SyntaxKind::ExecuteBlock, + found: unexpected.into_token(), + }); None } } @@ -833,13 +827,10 @@ impl<'a> Parser<'a> { } unexpected => { - handler.receive( - UnexpectedSyntax { - expected: SyntaxKind::ExecuteBlockTail, - found: unexpected.into_token(), - } - .into(), - ); + handler.receive(UnexpectedSyntax { + expected: SyntaxKind::ExecuteBlockTail, + found: unexpected.into_token(), + }); None } }