Fix 3.2 for/if loopback bug

problem was handling in Python 3.2

 for ...
    if ...
    else:
      ....
      jump for
    come from if
    jump for

In later Python 3's a "come from" is removed.

Also, start to DRY parser{,2,3} grammar rules.
This commit is contained in:
rocky
2016-05-08 12:09:50 -04:00
parent 4a79082872
commit a65a8bb68e
6 changed files with 60 additions and 40 deletions

View File

@@ -350,26 +350,21 @@ class Python3Parser(PythonParser):
l_stmts_opt JUMP_BACK
POP_BLOCK
else_suitec COME_FROM
_for ::= GET_ITER FOR_ITER
_for ::= LOAD_CONST FOR_LOOP
for_block ::= l_stmts_opt JUMP_BACK
for_block ::= return_stmts _come_from
forstmt ::= SETUP_LOOP expr _for designator
for_block POP_BLOCK _come_from
forelsestmt ::= SETUP_LOOP expr _for designator
for_block POP_BLOCK else_suite COME_FROM
forelselaststmt ::= SETUP_LOOP expr _for designator
for_block POP_BLOCK else_suitec COME_FROM
forelselaststmtl ::= SETUP_LOOP expr _for designator
for_block POP_BLOCK else_suitel COME_FROM
'''
def p_for3(self, args):
"""
# In Python 3.2 JUMP_ABSOLUTE's (which can
# turn into COME_FROM's) are not optimized as
# they are in later Python's.
#
# So an if statement can jump to the end of a for loop
# which in turn jump's back to the beginning of that loop.
#
# Therefore we allow COME_FROM JUMP_BACK below.
for_block ::= l_stmts_opt COME_FROM JUMP_BACK
"""
def p_genexpr3(self, args):
'''
load_genexpr ::= LOAD_GENEXPR