mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-06 21:04:29 +08:00
Check better for more transitions
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user