From 68eab722293393a91ac01ab6809a0e7fcb74b51c Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Fri, 22 Jun 2018 01:59:39 +0200 Subject: [PATCH] Some slight changes to error recovery --- parso/python/parser.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/parso/python/parser.py b/parso/python/parser.py index f05f1a8..32fff51 100644 --- a/parso/python/parser.py +++ b/parso/python/parser.py @@ -162,17 +162,19 @@ class Parser(BaseParser): # 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 # error recovery. - #print('x', pprint.pprint(stack)) - ilabel = token_to_ilabel(pgen_grammar, NEWLINE, value) - try: - plan = stack[-1].dfa.ilabel_to_plan[ilabel] - except KeyError: - pass - else: - if plan.next_dfa.is_final and not plan.dfa_pushes: - stack[-1].dfa = plan.next_dfa - add_token_callback(typ, value, start_pos, prefix) - return + if stack[-1].dfa.from_rule == 'simple_stmt': + ilabel = token_to_ilabel(pgen_grammar, NEWLINE, value) + try: + plan = stack[-1].dfa.ilabel_to_plan[ilabel] + except KeyError: + pass + else: + if plan.next_dfa.is_final and not plan.dfa_pushes: + # We are ignoring here that the newline would be + # required for a simple_stmt. + stack[-1].dfa = plan.next_dfa + add_token_callback(typ, value, start_pos, prefix) + return if not self._error_recovery: return super(Parser, self).error_recovery(