From f82a05580728052b92abf6b1b88c57701cbbb314 Mon Sep 17 00:00:00 2001 From: slavek-kucera <53339291+slavek-kucera@users.noreply.github.com> Date: Tue, 12 Nov 2024 12:32:14 +0100 Subject: [PATCH] refactor: Streamline macro operand grammar --- .../parsing/grammar/macro_operand_rules.g4 | 44 ++++++++----------- parser_library/test/context/macro_test.cpp | 17 +++++++ 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/parser_library/src/parsing/grammar/macro_operand_rules.g4 b/parser_library/src/parsing/grammar/macro_operand_rules.g4 index f63284ddf..70dad789d 100644 --- a/parser_library/src/parsing/grammar/macro_operand_rules.g4 +++ b/parser_library/src/parsing/grammar/macro_operand_rules.g4 @@ -121,43 +121,35 @@ mac_entry_basic_tokens [concat_chain* chain] lpar { std::vector sublist; - bool pending_empty = false; + bool pending_empty = true; + bool entered = false; } - ( - comma - { - sublist.emplace_back(); - pending_empty = true; - } - )* ( mac_entry { sublist.push_back(std::move($mac_entry.chain)); pending_empty = false; + entered = true; + } + )? + ( + comma + { + entered = true; + if (pending_empty) + sublist.emplace_back(); + pending_empty = true; } ( - comma - ( - comma - { - sublist.emplace_back(); - } - )* + mac_entry { - pending_empty = true; + sublist.push_back(std::move($mac_entry.chain)); + pending_empty = false; } - ( - mac_entry - { - sublist.push_back(std::move($mac_entry.chain)); - pending_empty = false; - } - )? - )* - )? + )? + )* { - if (pending_empty) + if (entered && pending_empty) { sublist.emplace_back(); } diff --git a/parser_library/test/context/macro_test.cpp b/parser_library/test/context/macro_test.cpp index 2c98e85c6..79ad4ce6c 100644 --- a/parser_library/test/context/macro_test.cpp +++ b/parser_library/test/context/macro_test.cpp @@ -1275,3 +1275,20 @@ TEST(macro, nested_invalid_prototype) EXPECT_TRUE(matches_message_codes(a.diags(), { "E043" })); } + +TEST(macro, nested_parenthesis_with_attributes) +{ + std::string input = R"( + MACRO + MAC + MEND + + MAC (XXXXXXX,L'XXXXXXXXXXXXXXXXXXXXX,(XXXXXXXXXXXXXXXXXXXX+ + X,XXXXX),XXXXXXX),(XXXXX,L'XXXXXXXXXXXXXXXXXX, + + (XXXXXXXXXXXXXXXXXX,XXXXX),XXXXXXX) +)"; + analyzer a(input); + a.analyze(); + + EXPECT_TRUE(a.diags().empty()); +}