From 0de8aef53a2e9e86340bae3d051a1d5d8372ec99 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Tue, 30 Dec 2025 13:20:26 +1300 Subject: 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. --- src/stages/semantic.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/stages/semantic.rs') 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) => { -- cgit v1.2.3-70-g09d2