Avoid creating redundant auxiliary repeat rules

This commit is contained in:
Max Brunsfeld 2015-04-16 17:42:22 -07:00
parent 9ef52ce2fb
commit e8db35af6b
3 changed files with 2227 additions and 2263 deletions

View file

@ -67,6 +67,28 @@ describe("expand_repeats", []() {
})));
});
it("does not create redundant auxiliary rules", [&]() {
SyntaxGrammar grammar({
{ "rule0", choice({
seq({ i_token(1), repeat(i_token(3)) }),
seq({ i_token(2), repeat(i_token(3)) }) }) },
}, {}, set<Symbol>());
auto match = expand_repeats(grammar);
AssertThat(match.rules, Equals(rule_list({
{ "rule0", choice({
seq({ i_token(1), choice({ i_aux_sym(0), blank() }) }),
seq({ i_token(2), choice({ i_aux_sym(0), blank() }) }) }) },
})));
AssertThat(match.aux_rules, Equals(rule_list({
{ "rule0_repeat0", seq({
i_token(3),
choice({ i_aux_sym(0), blank() }) }) },
})));
});
it("can replace multiple repeats in the same rule", [&]() {
SyntaxGrammar grammar({
{ "rule0", seq({