Fix 3.8 grammar rule bug: "for" with "if"/"return"

This commit is contained in:
rocky
2020-01-23 06:07:34 -05:00
parent 29715bb8bf
commit 5951f974d5
4 changed files with 11 additions and 9 deletions

View File

@@ -1,6 +1,8 @@
# from mult_by_const/instruction.py
# Bug in 3.8 was handling no JUMP_BACK in "for" loop. It is
# in the "if" instead
# RUNNABLE!
def instruction_sequence_value(instrs, a, b):
for instr in instrs:
if a:

View File

@@ -85,7 +85,7 @@ class Python38Parser(Python37Parser):
# 3.8 can push a looping JUMP_BACK into into a JUMP_ from a statement that jumps to it
lastl_stmt ::= ifpoplaststmtl
ifpoplaststmtl ::= testexpr POP_TOP c_stmts_opt JUMP_BACK
ifpoplaststmtl ::= testexpr POP_TOP c_stmts_opt
ifelsestmtl ::= testexpr c_stmts_opt jb_cfs else_suitel JUMP_BACK come_froms
# Keep indices the same in ifelsestmtl

View File

@@ -471,19 +471,19 @@ MAP_R0 = (TABLE_R0, -1, 0)
MAP_R = (TABLE_R, -1)
MAP = {
'stmt': MAP_R,
'call': MAP_R,
'del_stmt': MAP_R,
'store': MAP_R,
'exprlist': MAP_R0,
"stmt": MAP_R,
"call": MAP_R,
"del_stmt": MAP_R,
"store": MAP_R,
"exprlist": MAP_R0,
}
ASSIGN_TUPLE_PARAM = lambda param_name: \
SyntaxTree('expr', [ Token('LOAD_FAST', pattr=param_name) ])
SyntaxTree("expr", [ Token("LOAD_FAST", pattr=param_name) ])
escape = re.compile(r'''
escape = re.compile(r"""
(?P<prefix> [^%]* )
% ( \[ (?P<child> -? \d+ ) \] )?
((?P<type> [^{] ) |
( [{] (?P<expr> [^}]* ) [}] ))
''', re.VERBOSE)
""", re.VERBOSE)