Fix 3.x generator bug...

found by Daniel Brandburn. See
af61622960
This commit is contained in:
rocky
2016-05-21 05:05:03 -04:00
parent 95bc1a76cb
commit 09f6286bec
6 changed files with 29 additions and 10 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,24 @@
# Had bug in Python 3.x
# Should see (Python 2.x and 3.x:
# get_iter ::= expr GET_ITER
# expr ::= get_iter
# _for ::= GET_ITER FOR_ITER
# designator ::= STORE_FAST
# expr ::= LOAD_FAST
# yield ::= expr YIELD_VALUE
# expr ::= yield
# gen_comp_body ::= expr YIELD_VALUE POP_TOP
# comp_body ::= gen_comp_body
# comp_iter ::= comp_body
# comp_for ::= expr _for designator comp_iter JUMP_BACK
# comp_iter ::= comp_for
# genexpr_func ::= LOAD_FAST FOR_ITER designator comp_iter JUMP_BACK
def multi_genexpr(blog_posts):
return (
entry
for blog_post in blog_posts
for entry in blog_post.entry_set
)

View File

@@ -288,6 +288,8 @@ class PythonParser(GenericASTBuilder):
comp_if ::= expr jmp_false comp_iter
comp_ifnot ::= expr jmp_true comp_iter
comp_for ::= expr _for designator comp_iter JUMP_BACK
"""
def p_expr(self, args):

View File

@@ -36,12 +36,6 @@ class Python2Parser(PythonParser):
list_for ::= expr _for designator list_iter JUMP_BACK
"""
def p_setcomp2(self, args):
'''
# This is different in python3 - should it be?
comp_for ::= expr _for designator comp_iter JUMP_BACK
'''
def p_print(self, args):
'''
stmt ::= print_items_stmt

View File

@@ -58,10 +58,9 @@ class Python3Parser(PythonParser):
def p_setcomp3(self, args):
"""
# This is different in Python 2 - should it be?
comp_for ::= expr _for designator comp_iter JUMP_ABSOLUTE
# See also common Python p_setcomp
# Does this also happen in Python 2?
# If so, adjust p_setcomp in parser.py
comp_for ::= expr _for designator comp_iter JUMP_BACK
"""
def p_grammar(self, args):