Skip to content

Commit 4a35426

Browse files
committed
Adjust 3.7 chained compare for adjusted grammar
Add test for last change
1 parent cd64156 commit 4a35426

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed
394 Bytes
Binary file not shown.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Bug in 3.6 was not taking "else" branch after compond "if"
2+
# In earlier versions we had else detection needed here.
3+
4+
def f(a, b, c):
5+
if a and b:
6+
x = 1
7+
else:
8+
x = 2
9+
if c:
10+
x = 3
11+
return(x)
12+
13+
assert f(True, True, True) == 3
14+
assert f(True, True, False) == 1
15+
assert f(True, False, True) == 3
16+
assert f(True, False, False) == 2

uncompyle6/parsers/parse37.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2017-2018 Rocky Bernstein
1+
# Copyright (c) 2017-2019 Rocky Bernstein
22
#
33
# This program is free software: you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License as published by
@@ -73,11 +73,11 @@ def p_37misc(self, args):
7373
compare_chained37 ::= expr compare_chained1a_37
7474
compare_chained37 ::= expr compare_chained1b_37
7575
compare_chained2a_37 ::= expr COMPARE_OP POP_JUMP_IF_TRUE JUMP_FORWARD
76-
compare_chained2b_37 ::= expr COMPARE_OP POP_JUMP_IF_FALSE JUMP_FORWARD
76+
compare_chained2b_37 ::= expr COMPARE_OP COME_FROM POP_JUMP_IF_FALSE JUMP_FORWARD ELSE
7777
compare_chained1a_37 ::= expr DUP_TOP ROT_THREE COMPARE_OP POP_JUMP_IF_FALSE
7878
compare_chained2a_37 ELSE POP_TOP COME_FROM
7979
compare_chained1b_37 ::= expr DUP_TOP ROT_THREE COMPARE_OP POP_JUMP_IF_FALSE
80-
compare_chained2b_37 ELSE POP_TOP JUMP_FORWARD COME_FROM
80+
compare_chained2b_37 POP_TOP JUMP_FORWARD COME_FROM
8181
"""
8282

8383
def customize_grammar_rules(self, tokens, customize):

uncompyle6/semantics/customize3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ def return_closure(node):
922922
(-4, 19)),
923923
'compare_chained1b_37': ( ' %[3]{pattr.replace("-", " ")} %p %p',
924924
(0, 19),
925-
(-5, 19)),
925+
(-4, 19)),
926926
'compare_chained2a_37': ( '%[1]{pattr.replace("-", " ")} %p', (0, 19)),
927927

928928
'compare_chained2b_37': ( '%[1]{pattr.replace("-", " ")} %p', (0, 19)),

0 commit comments

Comments
 (0)