From: Kevin Date: Sun, 10 May 2020 02:23:32 +0000 (-0400) Subject: Support filters on all variables X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=17945c23a5e140e55a89e46c040d54dc340ea64c;p=thirdparty%2Fjinja.git Support filters on all variables This adds support to filters on all variables instead of to just variables which are being printed within templates. This now allows us to pass in variables that are using filters as parameters within a block, so they can be used for setting new variables or to perform transformations on the fly. --- diff --git a/.gitignore b/.gitignore index 81752e0e..dacb502c 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ venv-*/ htmlcov .pytest_cache/ /.vscode/ +tatsu_test.json \ No newline at end of file diff --git a/grammar.ebnf b/grammar.ebnf index 667e8100..314e9341 100644 --- a/grammar.ebnf +++ b/grammar.ebnf @@ -126,7 +126,7 @@ block_parameter_value_only variable_expression = - variable_open type:`variable` name:variable_identifier { !variable_close {SP}* filters+:variable_filter }* variable_close + variable_open type:`variable` name:variable_identifier variable_close ; variable_open = @@ -141,6 +141,7 @@ variable_identifier = variable:( LITERAL | IDENTIFIER ) accessors:{ variable_accessor }* + { {SP}* filters+:variable_filter }* ; variable_accessor diff --git a/test_tatsu.py b/test_tatsu.py index d197f550..8ff2e45b 100644 --- a/test_tatsu.py +++ b/test_tatsu.py @@ -1,7 +1,8 @@ +from datetime import datetime from tatsu.util import asjson import json import tatsu -from datetime import datetime +import sys with open('grammar.ebnf', 'r') as tatsu_grammar: @@ -20,5 +21,5 @@ with open('grammar.ebnf', 'r') as tatsu_grammar: print(json.dumps(asjson(ast), indent=2)) - print("Grammar", grammar_end - grammar_start) - print("Parser", parse_end - parse_start) \ No newline at end of file + print("Grammar", grammar_end - grammar_start, file=sys.stderr) + print("Parser", parse_end - parse_start, file=sys.stderr) \ No newline at end of file diff --git a/test_template.jinja b/test_template.jinja index 6d8129ca..af50f650 100644 --- a/test_template.jinja +++ b/test_template.jinja @@ -41,4 +41,8 @@ across lines #} # for item in seq:
  • {{ item }}
  • ## this comment is ignored # endfor - \ No newline at end of file + +{% set reply | wordwrap %} + You wrote: + {{ message }} +{% endset %} \ No newline at end of file