]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Add support for tests
authorKevin Brown <kevin@kevin-brown.com>
Fri, 8 May 2020 17:51:14 +0000 (13:51 -0400)
committerKevin <kevin@kevin-brown.com>
Sun, 10 May 2020 01:50:06 +0000 (21:50 -0400)
Right now these are very basic and don't appear to form the correct
parse tree for logical comparisons which use tests as well. But it
parses at lease somewaht correctly, so there is something to work
with here.

tatsu_grammar.txt
test_template.jinja

index 6a50d4b65d433184989d0dc6bebffa58ce769cc7..a0d21e3a28f6dc0217b276b6d00571516ec380ee 100644 (file)
@@ -125,7 +125,33 @@ variable_accessor_call_parameter_value_only
 \r
 variable_accessor_call_parameter_value\r
     =\r
-    {SP}* @:variable_identifier {SP}*\r
+    {SP}* @:( variable_tests | variable_identifier ) {SP}*\r
+    ;\r
+\r
+variable_tests\r
+    =\r
+    left:variable_identifier {SP}*\r
+    (\r
+        | ( "is" {SP}* test_function:variable_accessor_call_parameter_value )\r
+        | ( comparator:variable_tests_comparator right: variable_accessor_call_parameter_value )\r
+        | ( logical_operator:variable_tests_logical_operator right: variable_accessor_call_parameter_value )\r
+    )\r
+    ;\r
+\r
+variable_tests_comparator\r
+    =\r
+    | "=="\r
+    | "!="\r
+    | ">"\r
+    | ">="\r
+    | "<"\r
+    | "<="\r
+    ;\r
+\r
+variable_tests_logical_operator\r
+    =\r
+    | "and"\r
+    | "or"\r
     ;\r
 \r
 variable_accessor_dot\r
index a24a0c907a608ffba0eaae34344163a8eeaae054..ce3aad5e5cb411fb131fd99d2b60846aea63fed9 100644 (file)
@@ -18,4 +18,15 @@ across lines #}
                          ('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
+{% trans user=user.username %}Hello, {{ user }}!{% endtrans %}\r
+{% set navigation = [('index.html', 'Index'), ('about.html', 'About')] %}\r
+{% set key, value = call_something() %}\r
+{% for value in values %}\r
+    {% if loop.previtem is defined and value > loop.previtem %}\r
+        The value just increased!\r
+    {% endif %}\r
+    {{ value }}\r
+    {% if loop.nextitem is defined and loop.nextitem > value %}\r
+        The value will increase even more!\r
+    {% endif %}\r
+{% endfor %}\r