Skip to content

Commit 4d4e59c

Browse files
committed
Towards fixing a 3.2 while true: ... break bug
1 parent 9b1dd0f commit 4d4e59c

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

uncompyle6/parsers/parse3.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,12 +696,19 @@ def add_custom_rules(self, tokens, customize):
696696
self.check_reduce['augassign1'] = 'AST'
697697
self.check_reduce['augassign2'] = 'AST'
698698
self.check_reduce['while1stmt'] = 'noAST'
699+
# FIXME: remove parser errors caused by the below
700+
# self.check_reduce['while1elsestmt'] = 'noAST'
699701
return
700702

701703
def reduce_is_invalid(self, rule, ast, tokens, first, last):
702704
lhs = rule[0]
703705
if lhs in ('augassign1', 'augassign2') and ast[0][0] == 'and':
704706
return True
707+
elif lhs == 'while1elsestmt':
708+
last += 1
709+
while isinstance(tokens[last], str):
710+
last += 1
711+
return tokens[first].attr != tokens[last].offset
705712
elif lhs == 'while1stmt':
706713
if tokens[last] in ('COME_FROM_LOOP', 'JUMP_BACK'):
707714
# jump_back should be right afer SETUP_LOOP. Test?

uncompyle6/parsers/parse32.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ def p_32to35(self, args):
1919
COME_FROM_LOOP
2020
whileTruestmt ::= SETUP_LOOP return_stmts
2121
COME_FROM_LOOP
22+
23+
# Python 3.2+ has more loop optimization that removes
24+
# JUMP_FORWARD in some cases, and hence we also don't
25+
# see COME_FROM
26+
_ifstmts_jump ::= c_stmts_opt
2227
"""
2328
pass
2429

uncompyle6/parsers/parse33.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ def p_33on(self, args):
2121
iflaststmt ::= testexpr c_stmts_opt33
2222
c_stmts_opt33 ::= JUMP_BACK JUMP_ABSOLUTE c_stmts_opt
2323
_ifstmts_jump ::= c_stmts_opt JUMP_FORWARD _come_from
24-
25-
# Python 3.3+ has more loop optimization that removes
26-
# JUMP_FORWARD in some cases, and hence we also don't
27-
# see COME_FROM
28-
_ifstmts_jump ::= c_stmts_opt
2924
"""
3025

3126
class Python33ParserSingle(Python33Parser, PythonParserSingle):

0 commit comments

Comments
 (0)