diff --git a/spec/compiler/prepare_grammar/expand_repeats_spec.cc b/spec/compiler/prepare_grammar/expand_repeats_spec.cc index 8da8ac73..c25ff47c 100644 --- a/spec/compiler/prepare_grammar/expand_repeats_spec.cc +++ b/spec/compiler/prepare_grammar/expand_repeats_spec.cc @@ -19,9 +19,9 @@ describe("expand_repeats", []() { AssertThat(result.variables, Equals(vector({ 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("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() }) })), }))); }); diff --git a/src/compiler/prepare_grammar/expand_repeats.cc b/src/compiler/prepare_grammar/expand_repeats.cc index 727b8a4d..7963e94b 100644 --- a/src/compiler/prepare_grammar/expand_repeats.cc +++ b/src/compiler/prepare_grammar/expand_repeats.cc @@ -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() }) }))); + aux_rules.push_back( + Variable(helper_rule_name, VariableTypeAuxiliary, + Choice::build({ Seq::build({ repeat_symbol.copy(), inner_rule }), + inner_rule }))); return repeat_symbol.copy(); }