From 5e83592b5d5a50fb36f128980a08d04fdae3bd5f Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Tue, 19 Dec 2023 18:46:41 +1300 Subject: Report preceding label name on assembly error When the assembler encounters an error, the erroneous line and the line number are output in order to help the user to find where in the input file the error occurred. This is useful for single-file inputs, but the line number is generally not helpful if the input file was generated by concatenating multiple files. In order to help the user to determine where in the program source the error occurred, the assembler now reports the name of the label which directly precedes the erroneous line. --- src/semantic_token.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/semantic_token.rs') diff --git a/src/semantic_token.rs b/src/semantic_token.rs index 77ba892..265db91 100644 --- a/src/semantic_token.rs +++ b/src/semantic_token.rs @@ -21,6 +21,7 @@ pub struct SemanticToken { pub r#type: SemanticTokenType, pub source_location: SourceLocation, pub bytecode_location: BytecodeLocation, + pub parent_label: Option, } impl SemanticToken { @@ -28,6 +29,7 @@ impl SemanticToken { pub fn print_error(&self, source_code: &str) -> bool { let mut is_error = false; macro_rules! red {()=>{eprint!("\x1b[31m")};} + macro_rules! dim {()=>{eprint!("\x1b[0;2m")};} macro_rules! normal {()=>{eprint!("\x1b[0m")};} if let SemanticTokenType::Error(token, error) = &self.r#type { @@ -60,6 +62,11 @@ impl SemanticToken { }; eprintln!("Invalid token in macro definition, macro definitions are not allowed to contain {name}") } } + + if let Some(label) = &self.parent_label { + eprint!(" ... "); red!(); eprint!("| "); dim!(); eprintln!("@{label} "); normal!(); + } + let line = source_code.split('\n').nth(self.source_location.start.line).unwrap(); eprint!("{:>5} ", self.source_location.start.line+1); red!(); eprint!("| "); normal!(); -- cgit v1.2.3-70-g09d2