Files
python-uncompyle6/uncompyle6/parsers/reducecheck/except_handler_else.py
rocky fedd5e0ba5 Better "try" vs. "try"/"else" disambiguation ...
via reduction check that was originally only in 2.7
2020-01-09 22:37:02 -05:00

28 lines
1016 B
Python

# Copyright (c) 2020 Rocky Bernstein
def except_handler_else(self, lhs, n, rule, ast, tokens, first, last):
# FIXME: expand this to other versions
if self.version not in (2.7, 3.5):
return False
if tokens[first] in ("JUMP_FORWARD", "JUMP_ABSOLUTE"):
first_jump_target = tokens[first].pattr
last = min(last, len(tokens)-1)
for i in range(last, first, -1):
if tokens[i] == "END_FINALLY":
i -= 1
second_jump = tokens[i]
if second_jump in ("JUMP_FORWARD", "JUMP_ABSOLUTE"):
second_jump_target = second_jump.pattr
equal_target = second_jump_target == first_jump_target
if equal_target:
return lhs != "except_handler"
else:
return lhs != "except_handler_else"
pass
else:
return False
pass
pass
return False