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()); +}