From: Kevin Date: Sun, 10 May 2020 16:54:08 +0000 (-0400) Subject: Parse arguments to calls X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1e98d2b19c361722ada5cc269c53edce4c126190;p=thirdparty%2Fjinja.git Parse arguments to calls This can be combined with the logic for parsing arguments to filters then they both generate the same AST. --- diff --git a/new_parser.py b/new_parser.py index 3bfedb36..1dbd839d 100644 --- a/new_parser.py +++ b/new_parser.py @@ -256,9 +256,7 @@ def parse_variable_accessor(node, ast): accessor_node = nodes.Getattr() accessor_node.attr = ast['parameter'] elif accessor_type == 'call': - accessor_node = nodes.Call() - accessor_node.args = [] - accessor_node.kwargs = [] + accessor_node = parse_variable_accessor_call(ast) accessor_node.node = node accessor_node.ctx = "load" @@ -266,6 +264,31 @@ def parse_variable_accessor(node, ast): return accessor_node +def parse_variable_accessor_call(ast): + args = [] + kwargs = [] + dynamic_args = None + dynamic_kwargs = None + + if ast['parameters']: + for argument in ast['parameters']: + value = parse_variable(argument['value']) + + if 'key' in argument: + kwargs.append( + nodes.Keyword(argument['key'], value) + ) + else: + args.append(value) + + node = nodes.Call() + node.args = args + node.kwargs = kwargs + node.dyn_args = dynamic_args + node.dyn_kwargs = dynamic_kwargs + + return node + def parse_variable_filter(node, ast): args = [] kwargs = []