]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Added tuple literal support
authorKevin Brown <kevin@kevin-brown.com>
Fri, 8 May 2020 12:49:24 +0000 (08:49 -0400)
committerKevin <kevin@kevin-brown.com>
Sun, 10 May 2020 01:50:06 +0000 (21:50 -0400)
This maintains the expectation that tuple literals will always end
with a comma if there is a single item.

The example is the combined one from the Jinja docs but it does not
include the comma for the tuple assignment since the grammar does
not currently support that.

tatsu_grammar.txt
test_template.jinja

index bad94a8d230bb78733a5c4cc51963e443c735112..45f8ecab21415b60a9e4bf929fb648f74e1dbb61 100644 (file)
@@ -150,7 +150,7 @@ content                 = !(block_open | variable_open | comment_open) CHAR ;
 \r
 LITERAL\r
     =\r
-    STRING_LITERAL | NUMBER_LITERAL | BOOLEAN_LITERAL | LIST_LITERAL\r
+    STRING_LITERAL | NUMBER_LITERAL | BOOLEAN_LITERAL | LIST_LITERAL | TUPLE_LITERAL\r
     ;\r
 \r
 LIST_LITERAL\r
@@ -159,6 +159,12 @@ LIST_LITERAL
     | "[" {SP}* "]"\r
     ;\r
 \r
+TUPLE_LITERAL\r
+    =\r
+    "(" {SP}* tuple+:LITERAL {SP}* { "," {SP}* tuple+:LITERAL {SP}* } ")"\r
+    | "(" {SP}* tuple+:LITERAL {SP}* "," {SP}* ")"\r
+    ;\r
+\r
 INTEGER_LITERAL\r
     =\r
     /[\d_]*\d+/\r
index d5f3f4834feb6ce636ed3e56203d12ed5d825a65..8cde1b6ed5a9b398dd5c82570b20a55d57bec467 100644 (file)
@@ -14,5 +14,8 @@ across lines #}
 {% if False %}\r
 {{ '{{' }}\r
 {% endif %}\r
-{% for item in ['1', 2, 3.14] %}{{ item }}{% endfor %}\r
+{% for href caption in [('index.html', 'Index'), ('about.html', 'About'),\r
+                         ('downloads.html', 'Downloads')] %}\r
+    <li><a href="{{ href }}">{{ caption }}</a></li>\r
+{% endfor %}\r
 {% trans user=user.username %}Hello, {{ user }}!{% endtrans %}
\ No newline at end of file