From: Kevin Brown Date: Fri, 8 May 2020 17:51:14 +0000 (-0400) Subject: Add support for tests X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7ac9e2d97809177732ad0faddd576f794c3fbae4;p=thirdparty%2Fjinja.git Add support for tests 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. --- diff --git a/tatsu_grammar.txt b/tatsu_grammar.txt index 6a50d4b6..a0d21e3a 100644 --- a/tatsu_grammar.txt +++ b/tatsu_grammar.txt @@ -125,7 +125,33 @@ variable_accessor_call_parameter_value_only variable_accessor_call_parameter_value = - {SP}* @:variable_identifier {SP}* + {SP}* @:( variable_tests | variable_identifier ) {SP}* + ; + +variable_tests + = + left:variable_identifier {SP}* + ( + | ( "is" {SP}* test_function:variable_accessor_call_parameter_value ) + | ( comparator:variable_tests_comparator right: variable_accessor_call_parameter_value ) + | ( logical_operator:variable_tests_logical_operator right: variable_accessor_call_parameter_value ) + ) + ; + +variable_tests_comparator + = + | "==" + | "!=" + | ">" + | ">=" + | "<" + | "<=" + ; + +variable_tests_logical_operator + = + | "and" + | "or" ; variable_accessor_dot diff --git a/test_template.jinja b/test_template.jinja index a24a0c90..ce3aad5e 100644 --- a/test_template.jinja +++ b/test_template.jinja @@ -18,4 +18,15 @@ across lines #} ('downloads.html', 'Downloads')] %}
  • {{ caption }}
  • {% endfor %} -{% trans user=user.username %}Hello, {{ user }}!{% endtrans %} \ No newline at end of file +{% trans user=user.username %}Hello, {{ user }}!{% endtrans %} +{% set navigation = [('index.html', 'Index'), ('about.html', 'About')] %} +{% set key, value = call_something() %} +{% for value in values %} + {% if loop.previtem is defined and value > loop.previtem %} + The value just increased! + {% endif %} + {{ value }} + {% if loop.nextitem is defined and loop.nextitem > value %} + The value will increase even more! + {% endif %} +{% endfor %}