remove unpack_list rule and ...

tidy things a bit more
This commit is contained in:
rocky
2017-11-25 00:32:13 -05:00
parent c9f3838d04
commit af38064a1b
8 changed files with 142 additions and 139 deletions

View File

@@ -19,7 +19,7 @@ def test_grammar():
expect_lhs = set(['expr1024', 'pos_arg'])
unused_rhs = set(['build_list', 'call_function', 'mkfunc',
'mklambda',
'unpack', 'unpack_list'])
'unpack',])
expect_right_recursive = frozenset([('designList',
('designator', 'DUP_TOP', 'designList'))])
if PYTHON3:

View File

@@ -104,13 +104,13 @@ check-bytecode-2.5:
#: Get grammar coverage for Python 2.5
grammar-coverage-2.5:
SPARK_PARSER_COVERAGE=/tmp/spark-grammar-25.cover $(PYTHON) test_pythonlib.py --bytecode-2.5
SPARK_PARSER_COVERAGE=/tmp/spark-grammar-25.cover $(PYTHON) test_pyenvlib.py --2.5.6
SPARK_PARSER_COVERAGE=$(COVER_DIR)/spark-grammar-25.cover $(PYTHON) test_pythonlib.py --bytecode-2.5
SPARK_PARSER_COVERAGE=$(COVER_DIR)/spark-grammar-25.cover $(PYTHON) test_pyenvlib.py --2.5.6
#: Get grammar coverage for Python 2.6
grammar-coverage-2.6:
SPARK_PARSER_COVERAGE=/tmp/spark-grammar-26.cover $(PYTHON) test_pythonlib.py --bytecode-2.6
SPARK_PARSER_COVERAGE=/tmp/spark-grammar-26.cover $(PYTHON) test_pyenvlib.py --2.6.9
SPARK_PARSER_COVERAGE=$(COVER_DIR)/spark-grammar-26.cover $(PYTHON) test_pythonlib.py --bytecode-2.6
SPARK_PARSER_COVERAGE=$(COVER_DIR)/spark-grammar-26.cover $(PYTHON) test_pyenvlib.py --2.6.9
#: Get grammar coverage for Python 2.7
grammar-coverage-2.7:

Binary file not shown.

View File

@@ -549,15 +549,14 @@ class PythonParser(GenericASTBuilder):
## designLists ::=
## Will need to redo semantic actiion
designator ::= STORE_FAST
designator ::= STORE_NAME
designator ::= STORE_GLOBAL
designator ::= STORE_DEREF
designator ::= expr STORE_ATTR
designator ::= store_subscr
designator ::= STORE_FAST
designator ::= STORE_NAME
designator ::= STORE_GLOBAL
designator ::= STORE_DEREF
designator ::= expr STORE_ATTR
designator ::= store_subscr
store_subscr ::= expr expr STORE_SUBSCR
designator ::= unpack
designator ::= unpack_list
designator ::= unpack
'''

View File

@@ -258,6 +258,7 @@ class Python2Parser(PythonParser):
PyPy adds custom rules here as well
"""
if 'PyPy' in customize:
# PyPy-specific customizations
self.addRule("""
@@ -276,6 +277,8 @@ class Python2Parser(PythonParser):
else:
continue
opname_base = opname[:opname.rfind('_')]
# The order of opname listed is roughly sorted below
if opname_base in ('BUILD_LIST', 'BUILD_TUPLE', 'BUILD_SET'):
thousands = (v//1024)
thirty32s = ((v//32) % 32)
@@ -289,23 +292,6 @@ class Python2Parser(PythonParser):
self.seen1024 = True
rule = ('build_list ::= ' + 'expr1024 '*thousands +
'expr32 '*thirty32s + 'expr '*(v % 32) + opname)
elif opname == 'LOOKUP_METHOD':
# A PyPy speciality - DRY with parse3
self.add_unique_rule("load_attr ::= expr LOOKUP_METHOD",
opname, v, customize)
continue
elif opname == 'JUMP_IF_NOT_DEBUG':
self.add_unique_rules([
'jmp_true_false ::= POP_JUMP_IF_TRUE',
'jmp_true_false ::= POP_JUMP_IF_FALSE',
"stmt ::= assert_pypy",
"stmt ::= assert2_pypy",
"assert_pypy ::= JUMP_IF_NOT_DEBUG assert_expr jmp_true_false "
"LOAD_ASSERT RAISE_VARARGS_1 COME_FROM",
"assert2_pypy ::= JUMP_IF_NOT_DEBUG assert_expr jmp_true_false "
"LOAD_ASSERT expr CALL_FUNCTION_1 RAISE_VARARGS_1 COME_FROM",
], customize)
continue
elif opname_base == 'BUILD_MAP':
if opname == 'BUILD_MAP_n':
# PyPy sometimes has no count. Sigh.
@@ -327,34 +313,43 @@ class Python2Parser(PythonParser):
"mapexpr ::= %s %s" % (opname, kvlist_n)
], customize)
continue
elif opname == 'SETUP_EXCEPT':
# FIXME: have a way here to detect PyPy. Right now we
# only have SETUP_EXCEPT customization for PyPy, but that might not
# always be the case.
self.add_unique_rules([
"stmt ::= trystmt_pypy",
"trystmt_pypy ::= SETUP_EXCEPT suite_stmts_opt try_middle_pypy",
"try_middle_pypy ::= COME_FROM except_stmts END_FINALLY COME_FROM"
], customize)
continue
elif opname == 'SETUP_FINALLY':
# FIXME: have a way here to detect PyPy. Right now we
# only have SETUP_EXCEPT customization for PyPy, but that might not
# always be the case.
self.add_unique_rules([
"stmt ::= tryfinallystmt_pypy",
"tryfinallystmt_pypy ::= SETUP_FINALLY suite_stmts_opt COME_FROM_FINALLY "
"suite_stmts_opt END_FINALLY"
], customize)
continue
elif opname_base in ('UNPACK_TUPLE', 'UNPACK_SEQUENCE'):
rule = 'unpack ::= ' + opname + ' designator'*v
elif opname_base == 'UNPACK_LIST':
rule = 'unpack_list ::= ' + opname + ' designator'*v
elif opname_base in ('CALL_FUNCTION', 'CALL_FUNCTION_VAR',
'CALL_FUNCTION_VAR_KW', 'CALL_FUNCTION_KW'):
args_pos = (v & 0xff) # positional parameters
args_kw = (v >> 8) & 0xff # keyword parameters
# number of apply equiv arguments:
nak = ( len(opname_base)-len('CALL_FUNCTION') ) // 3
rule = 'call_function ::= expr ' + 'expr '*args_pos + 'kwarg '*args_kw \
+ 'expr ' * nak + opname
elif opname_base == 'CALL_METHOD':
# PyPy only - DRY with parse3
args_pos = (v & 0xff) # positional parameters
args_kw = (v >> 8) & 0xff # keyword parameters
# number of apply equiv arguments:
nak = ( len(opname_base)-len('CALL_METHOD') ) // 3
rule = 'call_function ::= expr ' + 'expr '*args_pos + 'kwarg '*args_kw \
+ 'expr ' * nak + opname
elif opname_base in ('DUP_TOPX', 'RAISE_VARARGS'):
# FIXME: remove these conditions if they are not needed.
# no longer need to add a rule
continue
elif opname == 'JUMP_IF_NOT_DEBUG':
self.add_unique_rules([
'jmp_true_false ::= POP_JUMP_IF_TRUE',
'jmp_true_false ::= POP_JUMP_IF_FALSE',
"stmt ::= assert_pypy",
"stmt ::= assert2_pypy",
"assert_pypy ::= JUMP_IF_NOT_DEBUG assert_expr jmp_true_false "
"LOAD_ASSERT RAISE_VARARGS_1 COME_FROM",
"assert2_pypy ::= JUMP_IF_NOT_DEBUG assert_expr jmp_true_false "
"LOAD_ASSERT expr CALL_FUNCTION_1 RAISE_VARARGS_1 COME_FROM",
], customize)
continue
elif opname == 'LOOKUP_METHOD':
# A PyPy speciality - DRY with parse3
self.add_unique_rule("load_attr ::= expr LOOKUP_METHOD",
opname, v, customize)
continue
elif opname_base == 'MAKE_FUNCTION':
if i > 0 and tokens[i-1] == 'LOAD_LAMBDA':
self.addRule('mklambda ::= %s LOAD_LAMBDA %s' %
@@ -381,23 +376,32 @@ class Python2Parser(PythonParser):
' GET_ITER CALL_FUNCTION_1' %
('expr '*v, opname))],
customize)
pass
continue
elif opname_base in ('CALL_FUNCTION', 'CALL_FUNCTION_VAR',
'CALL_FUNCTION_VAR_KW', 'CALL_FUNCTION_KW'):
args_pos = (v & 0xff) # positional parameters
args_kw = (v >> 8) & 0xff # keyword parameters
# number of apply equiv arguments:
nak = ( len(opname_base)-len('CALL_FUNCTION') ) // 3
rule = 'call_function ::= expr ' + 'expr '*args_pos + 'kwarg '*args_kw \
+ 'expr ' * nak + opname
elif opname_base == 'CALL_METHOD':
# PyPy only - DRY with parse3
args_pos = (v & 0xff) # positional parameters
args_kw = (v >> 8) & 0xff # keyword parameters
# number of apply equiv arguments:
nak = ( len(opname_base)-len('CALL_METHOD') ) // 3
rule = 'call_function ::= expr ' + 'expr '*args_pos + 'kwarg '*args_kw \
+ 'expr ' * nak + opname
elif opname == 'SETUP_EXCEPT':
# FIXME: have a way here to detect PyPy. Right now we
# only have SETUP_EXCEPT customization for PyPy, but that might not
# always be the case.
self.add_unique_rules([
"stmt ::= trystmt_pypy",
"trystmt_pypy ::= SETUP_EXCEPT suite_stmts_opt try_middle_pypy",
"try_middle_pypy ::= COME_FROM except_stmts END_FINALLY COME_FROM"
], customize)
continue
elif opname == 'SETUP_FINALLY':
# FIXME: have a way here to detect PyPy. Right now we
# only have SETUP_EXCEPT customization for PyPy, but that might not
# always be the case.
self.add_unique_rules([
"stmt ::= tryfinallystmt_pypy",
"tryfinallystmt_pypy ::= SETUP_FINALLY suite_stmts_opt COME_FROM_FINALLY "
"suite_stmts_opt END_FINALLY"
], customize)
continue
elif opname_base in ('UNPACK_TUPLE', 'UNPACK_SEQUENCE'):
rule = 'unpack ::= ' + opname + ' designator'*v
elif opname_base == 'UNPACK_LIST':
rule = 'unpack_list ::= ' + opname + ' designator'*v
else:
raise Exception('unknown customize token %s' % opname)
self.add_unique_rule(rule, opname_base, v, customize)

View File

@@ -110,7 +110,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
MAP_DIRECT_FRAGMENT = ()
stacked_params = ('f', 'indent', 'isLambda', '_globals')
stacked_params = ('f', 'indent', 'is_lambda', '_globals')
def __init__(self, version, scanner, showast=False,
debug_parser=PARSER_DEFAULT_DEBUG,
@@ -143,19 +143,19 @@ class FragmentsWalker(pysource.SourceWalker, object):
None)
indent = property(lambda s: s.params['indent'],
lambda s, x: s.params.__setitem__('indent', x),
lambda s: s.params.__delitem__('indent'),
None)
lambda s, x: s.params.__setitem__('indent', x),
lambda s: s.params.__delitem__('indent'),
None)
isLambda = property(lambda s: s.params['isLambda'],
lambda s, x: s.params.__setitem__('isLambda', x),
lambda s: s.params.__delitem__('isLambda'),
None)
is_lambda = property(lambda s: s.params['is_lambda'],
lambda s, x: s.params.__setitem__('is_lambda', x),
lambda s: s.params.__delitem__('is_lambda'),
None)
_globals = property(lambda s: s.params['_globals'],
lambda s, x: s.params.__setitem__('_globals', x),
lambda s: s.params.__delitem__('_globals'),
None)
lambda s, x: s.params.__setitem__('_globals', x),
lambda s: s.params.__delitem__('_globals'),
None)
def set_pos_info(self, node, start, finish, name=None):
if name is None: name = self.name
@@ -208,7 +208,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
def n_return_stmt(self, node):
start = len(self.f.getvalue()) + len(self.indent)
if self.params['isLambda']:
if self.params['is_lambda']:
self.preorder(node[0])
if hasattr(node[-1], 'offset'):
self.set_pos_info(node[-1], start,
@@ -237,7 +237,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
def n_return_if_stmt(self, node):
start = len(self.f.getvalue()) + len(self.indent)
if self.params['isLambda']:
if self.params['is_lambda']:
node[0].parent = node
self.preorder(node[0])
else:
@@ -529,7 +529,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
self.indent_more()
start = len(self.f.getvalue())
self.make_function(node, isLambda=False, codeNode=code_node)
self.make_function(node, is_lambda=False, codeNode=code_node)
self.set_pos_info(node, start, len(self.f.getvalue()))
@@ -992,7 +992,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
n_classdefdeco2 = n_classdef
def gen_source(self, ast, name, customize, isLambda=False, returnNone=False):
def gen_source(self, ast, name, customize, is_lambda=False, returnNone=False):
"""convert AST to Python source code"""
rn = self.return_none
@@ -1004,15 +1004,15 @@ class FragmentsWalker(pysource.SourceWalker, object):
self.println(self.indent, 'pass')
else:
self.customize(customize)
self.text = self.traverse(ast, isLambda=isLambda)
self.text = self.traverse(ast, is_lambda=is_lambda)
self.name = old_name
self.return_none = rn
def build_ast(self, tokens, customize, isLambda=False, noneInNames=False):
def build_ast(self, tokens, customize, is_lambda=False, noneInNames=False):
# assert type(tokens) == ListType
# assert isinstance(tokens[0], Token)
if isLambda:
if is_lambda:
tokens.append(Token('LAMBDA_MARKER'))
try:
ast = parser.parse(self.p, tokens, customize)
@@ -1118,7 +1118,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
self.last_finish = len(self.f.getvalue())
# FIXME: duplicated from pysource, since we don't find self.params
def traverse(self, node, indent=None, isLambda=False):
def traverse(self, node, indent=None, is_lambda=False):
'''Buulds up fragment which can be used inside a larger
block of code'''
self.param_stack.append(self.params)
@@ -1129,7 +1129,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
'_globals': {},
'f': StringIO(),
'indent': indent,
'isLambda': isLambda,
'is_lambda': is_lambda,
}
self.preorder(node)
self.f.write('\n'*self.pending_newlines)

View File

@@ -48,7 +48,7 @@ def find_none(node):
# FIXME: DRY the below code...
def make_function3_annotate(self, node, isLambda, nested=1,
def make_function3_annotate(self, node, is_lambda, nested=1,
codeNode=None, annotate_last=-1):
"""
Dump function defintion, doc string, and function
@@ -111,7 +111,7 @@ def make_function3_annotate(self, node, isLambda, nested=1,
else:
lambda_index = None
if lambda_index and isLambda and iscode(node[lambda_index].attr):
if lambda_index and is_lambda and iscode(node[lambda_index].attr):
assert node[lambda_index].kind == 'LOAD_LAMBDA'
code = node[lambda_index].attr
else:
@@ -127,7 +127,7 @@ def make_function3_annotate(self, node, isLambda, nested=1,
try:
ast = self.build_ast(code._tokens,
code._customize,
isLambda = isLambda,
is_lambda = is_lambda,
noneInNames = ('None' in code.co_names))
except (ParserError, ParserError2) as p:
self.write(str(p))
@@ -138,7 +138,7 @@ def make_function3_annotate(self, node, isLambda, nested=1,
kw_pairs = args_node.attr[1]
indent = self.indent
if isLambda:
if is_lambda:
self.write("lambda ")
else:
self.write("(")
@@ -254,7 +254,7 @@ def make_function3_annotate(self, node, isLambda, nested=1,
self.write(', ')
self.write('**%s' % code.co_varnames[argc + kw_pairs])
if isLambda:
if is_lambda:
self.write(": ")
else:
self.write(')')
@@ -273,7 +273,7 @@ def make_function3_annotate(self, node, isLambda, nested=1,
self.println(":")
if (len(code.co_consts) > 0 and
code.co_consts[0] is not None and not isLambda): # ugly
code.co_consts[0] is not None and not is_lambda): # ugly
# docstring exists, dump it
print_docstring(self, self.indent, code.co_consts[0])
@@ -286,11 +286,11 @@ def make_function3_annotate(self, node, isLambda, nested=1,
self.mod_globs -= all_globals
has_none = 'None' in code.co_names
rn = has_none and not find_none(ast)
self.gen_source(ast, code.co_name, code._customize, isLambda=isLambda,
self.gen_source(ast, code.co_name, code._customize, is_lambda=is_lambda,
returnNone=rn)
code._tokens = code._customize = None # save memory
def make_function2(self, node, isLambda, nested=1, codeNode=None):
def make_function2(self, node, is_lambda, nested=1, codeNode=None):
"""
Dump function defintion, doc string, and function body.
This code is specialied for Python 2.
@@ -336,7 +336,7 @@ def make_function2(self, node, isLambda, nested=1, codeNode=None):
lambda_index = None
if lambda_index and isLambda and iscode(node[lambda_index].attr):
if lambda_index and is_lambda and iscode(node[lambda_index].attr):
assert node[lambda_index].kind == 'LOAD_LAMBDA'
code = node[lambda_index].attr
else:
@@ -355,7 +355,7 @@ def make_function2(self, node, isLambda, nested=1, codeNode=None):
try:
ast = self.build_ast(code._tokens,
code._customize,
isLambda = isLambda,
is_lambda = is_lambda,
noneInNames = ('None' in code.co_names))
except (ParserError, ParserError2) as p:
self.write(str(p))
@@ -376,7 +376,7 @@ def make_function2(self, node, isLambda, nested=1, codeNode=None):
argc += 1
# dump parameter list (with default values)
if isLambda:
if is_lambda:
self.write("lambda ", ", ".join(params))
# If the last statement is None (which is the
# same thing as "return None" in a lambda) and the
@@ -421,17 +421,17 @@ def make_function2(self, node, isLambda, nested=1, codeNode=None):
if argc + kw_pairs > 0:
self.write('**%s' % code.co_varnames[argc + kw_pairs])
if isLambda:
if is_lambda:
self.write(": ")
else:
self.println("):")
if len(code.co_consts) > 0 and code.co_consts[0] is not None and not isLambda: # ugly
if len(code.co_consts) > 0 and code.co_consts[0] is not None and not is_lambda: # ugly
# docstring exists, dump it
print_docstring(self, indent, code.co_consts[0])
code._tokens = None # save memory
if not isLambda:
if not is_lambda:
assert ast == 'stmts'
all_globals = find_all_globals(ast, set())
@@ -440,12 +440,12 @@ def make_function2(self, node, isLambda, nested=1, codeNode=None):
self.mod_globs -= all_globals
has_none = 'None' in code.co_names
rn = has_none and not find_none(ast)
self.gen_source(ast, code.co_name, code._customize, isLambda=isLambda,
self.gen_source(ast, code.co_name, code._customize, is_lambda=is_lambda,
returnNone=rn)
code._tokens = None; code._customize = None # save memory
def make_function3(self, node, isLambda, nested=1, codeNode=None):
def make_function3(self, node, is_lambda, nested=1, codeNode=None):
"""Dump function definition, doc string, and function body in
Python version 3.0 and above
"""
@@ -528,7 +528,7 @@ def make_function3(self, node, isLambda, nested=1, codeNode=None):
pass
if lambda_index and isLambda and iscode(node[lambda_index].attr):
if lambda_index and is_lambda and iscode(node[lambda_index].attr):
assert node[lambda_index].kind == 'LOAD_LAMBDA'
code = node[lambda_index].attr
else:
@@ -548,7 +548,7 @@ def make_function3(self, node, isLambda, nested=1, codeNode=None):
try:
ast = self.build_ast(code._tokens,
code._customize,
isLambda = isLambda,
is_lambda = is_lambda,
noneInNames = ('None' in code.co_names))
except (ParserError, ParserError2) as p:
self.write(str(p))
@@ -573,7 +573,7 @@ def make_function3(self, node, isLambda, nested=1, codeNode=None):
argc += 1
# dump parameter list (with default values)
if isLambda:
if is_lambda:
self.write("lambda ", ", ".join(params))
# If the last statement is None (which is the
# same thing as "return None" in a lambda) and the
@@ -635,12 +635,12 @@ def make_function3(self, node, isLambda, nested=1, codeNode=None):
self.write(', ')
self.write('**%s' % code.co_varnames[argc + kw_pairs])
if isLambda:
if is_lambda:
self.write(": ")
else:
self.println("):")
if len(code.co_consts) > 0 and code.co_consts[0] is not None and not isLambda: # ugly
if len(code.co_consts) > 0 and code.co_consts[0] is not None and not is_lambda: # ugly
# docstring exists, dump it
print_docstring(self, self.indent, code.co_consts[0])
@@ -653,6 +653,6 @@ def make_function3(self, node, isLambda, nested=1, codeNode=None):
self.mod_globs -= all_globals
has_none = 'None' in code.co_names
rn = has_none and not find_none(ast)
self.gen_source(ast, code.co_name, code._customize, isLambda=isLambda,
self.gen_source(ast, code.co_name, code._customize, is_lambda=is_lambda,
returnNone=rn)
code._tokens = None; code._customize = None # save memory

View File

@@ -161,7 +161,7 @@ class SourceWalkerError(Exception):
return self.errmsg
class SourceWalker(GenericASTTraversal, object):
stacked_params = ('f', 'indent', 'isLambda', '_globals')
stacked_params = ('f', 'indent', 'is_lambda', '_globals')
def __init__(self, version, out, scanner, showast=False,
debug_parser=PARSER_DEFAULT_DEBUG,
@@ -383,7 +383,7 @@ class SourceWalker(GenericASTTraversal, object):
self.write(code.attr.co_name)
# FIXME: handle and pass full annotate args
make_function3_annotate(self, node, isLambda=False,
make_function3_annotate(self, node, is_lambda=False,
codeNode=code, annotate_last=annotate_last)
if len(self.param_stack) > 1:
@@ -553,19 +553,19 @@ class SourceWalker(GenericASTTraversal, object):
None)
indent = property(lambda s: s.params['indent'],
lambda s, x: s.params.__setitem__('indent', x),
lambda s: s.params.__delitem__('indent'),
None)
lambda s, x: s.params.__setitem__('indent', x),
lambda s: s.params.__delitem__('indent'),
None)
isLambda = property(lambda s: s.params['isLambda'],
lambda s, x: s.params.__setitem__('isLambda', x),
lambda s: s.params.__delitem__('isLambda'),
None)
is_lambda = property(lambda s: s.params['is_lambda'],
lambda s, x: s.params.__setitem__('is_lambda', x),
lambda s: s.params.__delitem__('is_lambda'),
None)
_globals = property(lambda s: s.params['_globals'],
lambda s, x: s.params.__setitem__('_globals', x),
lambda s: s.params.__delitem__('_globals'),
None)
lambda s, x: s.params.__setitem__('_globals', x),
lambda s: s.params.__delitem__('_globals'),
None)
def set_pos_info(self, node):
if hasattr(node, 'linestart') and node.linestart:
@@ -581,7 +581,7 @@ class SourceWalker(GenericASTTraversal, object):
def indent_less(self, indent=TAB):
self.indent = self.indent[:-len(indent)]
def traverse(self, node, indent=None, isLambda=False):
def traverse(self, node, indent=None, is_lambda=False):
self.param_stack.append(self.params)
if indent is None: indent = self.indent
p = self.pending_newlines
@@ -590,7 +590,7 @@ class SourceWalker(GenericASTTraversal, object):
'_globals': {},
'f': StringIO(),
'indent': indent,
'isLambda': isLambda,
'is_lambda': is_lambda,
}
self.preorder(node)
self.f.write('\n'*self.pending_newlines)
@@ -668,7 +668,7 @@ class SourceWalker(GenericASTTraversal, object):
self.prune()
def n_return_stmt(self, node):
if self.params['isLambda']:
if self.params['is_lambda']:
self.preorder(node[0])
self.prune()
else:
@@ -683,7 +683,7 @@ class SourceWalker(GenericASTTraversal, object):
self.prune() # stop recursing
def n_return_if_stmt(self, node):
if self.params['isLambda']:
if self.params['is_lambda']:
self.write(' return ')
self.preorder(node[0])
self.prune()
@@ -1016,7 +1016,7 @@ class SourceWalker(GenericASTTraversal, object):
self.write(func_name)
self.indent_more()
self.make_function(node, isLambda=False, codeNode=code_node)
self.make_function(node, is_lambda=False, codeNode=code_node)
if len(self.param_stack) > 1:
self.write('\n\n')
@@ -1025,15 +1025,15 @@ class SourceWalker(GenericASTTraversal, object):
self.indent_less()
self.prune() # stop recursing
def make_function(self, node, isLambda, nested=1,
def make_function(self, node, is_lambda, nested=1,
codeNode=None, annotate=None):
if self.version >= 3.0:
make_function3(self, node, isLambda, nested, codeNode)
make_function3(self, node, is_lambda, nested, codeNode)
else:
make_function2(self, node, isLambda, nested, codeNode)
make_function2(self, node, is_lambda, nested, codeNode)
def n_mklambda(self, node):
self.make_function(node, isLambda=True, codeNode=node[-2])
self.make_function(node, is_lambda=True, codeNode=node[-2])
self.prune() # stop recursing
def n_list_compr(self, node):
@@ -2161,7 +2161,7 @@ class SourceWalker(GenericASTTraversal, object):
code._tokens = None; code._customize = None # save memory
self.classes.pop(-1)
def gen_source(self, ast, name, customize, isLambda=False, returnNone=False):
def gen_source(self, ast, name, customize, is_lambda=False, returnNone=False):
"""convert AST to Python source code"""
rn = self.return_none
@@ -2173,20 +2173,20 @@ class SourceWalker(GenericASTTraversal, object):
self.println(self.indent, 'pass')
else:
self.customize(customize)
if isLambda:
self.write(self.traverse(ast, isLambda=isLambda))
if is_lambda:
self.write(self.traverse(ast, is_lambda=is_lambda))
else:
self.text = self.traverse(ast, isLambda=isLambda)
self.text = self.traverse(ast, is_lambda=is_lambda)
self.println(self.text)
self.name = old_name
self.return_none = rn
def build_ast(self, tokens, customize, isLambda=False,
def build_ast(self, tokens, customize, is_lambda=False,
noneInNames=False, isTopLevel=False):
# assert isinstance(tokens[0], Token)
if isLambda:
if is_lambda:
for t in tokens:
if t.kind == 'RETURN_END_IF':
t.kind = 'RETURN_END_IF_LAMBDA'