diff options
| author | Ben Bridle <ben@derelict.engineering> | 2025-12-30 13:20:26 +1300 |
|---|---|---|
| committer | Ben Bridle <ben@derelict.engineering> | 2025-12-30 14:00:45 +1300 |
| commit | 0de8aef53a2e9e86340bae3d051a1d5d8372ec99 (patch) | |
| tree | 1a6b177c25e212bf6d687b23fd88e315c73b28d1 /src/stages | |
| parent | 29e847768ae5d6fe7e631c668d23536729dbe8d8 (diff) | |
| download | torque-asm-0de8aef53a2e9e86340bae3d051a1d5d8372ec99.zip | |
Improve 'expected block token in macro definition' error message
When a macro definition body contains more than one token, every token
must be a block token. When a non-block token is included in one of
these macro definitions, an error points to the offending token and
says that a block token was expected in this macro definition.
The change that this commit makes is to also point to the top of the
macro definition to make it clearer that this macro definition is part
of the problem, not just the errant integer or list by itself. Without
this, the error message could be read to say that the integer or list
itself is a macro definition, which could be confusing.
Diffstat (limited to 'src/stages')
| -rw-r--r-- | src/stages/semantic.rs | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/stages/semantic.rs b/src/stages/semantic.rs index f96a0c5..1e8df56 100644 --- a/src/stages/semantic.rs +++ b/src/stages/semantic.rs @@ -101,7 +101,7 @@ impl SemanticParser { while let Some(argument) = parser.pull_argument_definition() { arguments.push(argument); } - let body = parser.parse_macro_definition_body(SemanticLocation::MacroDefinitionBody); + let body = parser.parse_macro_definition_body(&definition.name.source); self.pull_from(parser); let definition = MacroDefinition { name: definition.name, arguments, body }; let semantic = SemanticToken::MacroDefinition(definition); @@ -121,8 +121,9 @@ impl SemanticParser { } /// Parse the remaining syntactic tokens as a macro definition body. - fn parse_macro_definition_body(&mut self, location: SemanticLocation) -> MacroDefinitionBody { + fn parse_macro_definition_body(&mut self, source: &SourceSpan) -> MacroDefinitionBody { let mut tokens = Vec::new(); + let location = SemanticLocation::MacroDefinitionBody; while !self.syntactic.is_empty() { if let Some(token) = self.pull_macro_definition_body_token() { tokens.push(token); @@ -138,7 +139,7 @@ impl SemanticParser { match token { MacroDefinitionBody::Integer(integer) => { let error = SemanticError::ExpectedBlock(location); - let tracked = Tracked::from(error, integer.source); + let tracked = Tracked::from(error, source.wrap(integer.source)); self.errors.push(tracked); } MacroDefinitionBody::Block(mut tokens) => { @@ -146,7 +147,7 @@ impl SemanticParser { } MacroDefinitionBody::List(list) => { let error = SemanticError::ExpectedBlock(location); - let tracked = Tracked::from(error, list.source); + let tracked = Tracked::from(error, source.wrap(list.source)); self.errors.push(tracked); } MacroDefinitionBody::Invocation(invocation) => { |
