From 343a15b77ece1674ca49719f04b6189bb26d220e Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Mon, 13 Oct 2025 13:26:10 +1300 Subject: Add a specific error for nested macro definitions This case was previously being reported with the message "The macro definition was not terminated, add a ';' character to terminate", which was not very helpful. --- src/stages/syntactic.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/stages/syntactic.rs') diff --git a/src/stages/syntactic.rs b/src/stages/syntactic.rs index a1ba833..227b399 100644 --- a/src/stages/syntactic.rs +++ b/src/stages/syntactic.rs @@ -4,10 +4,10 @@ use assembler::Tokeniser; pub fn parse_syntactic>(source_code: &str, path: Option

) -> Result>, Vec>> { - parse_syntactic_from_tokeniser(Tokeniser::new(source_code, path)) + parse_syntactic_from_tokeniser(Tokeniser::new(source_code, path), false) } -fn parse_syntactic_from_tokeniser(mut t: Tokeniser) -> Result>, Vec>> { +fn parse_syntactic_from_tokeniser(mut t: Tokeniser, in_macro: bool) -> Result>, Vec>> { t.add_delimiters(&['@','&','%',';',':','|','{','}','(',')','[',']','#','~','"','\'']); let mut tokens = Vec::new(); let mut errors = Vec::new(); @@ -77,7 +77,7 @@ fn parse_syntactic_from_tokeniser(mut t: Tokeniser) -> Result SyntacticToken::BlockLiteral(tokens), Err(mut parse_errors) => { errors.append(&mut parse_errors); @@ -93,7 +93,7 @@ fn parse_syntactic_from_tokeniser(mut t: Tokeniser) -> Result SyntacticToken::Expression(tokens), Err(mut parse_errors) => { errors.append(&mut parse_errors); @@ -121,11 +121,14 @@ fn parse_syntactic_from_tokeniser(mut t: Tokeniser) -> Result { let name = t.eat_token(); + if in_macro { + err!(SyntacticError::MacroDefinitionInMacroDefinition); + } let source = t.get_source(); t.mark_child(); if let Some(_) = t.track_until(is_any!(';')) { let child = t.tokenise_child_span(); - match parse_syntactic_from_tokeniser(child) { + match parse_syntactic_from_tokeniser(child, true) { Ok(body) => { let name = Tracked::from(name, source); let definition = SyntacticMacroDefinition { name, body }; -- cgit v1.2.3-70-g09d2