3.6+ lambda params; add semantic rule customizing for lambdas

This commit is contained in:
rocky
2019-12-23 07:19:40 -05:00
parent 50fbea1a06
commit bffbd0b352
5 changed files with 3 additions and 3 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -101,7 +101,6 @@ class PythonParser(GenericASTBuilder):
many arguments it has. Often it is not used. many arguments it has. Often it is not used.
""" """
if rule not in self.new_rules: if rule not in self.new_rules:
# print("XXX ", rule) # debug
self.new_rules.add(rule) self.new_rules.add(rule)
self.addRule(rule, nop_func) self.addRule(rule, nop_func)
customize[opname] = arg_count customize[opname] = arg_count

View File

@@ -798,7 +798,7 @@ def make_function3(self, node, is_lambda, nested=1, code_node=None):
params.reverse() params.reverse()
else: else:
params.append("*%s" % code.co_varnames[argc]) params.append("*%s" % code.co_varnames[argc])
if not is_lambda: if not is_lambda or self.version >= 3.6:
argc += 1 argc += 1
# dump parameter list (with default values) # dump parameter list (with default values)

View File

@@ -484,7 +484,7 @@ class SourceWalker(GenericASTTraversal, object):
else: else:
# We can't comment out like above because there may be a trailing ')' # We can't comment out like above because there may be a trailing ')'
# that needs to be written # that needs to be written
assert len(node) == 3 and node[2] == "LAMBDA_MARKER" assert len(node) == 3 and node[2] in ("RETURN_VALUE_LAMBDA", "LAMBDA_MARKER")
self.preorder(node[0]) self.preorder(node[0])
self.prune() self.prune()
@@ -2366,6 +2366,7 @@ class SourceWalker(GenericASTTraversal, object):
p_insts = self.p.insts p_insts = self.p.insts
self.p.insts = self.scanner.insts self.p.insts = self.scanner.insts
ast = python_parser.parse(self.p, tokens, customize) ast = python_parser.parse(self.p, tokens, customize)
self.customize(customize)
self.p.insts = p_insts self.p.insts = p_insts
except (python_parser.ParserError, AssertionError) as e: except (python_parser.ParserError, AssertionError) as e:
raise ParserError(e, tokens) raise ParserError(e, tokens)