mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-10 14:41:58 +08:00
Move transition_to_generator to transitions
This commit is contained in:
@@ -174,7 +174,7 @@ class BaseParser(object):
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
plan = stack[-1].dfa.transition_to_plan[transition]
|
plan = stack[-1].dfa.transitions[transition]
|
||||||
break
|
break
|
||||||
except KeyError:
|
except KeyError:
|
||||||
if stack[-1].dfa.is_final:
|
if stack[-1].dfa.is_final:
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ class DFAState(object):
|
|||||||
self.nfa_set = nfa_set
|
self.nfa_set = nfa_set
|
||||||
self.is_final = final in nfa_set
|
self.is_final = final in nfa_set
|
||||||
self.arcs = {} # map from terminals/nonterminals to DFAState
|
self.arcs = {} # map from terminals/nonterminals to DFAState
|
||||||
self.transition_to_plan = {}
|
self.transitions = {} #: Dict[Union[TokenType, ReservedString], DFAPlan]
|
||||||
self.nonterminal_arcs = {}
|
self.nonterminal_arcs = {}
|
||||||
|
|
||||||
def add_arc(self, next_, label):
|
def add_arc(self, next_, label):
|
||||||
@@ -232,7 +232,7 @@ def generate_grammar(bnf_grammar, token_namespace):
|
|||||||
reserved_strings,
|
reserved_strings,
|
||||||
terminal_or_nonterminal
|
terminal_or_nonterminal
|
||||||
)
|
)
|
||||||
dfa_state.transition_to_plan[transition] = DFAPlan(next_dfa)
|
dfa_state.transitions[transition] = DFAPlan(next_dfa)
|
||||||
|
|
||||||
_calculate_tree_traversal(rule_to_dfas)
|
_calculate_tree_traversal(rule_to_dfas)
|
||||||
return Grammar(start_nonterminal, rule_to_dfas, reserved_strings)
|
return Grammar(start_nonterminal, rule_to_dfas, reserved_strings)
|
||||||
@@ -272,7 +272,7 @@ def _calculate_tree_traversal(nonterminal_to_dfas):
|
|||||||
for dfa_state in dfas:
|
for dfa_state in dfas:
|
||||||
for nonterminal, next_dfa in dfa_state.nonterminal_arcs.items():
|
for nonterminal, next_dfa in dfa_state.nonterminal_arcs.items():
|
||||||
for transition, pushes in first_plans[nonterminal].items():
|
for transition, pushes in first_plans[nonterminal].items():
|
||||||
dfa_state.transition_to_plan[transition] = DFAPlan(next_dfa, pushes)
|
dfa_state.transitions[transition] = DFAPlan(next_dfa, pushes)
|
||||||
|
|
||||||
|
|
||||||
def _calculate_first_plans(nonterminal_to_dfas, first_plans, nonterminal):
|
def _calculate_first_plans(nonterminal_to_dfas, first_plans, nonterminal):
|
||||||
@@ -282,7 +282,7 @@ def _calculate_first_plans(nonterminal_to_dfas, first_plans, nonterminal):
|
|||||||
# We only need to check the first dfa. All the following ones are not
|
# We only need to check the first dfa. All the following ones are not
|
||||||
# interesting to find first terminals.
|
# interesting to find first terminals.
|
||||||
state = dfas[0]
|
state = dfas[0]
|
||||||
for transition, next_ in state.transition_to_plan.items():
|
for transition, next_ in state.transitions.items():
|
||||||
# It's a string. We have finally found a possible first token.
|
# It's a string. We have finally found a possible first token.
|
||||||
new_first_plans[transition] = [next_.next_dfa]
|
new_first_plans[transition] = [next_.next_dfa]
|
||||||
|
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ class Parser(BaseParser):
|
|||||||
# error recovery.
|
# error recovery.
|
||||||
if self.stack[-1].dfa.from_rule == 'simple_stmt':
|
if self.stack[-1].dfa.from_rule == 'simple_stmt':
|
||||||
try:
|
try:
|
||||||
plan = self.stack[-1].dfa.transition_to_plan[PythonTokenTypes.NEWLINE]
|
plan = self.stack[-1].dfa.transitions[PythonTokenTypes.NEWLINE]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user