Parser for Jinja2 and daughter languages: nunjucks, twig
Project description
tree-sitter-jinja-dialects
A tree-sitter grammar for the Jinja template language family.
Supported languages
This grammar parses the union of syntax from:
- Jinja2 (Python) - the original
- Nunjucks (JavaScript) - Mozilla's JS port, used by 11ty
- Twig (PHP) - Symfony's template engine
- Tera (Rust) - Rust port
- Inja (C++) - C++ port
- Django Templates (Python) - predecessor, subset syntax
Valid syntax from any of these languages is accepted. Both true and True
parse as booleans; both none and null parse as null literals; both
key=val and key: val work in keyword arguments.
Architecture
The grammar follows a template-first approach: it parses template
delimiters and structure, exposing text nodes for HTML injection via
queries/injections.scm.
source_file := repeat(choice(statement, output, comment, text))
Expressions
Full expression parsing with 13-level precedence, including:
- Arithmetic, comparison, logical, membership (
in/not in), identity (is/is not) - Filter chains (
x | lower | truncate(50)) - Member access (
obj.prop,obj?.prop), subscript (items[0]) - Function calls with keyword arguments and spread
- Conditional expressions (Jinja2
x if c else yand Twigc ? x : y) - Twig operators:
===,!==,??,b-and/b-or/b-xor
Statements
All standard block and inline statements:
if/elif/else/endiffor/else/endfor(with tuple unpacking, condition filter,recursive)block/endblock,macro/endmacro,call/endcallfilter/endfilter,with/endwith,autoescape/endautoescaperaw/endrawandverbatim/endverbatim(via external scanner)set(inline and block forms),extends,include,import,from,do- Catch-all
generic_tagfor custom/extension tags
Whitespace control
All delimiter pairs support - (strip) and ~ (Twig preserve-newlines):
{{- expr -}} {%- tag -%} {#- comment -#}
{{~ expr ~}} {%~ tag ~%} {#~ comment ~#}
Queries
| File | Purpose |
|---|---|
highlights.scm |
Syntax highlighting |
injections.scm |
HTML injection into text nodes |
locals.scm |
Variable definitions and references |
tags.scm |
Symbol tagging (blocks, macros) |
Usage
Neovim
-- In your tree-sitter config
require('nvim-treesitter.configs').setup {
ensure_installed = { 'jinja' },
}
Node.js
const Parser = require('tree-sitter');
const Jinja = require('tree-sitter-jinja-dialects');
const parser = new Parser();
parser.setLanguage(Jinja);
const tree = parser.parse('{{ name | lower }}');
Bindings
Pre-built bindings for C, Go, Node.js, Python, Rust, and Swift.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tree_sitter_jinja_dialects-0.1.0.tar.gz.
File metadata
- Download URL: tree_sitter_jinja_dialects-0.1.0.tar.gz
- Upload date:
- Size: 51.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a8c3deaec7a5e39f6d95979fe60e3f86159e07f7a02f8f84b27fbb92de902e2
|
|
| MD5 |
9d2b76768f0943ad3e61db216675e449
|
|
| BLAKE2b-256 |
d3cdde4cfa7623de4d070ed69e65834e4bf1f3029c5c7882f4d014db13c53a71
|
Provenance
The following attestation bundles were made for tree_sitter_jinja_dialects-0.1.0.tar.gz:
Publisher:
publish.yml on bennypowers/tree-sitter-jinja-dialects
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tree_sitter_jinja_dialects-0.1.0.tar.gz -
Subject digest:
2a8c3deaec7a5e39f6d95979fe60e3f86159e07f7a02f8f84b27fbb92de902e2 - Sigstore transparency entry: 1393585071
- Sigstore integration time:
-
Permalink:
bennypowers/tree-sitter-jinja-dialects@68b4a6ea76b04f2627207f917eb4e2f35a47c7bf -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/bennypowers
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@68b4a6ea76b04f2627207f917eb4e2f35a47c7bf -
Trigger Event:
push
-
Statement type:
File details
Details for the file tree_sitter_jinja_dialects-0.1.0-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: tree_sitter_jinja_dialects-0.1.0-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 31.1 kB
- Tags: CPython 3.10+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2f3148113a394a293793858c5704ec0f13cf7de47a4bae972d6a149ed6462e0
|
|
| MD5 |
2e9ef30d341f1c9736c15c6e7da0d911
|
|
| BLAKE2b-256 |
ea0cc361dbaa90829703c61ef2b10767a3ce8e9953e389c88e1e8352d761fb7d
|
Provenance
The following attestation bundles were made for tree_sitter_jinja_dialects-0.1.0-cp310-abi3-win_amd64.whl:
Publisher:
publish.yml on bennypowers/tree-sitter-jinja-dialects
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tree_sitter_jinja_dialects-0.1.0-cp310-abi3-win_amd64.whl -
Subject digest:
b2f3148113a394a293793858c5704ec0f13cf7de47a4bae972d6a149ed6462e0 - Sigstore transparency entry: 1393585085
- Sigstore integration time:
-
Permalink:
bennypowers/tree-sitter-jinja-dialects@68b4a6ea76b04f2627207f917eb4e2f35a47c7bf -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/bennypowers
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@68b4a6ea76b04f2627207f917eb4e2f35a47c7bf -
Trigger Event:
push
-
Statement type:
File details
Details for the file tree_sitter_jinja_dialects-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: tree_sitter_jinja_dialects-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 45.3 kB
- Tags: CPython 3.10+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98396005531bdffee6f7dd6415ab57eda60a703e6ac72732171afbce5985847e
|
|
| MD5 |
81cc368ce69779012d36e22cb77c951a
|
|
| BLAKE2b-256 |
99cdb190a2fba882e633fed7270b117034ff932d0e25d84e2ac29cf22bd6a96b
|
Provenance
The following attestation bundles were made for tree_sitter_jinja_dialects-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl:
Publisher:
publish.yml on bennypowers/tree-sitter-jinja-dialects
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tree_sitter_jinja_dialects-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl -
Subject digest:
98396005531bdffee6f7dd6415ab57eda60a703e6ac72732171afbce5985847e - Sigstore transparency entry: 1393585175
- Sigstore integration time:
-
Permalink:
bennypowers/tree-sitter-jinja-dialects@68b4a6ea76b04f2627207f917eb4e2f35a47c7bf -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/bennypowers
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@68b4a6ea76b04f2627207f917eb4e2f35a47c7bf -
Trigger Event:
push
-
Statement type:
File details
Details for the file tree_sitter_jinja_dialects-0.1.0-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: tree_sitter_jinja_dialects-0.1.0-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 45.8 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf0f961aefd9e346f5a727be9b131e38ad6519605b934aa1575dd703460c62a8
|
|
| MD5 |
67b7ef98b0bf67910f01529ba96d3fb5
|
|
| BLAKE2b-256 |
44d81f0b59f17bed332868ba34eb5340a93698073957c4db1f376b2062c60e4c
|
Provenance
The following attestation bundles were made for tree_sitter_jinja_dialects-0.1.0-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish.yml on bennypowers/tree-sitter-jinja-dialects
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tree_sitter_jinja_dialects-0.1.0-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
bf0f961aefd9e346f5a727be9b131e38ad6519605b934aa1575dd703460c62a8 - Sigstore transparency entry: 1393585149
- Sigstore integration time:
-
Permalink:
bennypowers/tree-sitter-jinja-dialects@68b4a6ea76b04f2627207f917eb4e2f35a47c7bf -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/bennypowers
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@68b4a6ea76b04f2627207f917eb4e2f35a47c7bf -
Trigger Event:
push
-
Statement type:
File details
Details for the file tree_sitter_jinja_dialects-0.1.0-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: tree_sitter_jinja_dialects-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 29.8 kB
- Tags: CPython 3.10+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9daa970fb6e283d5cd15d832e46fb92464990fa6d9c9b8a1ab84e7d0258b166e
|
|
| MD5 |
7fc6f131ea4f66870c0347ff5d704fcf
|
|
| BLAKE2b-256 |
4ae19d010550f5755974564aeabab138236230c847039f73daa85d75d94c7b70
|
Provenance
The following attestation bundles were made for tree_sitter_jinja_dialects-0.1.0-cp310-abi3-macosx_11_0_arm64.whl:
Publisher:
publish.yml on bennypowers/tree-sitter-jinja-dialects
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tree_sitter_jinja_dialects-0.1.0-cp310-abi3-macosx_11_0_arm64.whl -
Subject digest:
9daa970fb6e283d5cd15d832e46fb92464990fa6d9c9b8a1ab84e7d0258b166e - Sigstore transparency entry: 1393585115
- Sigstore integration time:
-
Permalink:
bennypowers/tree-sitter-jinja-dialects@68b4a6ea76b04f2627207f917eb4e2f35a47c7bf -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/bennypowers
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@68b4a6ea76b04f2627207f917eb4e2f35a47c7bf -
Trigger Event:
push
-
Statement type: