More 2.4-2.6 try vs try/else determination

This commit is contained in:
rocky
2018-02-22 20:14:52 -05:00
parent 26e65e0d90
commit 30fbdff29c
2 changed files with 45 additions and 25 deletions

View File

@@ -83,26 +83,14 @@ class Python25Parser(Python26Parser):
if self.version == 2.5:
self.check_reduce['try_except'] = 'tokens'
def reduce_is_invalid(self, rule, ast, tokens, first, last):
invalid = super(Python25Parser,
self).reduce_is_invalid(rule, ast,
tokens, first, last)
if invalid or tokens is None:
return invalid
elif rule[0] == 'try_except':
# Distinguish try/except from try/except/else
if last == len(tokens):
last -= 1
if tokens[last] != 'COME_FROM' and tokens[last-1] == 'COME_FROM':
last -= 1
if (tokens[last] == 'COME_FROM'
and tokens[last-1] == 'END_FINALLY'
and tokens[last-2] == 'POP_TOP'):
# A jump of 2 is a jump around POP_TOP, END_FINALLY which
# would indicate try/else rather than try
return (tokens[last-3].kind != 'JUMP_FORWARD'
or tokens[last-3].attr != 2)
return False
## Don't need this for 2.5 yet..
# def reduce_is_invalid(self, rule, ast, tokens, first, last):
# invalid = super(Python25Parser,
# self).reduce_is_invalid(rule, ast,
# tokens, first, last)
# if invalid or tokens is None:
# return invalid
# return False
class Python25ParserSingle(Python26Parser, PythonParserSingle):