]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Parse variable tuples
authorKevin <kevin@kevin-brown.com>
Sun, 10 May 2020 16:03:32 +0000 (12:03 -0400)
committerKevin <kevin@kevin-brown.com>
Sun, 10 May 2020 16:03:32 +0000 (12:03 -0400)
Right now these are custom parsed since they are not the same as
tuple literals and generally serve a different purpose. They are
tuples which contain variable identifiers and are generally used
for assignment.

new_parser.py

index f540a0c2d91eaad587e465a6b49cdd63432a179f..ac1d7be2a75cdde3096a32a34dfe701a2a435f18 100644 (file)
@@ -150,6 +150,9 @@ def parse_template(ast):
     return nodes.Template(parse(ast), lineno=1)\r
 \r
 def parse_variable(ast, variable_context='load'):\r
+    if 'tuple' in ast:\r
+        return parse_variable_tuple(ast, variable_context)\r
+\r
     name = ast['variable']\r
 \r
     if 'literal_type' in name:\r
@@ -216,3 +219,15 @@ def parse_variable_filter(node, ast):
         dynamic_kwargs,\r
         lineno=lineno_from_parseinfo(ast['parseinfo'])\r
     )\r
+\r
+def parse_variable_tuple(ast, variable_context):\r
+    identifiers = []\r
+\r
+    for name in ast['tuple']:\r
+        identifiers.append(nodes.Name(name, variable_context))\r
+\r
+    return nodes.Tuple(\r
+        identifiers,\r
+        variable_context,\r
+        lineno=lineno_from_parseinfo(ast['parseinfo'])\r
+    )\r