From 938b40dd15f1d44f8881261a64e092fc0fd9165b Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Thu, 4 Dec 2025 16:51:03 +1300 Subject: Convert single-element lists to integers when an integer is required This allows an integer invocation with arguments to be wrapped in `[]` square brackets so that it can be passed to another invocation as an argument. --- src/stages/semantic.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/stages/semantic.rs') diff --git a/src/stages/semantic.rs b/src/stages/semantic.rs index 96cf7af..f96a0c5 100644 --- a/src/stages/semantic.rs +++ b/src/stages/semantic.rs @@ -272,10 +272,16 @@ impl SemanticParser { self.errors.push(Tracked::from(error, token.source)); None } - MacroDefinitionBody::List(list) => { - let error = SemanticError::ExpectedInteger(location); - self.errors.push(Tracked::from(error, list.source)); - None + MacroDefinitionBody::List(list) => match list.value { + // Convert a one-element list to an integer. + ListToken::ListLiteral(mut integers) if integers.len() == 1 => { + Some(integers.pop().unwrap()) + } + _ => { + let error = SemanticError::ExpectedInteger(location); + self.errors.push(Tracked::from(error, list.source)); + None + } } } } -- cgit v1.2.3-70-g09d2