Make repeat rules left-recursive instead of right recursive
This commit is contained in:
parent
0ea2962fbe
commit
cf19b2e58d
2 changed files with 21 additions and 21 deletions
|
|
@ -19,9 +19,9 @@ describe("expand_repeats", []() {
|
|||
|
||||
AssertThat(result.variables, Equals(vector<Variable>({
|
||||
Variable("rule0", VariableTypeNamed, i_sym(1)),
|
||||
Variable("rule0_repeat1", VariableTypeAuxiliary, seq({
|
||||
Variable("rule0_repeat1", VariableTypeAuxiliary, choice({
|
||||
seq({ i_sym(1), i_token(0) }),
|
||||
i_token(0),
|
||||
choice({ i_sym(1), blank() })
|
||||
})),
|
||||
})));
|
||||
});
|
||||
|
|
@ -41,9 +41,9 @@ describe("expand_repeats", []() {
|
|||
i_token(10),
|
||||
i_sym(1),
|
||||
})),
|
||||
Variable("rule0_repeat1", VariableTypeAuxiliary, seq({
|
||||
i_token(11),
|
||||
choice({ i_sym(1), blank() })
|
||||
Variable("rule0_repeat1", VariableTypeAuxiliary, choice({
|
||||
seq({ i_sym(1), i_token(11) }),
|
||||
i_token(11)
|
||||
})),
|
||||
})));
|
||||
});
|
||||
|
|
@ -63,9 +63,9 @@ describe("expand_repeats", []() {
|
|||
i_token(10),
|
||||
i_sym(1),
|
||||
})),
|
||||
Variable("rule0_repeat1", VariableTypeAuxiliary, seq({
|
||||
Variable("rule0_repeat1", VariableTypeAuxiliary, choice({
|
||||
seq({ i_sym(1), i_token(11) }),
|
||||
i_token(11),
|
||||
choice({ i_sym(1), blank() }),
|
||||
})),
|
||||
})));
|
||||
});
|
||||
|
|
@ -93,9 +93,9 @@ describe("expand_repeats", []() {
|
|||
i_token(3),
|
||||
i_sym(2),
|
||||
})),
|
||||
Variable("rule0_repeat1", VariableTypeAuxiliary, seq({
|
||||
Variable("rule0_repeat1", VariableTypeAuxiliary, choice({
|
||||
seq({ i_sym(2), i_token(4) }),
|
||||
i_token(4),
|
||||
choice({ i_sym(2), blank() }),
|
||||
})),
|
||||
})));
|
||||
});
|
||||
|
|
@ -115,13 +115,13 @@ describe("expand_repeats", []() {
|
|||
i_sym(1),
|
||||
i_sym(2),
|
||||
})),
|
||||
Variable("rule0_repeat1", VariableTypeAuxiliary, seq({
|
||||
Variable("rule0_repeat1", VariableTypeAuxiliary, choice({
|
||||
seq({ i_sym(1), i_token(10) }),
|
||||
i_token(10),
|
||||
choice({ i_sym(1), blank() }),
|
||||
})),
|
||||
Variable("rule0_repeat2", VariableTypeAuxiliary, seq({
|
||||
Variable("rule0_repeat2", VariableTypeAuxiliary, choice({
|
||||
seq({ i_sym(2), i_token(11) }),
|
||||
i_token(11),
|
||||
choice({ i_sym(2), blank() }),
|
||||
})),
|
||||
})));
|
||||
});
|
||||
|
|
@ -137,13 +137,13 @@ describe("expand_repeats", []() {
|
|||
AssertThat(result.variables, Equals(vector<Variable>({
|
||||
Variable("rule0", VariableTypeNamed, i_sym(2)),
|
||||
Variable("rule1", VariableTypeNamed, i_sym(3)),
|
||||
Variable("rule0_repeat1", VariableTypeAuxiliary, seq({
|
||||
Variable("rule0_repeat1", VariableTypeAuxiliary, choice({
|
||||
seq({ i_sym(2), i_token(10) }),
|
||||
i_token(10),
|
||||
choice({ i_sym(2), blank() }),
|
||||
})),
|
||||
Variable("rule1_repeat1", VariableTypeAuxiliary, seq({
|
||||
Variable("rule1_repeat1", VariableTypeAuxiliary, choice({
|
||||
seq({ i_sym(3), i_token(11) }),
|
||||
i_token(11),
|
||||
choice({ i_sym(3), blank() })
|
||||
})),
|
||||
})));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -41,10 +41,10 @@ class ExpandRepeats : public rules::IdentityRuleFn {
|
|||
string helper_rule_name = rule_name + "_repeat" + to_string(++repeat_count);
|
||||
Symbol repeat_symbol(offset + index);
|
||||
existing_repeats.push_back({ rule->copy(), repeat_symbol });
|
||||
aux_rules.push_back(Variable(
|
||||
helper_rule_name, VariableTypeAuxiliary,
|
||||
Seq::build({ inner_rule, Choice::build({ repeat_symbol.copy(),
|
||||
make_shared<Blank>() }) })));
|
||||
aux_rules.push_back(
|
||||
Variable(helper_rule_name, VariableTypeAuxiliary,
|
||||
Choice::build({ Seq::build({ repeat_symbol.copy(), inner_rule }),
|
||||
inner_rule })));
|
||||
return repeat_symbol.copy();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue