You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 09:22:40 +08:00
Towards fixing a 3.2 while true: ... break bug
This commit is contained in:
@@ -696,12 +696,19 @@ class Python3Parser(PythonParser):
|
|||||||
self.check_reduce['augassign1'] = 'AST'
|
self.check_reduce['augassign1'] = 'AST'
|
||||||
self.check_reduce['augassign2'] = 'AST'
|
self.check_reduce['augassign2'] = 'AST'
|
||||||
self.check_reduce['while1stmt'] = 'noAST'
|
self.check_reduce['while1stmt'] = 'noAST'
|
||||||
|
# FIXME: remove parser errors caused by the below
|
||||||
|
# self.check_reduce['while1elsestmt'] = 'noAST'
|
||||||
return
|
return
|
||||||
|
|
||||||
def reduce_is_invalid(self, rule, ast, tokens, first, last):
|
def reduce_is_invalid(self, rule, ast, tokens, first, last):
|
||||||
lhs = rule[0]
|
lhs = rule[0]
|
||||||
if lhs in ('augassign1', 'augassign2') and ast[0][0] == 'and':
|
if lhs in ('augassign1', 'augassign2') and ast[0][0] == 'and':
|
||||||
return True
|
return True
|
||||||
|
elif lhs == 'while1elsestmt':
|
||||||
|
last += 1
|
||||||
|
while isinstance(tokens[last], str):
|
||||||
|
last += 1
|
||||||
|
return tokens[first].attr != tokens[last].offset
|
||||||
elif lhs == 'while1stmt':
|
elif lhs == 'while1stmt':
|
||||||
if tokens[last] in ('COME_FROM_LOOP', 'JUMP_BACK'):
|
if tokens[last] in ('COME_FROM_LOOP', 'JUMP_BACK'):
|
||||||
# jump_back should be right afer SETUP_LOOP. Test?
|
# jump_back should be right afer SETUP_LOOP. Test?
|
||||||
|
@@ -19,6 +19,11 @@ class Python32Parser(Python3Parser):
|
|||||||
COME_FROM_LOOP
|
COME_FROM_LOOP
|
||||||
whileTruestmt ::= SETUP_LOOP return_stmts
|
whileTruestmt ::= SETUP_LOOP return_stmts
|
||||||
COME_FROM_LOOP
|
COME_FROM_LOOP
|
||||||
|
|
||||||
|
# Python 3.2+ has more loop optimization that removes
|
||||||
|
# JUMP_FORWARD in some cases, and hence we also don't
|
||||||
|
# see COME_FROM
|
||||||
|
_ifstmts_jump ::= c_stmts_opt
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@@ -21,11 +21,6 @@ class Python33Parser(Python32Parser):
|
|||||||
iflaststmt ::= testexpr c_stmts_opt33
|
iflaststmt ::= testexpr c_stmts_opt33
|
||||||
c_stmts_opt33 ::= JUMP_BACK JUMP_ABSOLUTE c_stmts_opt
|
c_stmts_opt33 ::= JUMP_BACK JUMP_ABSOLUTE c_stmts_opt
|
||||||
_ifstmts_jump ::= c_stmts_opt JUMP_FORWARD _come_from
|
_ifstmts_jump ::= c_stmts_opt JUMP_FORWARD _come_from
|
||||||
|
|
||||||
# Python 3.3+ has more loop optimization that removes
|
|
||||||
# JUMP_FORWARD in some cases, and hence we also don't
|
|
||||||
# see COME_FROM
|
|
||||||
_ifstmts_jump ::= c_stmts_opt
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class Python33ParserSingle(Python33Parser, PythonParserSingle):
|
class Python33ParserSingle(Python33Parser, PythonParserSingle):
|
||||||
|
Reference in New Issue
Block a user