add with statement support

This commit is contained in:
davidodenwald 2023-03-11 18:27:01 +01:00
parent 7415f62e8b
commit 288384e105
4 changed files with 12 additions and 2 deletions

View file

@ -56,7 +56,9 @@ export type Keyword =
| "from" | "from"
| "extends" | "extends"
| "block" | "block"
| "endblock"; | "endblock"
| "with"
| "endwith";
export const nonClosingStatements = [ export const nonClosingStatements = [
"else", "else",

View file

@ -12,7 +12,7 @@ import {
const NOT_FOUND = -1; const NOT_FOUND = -1;
const regex = const regex =
/(?<pre>(?<newline>\n)?(\s*?))(?<node>{{\s*(?<expression>'([^']|\\')*'|"([^"]|\\")*"|[\S\s]*?)\s*}}|{%(?<startDelimiter>[-+]?)\s*(?<statement>(?<keyword>for|endfor|if|else|elif|endif|macro|endmacro|call|endcall|filter|endfilter|set|endset|include|import|from|extends|block|endblock)('([^']|\\')*'|"([^"]|\\")*"|[\S\s])*?)\s*(?<endDelimiter>[-+]?)%}|(?<comment>{#[\S\s]*?#})|(?<scriptBlock><(script)((?!<)[\s\S])*>((?!<\/script)[\s\S])*?{{[\s\S]*?<\/(script)>)|(?<styleBlock><(style)((?!<)[\s\S])*>((?!<\/style)[\s\S])*?{{[\s\S]*?<\/(style)>)|(?<ignoreBlock><!-- prettier-ignore-start -->[\s\S]*<!-- prettier-ignore-end -->))/; /(?<pre>(?<newline>\n)?(\s*?))(?<node>{{\s*(?<expression>'([^']|\\')*'|"([^"]|\\")*"|[\S\s]*?)\s*}}|{%(?<startDelimiter>[-+]?)\s*(?<statement>(?<keyword>for|endfor|if|else|elif|endif|macro|endmacro|call|endcall|filter|endfilter|set|endset|include|import|from|extends|block|endblock|with|endwith)('([^']|\\')*'|"([^"]|\\")*"|[\S\s])*?)\s*(?<endDelimiter>[-+]?)%}|(?<comment>{#[\S\s]*?#})|(?<scriptBlock><(script)((?!<)[\s\S])*>((?!<\/script)[\s\S])*?{{[\s\S]*?<\/(script)>)|(?<styleBlock><(style)((?!<)[\s\S])*>((?!<\/style)[\s\S])*?{{[\s\S]*?<\/(style)>)|(?<ignoreBlock><!-- prettier-ignore-start -->[\s\S]*<!-- prettier-ignore-end -->))/;
export const parse: Parser<Node>["parse"] = (text) => { export const parse: Parser<Node>["parse"] = (text) => {
const statementStack: Statement[] = []; const statementStack: Statement[] = [];

View file

@ -0,0 +1,4 @@
{{ obj.method("argument")|default("", True) }}
{% with text='text', version=1 %}
{% include 'directory/template.jinja2' %}
{% endwith %}

View file

@ -0,0 +1,4 @@
{{ obj.method("argument")|default("", True) }}
{% with text='text', version=1 %}
{% include 'directory/template.jinja2' %}
{% endwith %}