Skip to content

Commit

Permalink
refactor: Streamline macro operand grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
slavek-kucera authored Nov 12, 2024
1 parent 9c908ac commit f82a055
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 26 deletions.
44 changes: 18 additions & 26 deletions parser_library/src/parsing/grammar/macro_operand_rules.g4
Original file line number Diff line number Diff line change
Expand Up @@ -121,43 +121,35 @@ mac_entry_basic_tokens [concat_chain* chain]
lpar
{
std::vector<concat_chain> 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();
}
Expand Down
17 changes: 17 additions & 0 deletions parser_library/test/context/macro_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

0 comments on commit f82a055

Please sign in to comment.