Check better for more transitions

This commit is contained in:
Dave Halter
2018-06-26 22:53:02 +02:00
parent 91d864b23d
commit f66e47c540
2 changed files with 7 additions and 4 deletions

View File

@@ -282,6 +282,10 @@ def _calculate_first_plans(nonterminal_to_dfas, first_plans, nonterminal):
# We only need to check the first dfa. All the following ones are not
# interesting to find first terminals.
state = dfas[0]
for transition, next_ in state.ilabel_to_plan.items():
# It's a string. We have finally found a possible first token.
new_first_plans[transition] = [next_.next_dfa]
for nonterminal2, next_ in state.nonterminal_arcs.items():
# It's a nonterminal and we have either a left recursion issue
# in the grammar or we have to recurse.
@@ -303,9 +307,5 @@ def _calculate_first_plans(nonterminal_to_dfas, first_plans, nonterminal):
)
new_first_plans[t] = [next_] + pushes
for transition, next_ in state.ilabel_to_plan.items():
# It's a string. We have finally found a possible first token.
new_first_plans[transition] = [next_.next_dfa]
first_plans[nonterminal] = new_first_plans
return new_first_plans

View File

@@ -285,3 +285,6 @@ def test_ambiguities():
with pytest.raises(ValueError, match='ambiguous'):
generate_grammar('''foo: bar | baz\nbar: 'x'\nbaz: "x"\n''', tokenize.PythonTokenTypes)
with pytest.raises(ValueError, match='ambiguous'):
generate_grammar('''foo: bar | 'x'\nbar: 'x'\n''', tokenize.PythonTokenTypes)