Skip to content

Commit 67c4546

Browse files
committed
little sync with decompyle3
Add another forelsestmt (found only in a loop) Add precidence on walrus operator
1 parent 33bff4d commit 67c4546

2 files changed

Lines changed: 20 additions & 15 deletions

File tree

uncompyle6/parsers/parse38.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ def p_38misc(self, args):
112112
for38 ::= expr get_for_iter store for_block
113113
114114
forelsestmt38 ::= expr get_for_iter store for_block POP_BLOCK else_suite
115+
forelsestmt38 ::= expr get_for_iter store for_block JUMP_BACK _come_froms else_suite
116+
115117
forelselaststmt38 ::= expr get_for_iter store for_block POP_BLOCK else_suitec
116118
forelselaststmtl38 ::= expr get_for_iter store for_block POP_BLOCK else_suitel
117119

uncompyle6/semantics/customize38.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019 by Rocky Bernstein
1+
# Copyright (c) 2019-2020 by 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
@@ -19,7 +19,7 @@
1919
# Python 3.8+ changes
2020
#######################
2121

22-
from uncompyle6.semantics.consts import TABLE_DIRECT
22+
from uncompyle6.semantics.consts import PRECEDENCE, TABLE_DIRECT
2323

2424
def customize_for_version38(self, version):
2525

@@ -37,14 +37,15 @@ def customize_for_version38(self, version):
3737
'%|async for %c in %c:\n%+%c%-%|else:\n%+%c%-\n\n',
3838
(7, 'store'), (0, 'expr'), (8, 'for_block'), (-1, 'else_suite') ),
3939

40-
'async_with_stmt38': (
41-
'%|async with %c:\n%+%|%c%-',
42-
(0, 'expr'), 7),
40+
"async_with_stmt38": (
41+
"%|async with %c:\n%+%|%c%-",
42+
(0, "expr"), 7),
4343

44-
'async_with_as_stmt38': (
45-
'%|async with %c as %c:\n%+%|%c%-',
46-
(0, 'expr'), (6, 'store'),
47-
(7, 'suite_stmts') ),
44+
"async_with_as_stmt38": (
45+
"%|async with %c as %c:\n%+%|%c%-",
46+
(0, "expr"), (6, "store"),
47+
(7, "suite_stmts")
48+
),
4849

4950
"call_stmt": (
5051
"%|%c\n", 0
@@ -80,11 +81,13 @@ def customize_for_version38(self, version):
8081
(2, 'store'),
8182
(0, 'expr'),
8283
(3, 'for_block') ),
83-
'forelsestmt38': (
84-
'%|for %c in %c:\n%+%c%-%|else:\n%+%c%-\n\n',
85-
(2, 'store'),
86-
(0, 'expr'),
87-
(3, 'for_block'), -2 ),
84+
85+
"forelsestmt38": (
86+
"%|for %c in %c:\n%+%c%-%|else:\n%+%c%-\n\n",
87+
(2, "store"),
88+
(0, "expr"),
89+
(3, "for_block"), -1 ),
90+
8891
'forelselaststmt38': (
8992
'%|for %c in %c:\n%+%c%-%|else:\n%+%c%-',
9093
(2, 'store'),
@@ -153,6 +156,6 @@ def customize_for_version38(self, version):
153156
(2, "suite_stmts_opt"),
154157
(8, "suite_stmts_opt") ),
155158
"named_expr": ( # AKA "walrus operator"
156-
"%c := %c", (2, "store"), (0, "expr")
159+
"%c := %p", (2, "store"), (0, "expr", PRECEDENCE["named_expr"]-1)
157160
)
158161
})

0 commit comments

Comments
 (0)