summaryrefslogtreecommitdiff
path: root/src/semantic_token.rs
diff options
context:
space:
mode:
authorBen Bridle <bridle.benjamin@gmail.com>2023-12-19 18:46:41 +1300
committerBen Bridle <bridle.benjamin@gmail.com>2023-12-19 18:46:49 +1300
commit5e83592b5d5a50fb36f128980a08d04fdae3bd5f (patch)
tree025656107591d1b6c53f5c2a744b36099dcca27a /src/semantic_token.rs
parent360a13ad170a8eb52cf125749129168581ace7fe (diff)
downloadbedrock-asm-5e83592b5d5a50fb36f128980a08d04fdae3bd5f.zip
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.
Diffstat (limited to 'src/semantic_token.rs')
-rw-r--r--src/semantic_token.rs7
1 files changed, 7 insertions, 0 deletions
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<String>,
}
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!();