Another Python 3 closure grammar bug

This commit is contained in:
rocky
2016-05-09 06:21:23 -04:00
parent 73461d323e
commit e63bcd54e9
4 changed files with 36 additions and 2 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,25 @@
# Tests bug in Python 3
# load_closure ::= LOAD_CLOSURE BUILD_TUPLE_1
# Python 3.5
# mkfunc ::= load_closure LOAD_CONST LOAD_CONST MAKE_CLOSURE_0
# Python 3.2
# mkfunc ::= load_closure LOAD_CONST MAKE_CLOSURE_0
# mkfuncdeco0 ::= mkfunc
# mkfuncdeco ::= expr mkfuncdeco0 CALL_FUNCTION_1
# designator ::= STORE_FAST
# funcdefdeco ::= mkfuncdeco designator
# stmt ::= funcdefdeco
from functools import wraps
def contextmanager(func):
@wraps(func)
def helper(*args, **kwds):
return _GeneratorContextManager(func, *args, **kwds)
return helper

View File

@@ -528,10 +528,19 @@ class Python3Parser(PythonParser):
'expr GET_ITER CALL_FUNCTION_1' %
('expr '* token.attr, opname),
opname, token.attr, customize)
rule = ('mkfunc ::= %s load_closure BUILD_TUPLE_1 LOAD_CONST LOAD_CONST %s'
rule = ('mkfunc ::= %s load_closure LOAD_CONST %s'
% ('expr ' * token.attr, opname))
# Python 3.5+ instead of above?
rule = ('mkfunc ::= %s load_closure LOAD_CONST LOAD_CONST %s'
% ('expr ' * token.attr, opname))
self.add_unique_rule(rule, opname, token.attr, customize)
rule = ('mkfunc ::= %s load_closure load_genexpr %s'
% ('expr ' * token.attr, opname))
self.add_unique_rule(rule, opname, token.attr, customize)
rule = ('mkfunc ::= %s load_closure BUILD_TUPLE_1 LOAD_GENXPR LOAD_CONST %s'
rule = ('mkfunc ::= %s load_closure LOAD_CONST %s'
% ('expr ' * token.attr, opname))
self.add_unique_rule(rule, opname, token.attr, customize)
return