mirror of
https://github.com/davidhalter/parso.git
synced 2026-08-12 19:11:34 +08:00
Some slight changes to error recovery
This commit is contained in:
+13
-11
@@ -162,17 +162,19 @@ class Parser(BaseParser):
|
|||||||
# possible (and valid in Python ) that there's no newline at the
|
# possible (and valid in Python ) that there's no newline at the
|
||||||
# end of a file, we have to recover even if the user doesn't want
|
# end of a file, we have to recover even if the user doesn't want
|
||||||
# error recovery.
|
# error recovery.
|
||||||
#print('x', pprint.pprint(stack))
|
if stack[-1].dfa.from_rule == 'simple_stmt':
|
||||||
ilabel = token_to_ilabel(pgen_grammar, NEWLINE, value)
|
ilabel = token_to_ilabel(pgen_grammar, NEWLINE, value)
|
||||||
try:
|
try:
|
||||||
plan = stack[-1].dfa.ilabel_to_plan[ilabel]
|
plan = stack[-1].dfa.ilabel_to_plan[ilabel]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if plan.next_dfa.is_final and not plan.dfa_pushes:
|
if plan.next_dfa.is_final and not plan.dfa_pushes:
|
||||||
stack[-1].dfa = plan.next_dfa
|
# We are ignoring here that the newline would be
|
||||||
add_token_callback(typ, value, start_pos, prefix)
|
# required for a simple_stmt.
|
||||||
return
|
stack[-1].dfa = plan.next_dfa
|
||||||
|
add_token_callback(typ, value, start_pos, prefix)
|
||||||
|
return
|
||||||
|
|
||||||
if not self._error_recovery:
|
if not self._error_recovery:
|
||||||
return super(Parser, self).error_recovery(
|
return super(Parser, self).error_recovery(
|
||||||
|
|||||||
Reference in New Issue
Block a user