Yet another Python 3.x COME_FROM grammar problem

This commit is contained in:
rocky
2016-05-08 13:08:12 -04:00
parent a65a8bb68e
commit 400153ea53
4 changed files with 30 additions and 18 deletions

Binary file not shown.

View File

@@ -0,0 +1,25 @@
# Python 3 bugs with multiple COME_FROMs
# Tests:
# 160 POP_TOP ''
# 161 JUMP_BACK '118' # to: for name in names
# 164 JUMP_BACK '118' # to: for name in names after endif
# 167 POP_BLOCK '' # ends for loop
# 168_0 COME_FROM '63' # end of if os.path is...
# 168_1 COME_FROM '108' # end of first result.append(name) in if/then
# 168_2 COME_FROM '111' # end of "for name in names" in else
import os
import posixpath
def filter(names, pat):
result = []
pat = os.path.normcase(pat)
match = _compile_pattern(pat, isinstance(pat, bytes))
if os.path is posixpath:
for name in names:
if match(name):
result.append(name)
else:
for name in names:
if match(os.path.normcase(name)):
result.append(name) # bug here

View File

@@ -166,20 +166,20 @@ class PythonParser(GenericASTBuilder):
_for ::= GET_ITER FOR_ITER
_for ::= LOAD_CONST FOR_LOOP
for_block ::= l_stmts_opt JUMP_BACK
for_block ::= l_stmts_opt _come_from 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
for_block POP_BLOCK else_suite _come_from
forelselaststmt ::= SETUP_LOOP expr _for designator
for_block POP_BLOCK else_suitec COME_FROM
for_block POP_BLOCK else_suitec _come_from
forelselaststmtl ::= SETUP_LOOP expr _for designator
for_block POP_BLOCK else_suitel COME_FROM
for_block POP_BLOCK else_suitel _come_from
"""
def p_import20(self, args):
@@ -223,7 +223,7 @@ class PythonParser(GenericASTBuilder):
list_iter ::= list_if_not
list_iter ::= lc_body
_come_from ::= COME_FROM
_come_from ::= _come_from COME_FROM
_come_from ::=
list_if ::= expr jmp_false list_iter

View File

@@ -352,19 +352,6 @@ class Python3Parser(PythonParser):
else_suitec 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