diff options
| author | Miquel Sabaté Solà <mssola@mssola.com> | 2026-02-02 19:56:21 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mssola@mssola.com> | 2026-02-02 19:56:21 +0100 |
| commit | 930ad1cc4422f19251ea77a625816e3aebcc6eea (patch) | |
| tree | 6223b56dfc21a7b4278364e953e2457267518b7f /lib/xixanta/src/parser.rs | |
| parent | e6f6f514cd11e9a512abb00d16b93e800e861c58 (diff) | |
| download | tools.nes-930ad1cc4422f19251ea77a625816e3aebcc6eea.tar.gz tools.nes-930ad1cc4422f19251ea77a625816e3aebcc6eea.zip | |
xixanta: add context from macro expansions
The way macro expansions work is that the evaluated bundles replace the
current node, but this throws away the context of the line, the source,
etc. from the original line of code.
Add a stack that is pushed/popped when expanding macros, and are then
cloned for each pending node and error. This way, errors have full
context of the original code and can display backtraces for macro
expansion.
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
Diffstat (limited to 'lib/xixanta/src/parser.rs')
| -rw-r--r-- | lib/xixanta/src/parser.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/xixanta/src/parser.rs b/lib/xixanta/src/parser.rs index cf01133..7a7e3f0 100644 --- a/lib/xixanta/src/parser.rs +++ b/lib/xixanta/src/parser.rs @@ -242,6 +242,7 @@ impl Parser { global: false, source: self.sources[self.current_source].clone(), message: "expecting a number formatted with a leading '$' sign".to_string(), + expanded_from: vec![], }) } } @@ -257,6 +258,7 @@ impl Parser { global: false, source: self.sources[self.current_source].clone(), message: "expecting a number formatted with a leading '$' sign".to_string(), + expanded_from: vec![], }); } let Ok(val) = usize::from_str_radix(arg.get(1..).unwrap_or("0000"), 16) else { @@ -264,6 +266,7 @@ impl Parser { line: self.line, global: false, source: self.sources[self.current_source].clone(), + expanded_from: vec![], message: "could not parse asan:reserve number".to_string(), }); }; @@ -272,6 +275,7 @@ impl Parser { line: self.line, global: false, source: self.sources[self.current_source].clone(), + expanded_from: vec![], message: "bad asan:reserve number, should be higher than $01".to_string(), }); } @@ -460,6 +464,7 @@ impl Parser { line: self.line, global: false, source: self.sources[self.current_source].clone(), + expanded_from: vec![], message: "you cannot have a relative label inside of an identifier".to_string(), }); } @@ -484,6 +489,7 @@ impl Parser { line: self.line, global: false, source: self.sources[self.current_source].clone(), + expanded_from: vec![], message: "you can only jump to a maximum of four relative labels".to_string(), }); } @@ -497,6 +503,7 @@ impl Parser { line: self.line, global: false, source: self.sources[self.current_source].clone(), + expanded_from: vec![], message: format!("{msg} relative label can only have '{next}' characters"), }); } @@ -801,6 +808,7 @@ impl Parser { line: node.value.line, global: false, message: ".include statement cannot be inside of a code block".to_string(), + expanded_from: vec![], source: self.sources[self.current_source].clone(), } .into()); @@ -963,6 +971,7 @@ impl Parser { line: node.value.line, global: false, source: current_source.clone(), + expanded_from: vec![], message: ".include statements expect a file as the argument".to_string(), } .into()); @@ -980,6 +989,7 @@ impl Parser { line: node.value.line, global: false, source: current_source.clone(), + expanded_from: vec![], message: format!("could not open source file '{file_path}': {e}"), } .into()) @@ -990,6 +1000,7 @@ impl Parser { line: node.value.line, global: false, source: current_source.clone(), + expanded_from: vec![], message: format!("could not find out the parent directory for file '{file_path}'"), } .into()); @@ -1030,6 +1041,7 @@ impl Parser { line: node.value.line, global: false, source: self.sources[self.current_source].clone(), + expanded_from: vec![], message: format!( "path has to be written inside of double quotes ('{value}' given instead)", ), @@ -1443,6 +1455,7 @@ impl Parser { line: self.line, global: false, source: self.sources[self.current_source].clone(), + expanded_from: vec![], message: "bad literal syntax".to_string(), }); } @@ -1645,6 +1658,7 @@ impl Parser { line: self.line, global: false, source: self.sources[self.current_source].clone(), + expanded_from: vec![], message: "numeric literals cannot have white spaces".to_string(), }); } @@ -1744,6 +1758,7 @@ impl Parser { message: String::from(msg), global: false, source: self.sources[self.current_source].clone(), + expanded_from: vec![], line: self.line, } } |
