From 8dfdd603b022ab9775cda08b9c2350d43667ff0f Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Sun, 26 Nov 2023 10:29:55 +1300 Subject: Exit with status 1 on assembly error This will break unix pipelines in order to prevent any emulator down the pipeline from attempting to run a malassembled program. --- src/semantic_token.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/semantic_token.rs') diff --git a/src/semantic_token.rs b/src/semantic_token.rs index 3d08b25..77ba892 100644 --- a/src/semantic_token.rs +++ b/src/semantic_token.rs @@ -24,11 +24,15 @@ pub struct SemanticToken { } impl SemanticToken { - pub fn print_error(&self, source_code: &str) { + /// Returns true if an error was printed. + pub fn print_error(&self, source_code: &str) -> bool { + let mut is_error = false; macro_rules! red {()=>{eprint!("\x1b[31m")};} macro_rules! normal {()=>{eprint!("\x1b[0m")};} if let SemanticTokenType::Error(token, error) = &self.r#type { + is_error = true; + red!(); eprint!("[ERROR] "); normal!(); let source = &self.source_location.source; match error { @@ -70,11 +74,12 @@ impl SemanticToken { } normal!(); eprintln!(); } - if let SemanticTokenType::MacroDefinition(definition) = &self.r#type { + else if let SemanticTokenType::MacroDefinition(definition) = &self.r#type { for token in &definition.body_tokens { - token.print_error(source_code); + if token.print_error(source_code) { is_error = true } } } + is_error } } -- cgit v1.2.3-70-g09d2