Skip to content

Commit b28f305

Browse files
committed
Expand grammar check for ifelse continue for 2.7
1 parent 703716c commit b28f305

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

uncompyle6/parsers/reducecheck/ifelsestmt.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,8 @@
8282
),
8383
),
8484
(
85-
'ifelsestmtc',
86-
(
87-
'testexpr',
88-
'c_stmts_opt',
89-
'JUMP_FORWARD',
90-
'else_suite',
91-
'come_froms'
92-
),
85+
"ifelsestmtc",
86+
("testexpr", "c_stmts_opt", "JUMP_FORWARD", "else_suite", "come_froms"),
9387
),
9488
(
9589
"ifelsestmt",
@@ -155,7 +149,6 @@
155149

156150

157151
def ifelsestmt(self, lhs, n, rule, tree, tokens, first, last):
158-
159152
if (last + 1) < n and tokens[last + 1] == "COME_FROM_LOOP" and lhs != "ifelsestmtc":
160153
# ifelsestmt jumped outside of loop. No good.
161154
return True
@@ -176,10 +169,7 @@ def ifelsestmt(self, lhs, n, rule, tree, tokens, first, last):
176169
stmts = tree[1]
177170
if stmts in ("c_stmts",) and len(stmts) == 1:
178171
raise_stmt1 = stmts[0]
179-
if (
180-
raise_stmt1 == "raise_stmt1" and
181-
raise_stmt1[0] in ("LOAD_ASSERT",)
182-
):
172+
if raise_stmt1 == "raise_stmt1" and raise_stmt1[0] in ("LOAD_ASSERT",):
183173
return True
184174

185175
# Make sure all the offsets from the "come froms" at the
@@ -277,17 +267,18 @@ def ifelsestmt(self, lhs, n, rule, tree, tokens, first, last):
277267
# only if we are trying to match or reduce an "if"
278268
# statement of the kind that can occur only inside a
279269
# loop construct.
270+
280271
if lhs in ("ifelsestmtl", "ifelsestmtc"):
281272
jump_false = jmp
282273
if (
283-
tree[2].kind == "JUMP_FORWARD"
274+
tree[2].kind in ("JUMP_FORWARD", "JUMP_ABSOLUTE")
284275
and jump_false == "jmp_false"
285276
and len(else_suite) == 1
286277
):
287278
suite_stmts = else_suite[0]
288279
continue_stmt = suite_stmts[0]
289280
if (
290-
suite_stmts == "suite_stmts"
281+
suite_stmts in ("suite_stmts", "c_stmts")
291282
and len(suite_stmts) == 1
292283
and continue_stmt == "continue"
293284
and jump_false[0].attr == continue_stmt[0].attr

uncompyle6/scanners/scanner2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def ingest(self, co, classname=None, code_objects={}, show_asm=None):
213213
names=co.co_names,
214214
constants=co.co_consts,
215215
cells=bytecode._cell_names,
216-
linestarts=bytecode._linestarts,
216+
line_starts=bytecode._linestarts,
217217
asm_format="extended",
218218
)
219219

0 commit comments

Comments
 (0)