add tests and queries

This commit is contained in:
2026-08-16 20:14:20 -04:00
parent 9c43c52a0a
commit d087c70b46
18 changed files with 10742 additions and 11061 deletions
+3
View File
@@ -0,0 +1,3 @@
{
"parser-directories": ["."]
}
+165 -120
View File
@@ -28,28 +28,24 @@ const django = grammar({
$.matcher_error,
],
reserved: {
global: ($) => ["not", "if", "in", "is", "as"],
global: ($) => ["not", "if", "in", "is", "as", "for", "from"],
},
rules: {
template: ($) => repeat1(choice($.template_tag, $.content)),
content: ($) => /(?:[^\{]|\{[^\{#%}])+/,
template_tag: ($) => choice($.template_block_groups, $.template_variable, $.template_comment),
filtered_value: ($) => seq(
$.value,
optional(
seq(
token.immediate("|"),
$.filter_expression
),
),
),
filter_expression: ($) => seq($.filter, repeat(seq(token.immediate("|"), $.filter))),
template_tag: ($) =>
choice($.template_block_groups, $.template_variable, $.template_comment),
filtered_value: ($) =>
seq($.value, optional(seq(token.immediate("|"), $.filter_expression))),
filter_expression: ($) =>
seq($.filter, repeat(seq(token.immediate("|"), $.filter))),
value: ($) => choice($.literal, $.variable_attribute),
literal: ($) => choice($.number, $.string),
number: ($) => /-?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[eE]-?[0-9]+)?/,
string: ($) => /"(?:[^"\\]|\\\\|\\")*"|'(?:[^'\\]|\\\\|\\')*'/,
attribute: ($) => /[a-zA-Z0-9_]+(?:\.[a-zA-Z0-9_]+)*/,
variable_attribute: ($) => seq($.identifier, optional(seq(token.immediate('.'), $.attribute))),
variable_attribute: ($) =>
seq($.identifier, optional(seq(token.immediate("."), $.attribute))),
identifier: ($) => /[a-zA-Z][a-zA-Z0-9_]*/,
binaryOperator: ($) =>
choice(
@@ -64,13 +60,13 @@ const django = grammar({
"in",
prec(1, seq("not", "in")),
"is",
prec(1, seq("is", "not"))
prec(1, seq("is", "not")),
),
predicate: ($) =>
seq(
optional("not"),
$.filtered_value,
repeat(seq($.binaryOperator, optional("not"), $.filtered_value))
repeat(seq($.binaryOperator, optional("not"), $.filtered_value)),
),
template_variable: ($) => seq("{{", $.filtered_value, "}}"),
template_comment: ($) => seq("{#", /(?:[^#]|#[^}])*/, "#}"),
@@ -89,6 +85,7 @@ const django = grammar({
$.if_group,
$.ifchanged_group,
$.include,
$.load,
$.lorem,
$.now,
$.partial,
@@ -100,106 +97,127 @@ const django = grammar({
$.template_tag_block,
$.url_block,
$.verbatim_group,
$.with_group
$.width_ratio,
$.with_group,
),
filter: ($) =>
choice(
seq("add:", $.value),
"addslashes",
"capfirst",
seq("center:", $.value),
seq("cut:", $.value),
choice(seq("date:", $.value), "date"),
seq("default:", $.value),
seq("default_if_none:", $.value),
seq("dictsort:", $.value),
seq("dictsortreversed:", $.value),
seq("divisibleby:", $.value),
"escape",
"escapejs",
"filesizeformat",
"first",
choice(seq("floatformat:", $.value), "floatformat"),
"force_escape",
seq("get_digit:", $.value),
"iriencode",
seq("join:", $.value),
choice(seq("json_script:", $.value), "json_script"),
"last",
"length",
seq("length_is:", $.value),
"linebreaks",
"linebreaksbr",
"linenumbers",
seq("ljust:", $.value),
"lower",
"make_list",
"phone2numeric",
choice(seq("pluralize:", $.value), "pluralize"),
"pprint",
"random",
seq("rjust:", $.value),
"safe",
"safeseq",
seq("slice:", $.value),
"slugify",
seq("stringformat:", $.value),
"striptags",
choice(seq("time:", $.value), "time"),
choice(seq("timesince:", $.value), "timesince"),
choice(seq("timeuntil:", $.value), "timeuntil"),
"title",
seq("truncatechars:", $.value),
seq("truncatechars_html:", $.value),
seq("truncatewords:", $.value),
seq("truncatewords_html:", $.value),
"unordered_list",
"upper",
choice(seq("urlencode:", $.value), "urlencode"),
"urlize",
seq("urlizetrunc:", $.value),
"wordcount",
seq("wordwrap:", $.value),
choice(seq("yesno:", $.value), "yesno"),
),
filter: ($) => choice(
seq("add:", $.value),
"addslashes",
"capfirst",
seq("center:", $.value),
seq("cut:", $.value),
choice(seq("date:", $.value), "date"),
seq("default:", $.value),
seq("default_if_none:", $.value),
seq("dictsort:", $.value),
seq("dictsortreversed:", $.value),
seq("divisibleby:", $.value),
"escape",
"escapejs",
"filesizeformat",
"first",
choice(seq("floatformat:", $.value), "floatformat"),
"force_escape",
seq("get_digit:", $.value),
"iriencode",
seq("join:", $.value),
choice(seq("json_script:", $.value), "json_script"),
"last",
"length",
seq("length_is:", $.value),
"linebreaks",
"linebreaksbr",
"linenumbers",
seq("ljust:", $.value),
"lower",
"make_list",
"phone2numeric",
choice(seq("pluralize:", $.value), "pluralize"),
"pprint",
"random",
seq("rjust:", $.value),
"safe",
"safeseq",
seq("slice:", $.value),
"slugify",
seq("stringformat:", $.value),
"striptags",
choice(seq("time:", $.value), "time"),
choice(seq("timesince:", $.value), "timesince"),
choice(seq("timeuntil:", $.value), "timeuntil"),
"title",
seq("truncatechars:", $.value),
seq("truncatechars_html:", $.value),
seq("truncatewords:", $.value),
seq("truncatewords_html:", $.value),
"unordered_list",
"upper",
choice(seq("urlencode:", $.value), "urlencode"),
"urlize",
seq("urlizetrunc:", $.value),
"wordcount",
seq("wordwrap:", $.value),
choice(seq("yesno:", $.value), "yesno"),
),
autoescape_group: ($) =>
seq(block("autoescape", choice("on", "off")), optional($.template), block("endautoescape")),
seq(
block("autoescape", choice("on", "off")),
optional($.template),
block("endautoescape"),
),
block_group: ($) =>
seq(
block("block", field("name", $.push_block)),
optional($.template),
block("endblock", $.pop_block)
block("endblock", $.pop_block),
),
comment_group: ($) =>
seq(
block("comment", optional($.string)),
optional($.comment_content),
prec(1, block("endcomment"))
block("endcomment"),
),
csrf_token: ($) => block("csrf_token"),
cycle: ($) =>
block(
"cycle",
repeat1($.filtered_value),
optional(seq("as", field("name", $.identifier))),
optional("silent")
optional(seq("as", field("variable", $.identifier))),
optional("silent"),
),
debug: ($) => block("debug"),
extends: ($) => block("extends", $.filtered_value),
filter_group: ($) =>
seq(block("filter", $.filter_expression), optional($.template), block("endfilter")),
firstof: ($) => block("firstof", repeat1($.filtered_value), optional(seq("as", $.identifier))),
seq(
block("filter", $.filter_expression),
optional($.template),
block("endfilter"),
),
firstof: ($) =>
block(
"firstof",
repeat1($.filtered_value),
optional(seq("as", $.identifier)),
),
for_scope: ($) =>
prec.left(
seq(
block(
"for",
field("variable", $.identifier),
repeat(seq(",", field("variable", $.identifier))),
"in",
$.filtered_value,
),
optional($.template),
),
),
for_group: ($) =>
seq(
block(
"for",
field("variables", $.identifier),
repeat(seq(",", field("variables", $.identifier))),
"in",
$.filtered_value
),
optional($.template),
$.for_scope,
optional(seq(block("empty"), optional($.template))),
block("endfor")
block("endfor"),
),
if_group: ($) =>
seq(
@@ -207,44 +225,61 @@ const django = grammar({
optional($.template),
repeat(seq(block("elif", $.predicate), optional($.template))),
optional(seq(block("else"), optional($.template))),
block("endif")
block("endif"),
),
ifchanged_group: ($) =>
seq(
block("ifchanged", repeat($.filtered_value)),
optional($.template),
block("endifchanged")
block("endifchanged"),
),
include: ($) => block("include", $.filtered_value),
library: ($) =>
prec(
-1,
seq($.identifier, optional(seq(token.immediate("."), $.identifier))),
),
load: ($) =>
block(
"load",
choice(
repeat1($.variable_attribute),
seq(repeat1($.identifier), "from", $.variable_attribute)
)
seq(repeat1($.identifier), "from", $.library),
repeat1($.library),
),
),
lorem: ($) => block("lorem", $.filtered_value, choice("w", "p", "b"), optional("random")),
now: ($) => block("now", $.string, optional(seq("as", field("variable", $.identifier)))),
partial: ($) => block("partial", field("name", $.identifier)),
lorem: ($) =>
block(
"lorem",
$.filtered_value,
choice("w", "p", "b"),
optional("random"),
),
now: ($) =>
block("now", $.string, optional(seq("as", field("name", $.identifier)))),
partial: ($) => block("partial", $.identifier),
partialdef_group: ($) =>
seq(
block("partialdef", field("name", $.push_partial), optional("inline")),
block("partialdef", $.push_partial, optional("inline")),
optional($.template),
block("endpartialdef", $.pop_partial)
block("endpartialdef", $.pop_partial),
),
query_string: ($) =>
block("querystring", repeat($.identifier), repeat(seq($.identifier, "=", $.filtered_value))),
block(
"querystring",
repeat($.identifier),
repeat(seq($.identifier, "=", $.filtered_value)),
),
regroup: ($) =>
block(
"regroup",
$.filtered_value,
"by",
$.attribute,
optional(seq("as", field("variable", $.identifier)))
optional(seq("as", field("variable", $.identifier))),
),
reset_cycle: ($) => block("resetcycle", optional($.identifier)),
spaceless_group: ($) => seq(block("spaceless"), optional($.template), block("endspaceless")),
spaceless_group: ($) =>
seq(block("spaceless"), optional($.template), block("endspaceless")),
template_tag_block: ($) =>
block(
"templatetag",
@@ -256,33 +291,43 @@ const django = grammar({
"openbrace",
"closebrace",
"opencomment",
"closecomment"
)
),
url_block: $ => block(
"url",
choice($.string, $.identifier),
optional(
choice(
repeat1($.filtered_value),
repeat1(seq($.identifier, '=', $.filtered_value)),
"closecomment",
),
),
optional(
seq("as", field("variable", $.identifier)),
url_block: ($) =>
block(
"url",
choice($.string, $.identifier),
optional(
choice(
repeat1($.filtered_value),
repeat1(seq($.identifier, "=", $.filtered_value)),
),
),
optional(seq("as", field("variable", $.identifier))),
),
),
verbatim_group: ($) =>
seq(
block("verbatim", field("name", $.push_verbatim)),
block("verbatim", $.push_verbatim),
optional($.verbatim_content),
block("endverbatim", $.pop_verbatim),
),
width_ratio: ($) =>
block(
"widthratio",
$.filtered_value,
$.filtered_value,
$.filtered_value,
optional(seq("as", field("variable", $.identifier))),
),
with_group: ($) =>
seq(
block("with", field("variables", repeat1(seq(field("name", $.identifier), "=", $.filtered_value)))),
block(
"with",
repeat1(seq(field("variable", $.identifier), "=", $.filtered_value)),
),
optional($.template),
block("endwith")
block("endwith"),
),
},
});
+2
View File
@@ -12,6 +12,8 @@
"parser-test": "tree-sitter test",
"parser-generate": "tree-sitter generate",
"parser-build": "tree-sitter build --wasm",
"highlight": "tree-sitter highlight",
"tag": "tree-sitter tag",
"playground": "tree-sitter playground"
},
"dependencies": {
+145 -14
View File
@@ -1,29 +1,160 @@
; Identifiers
(cycle name:
name: (identifier) @variable)
(identifier) @variable
variable: (identifier) @variable.parameter
(block_group
name: (push_block) @block_name)
(push_block) @type)
(partialdef_group
name: (push_partial) @partial_name)
(push_partial) @type)
(verbatim_group
name: (push_verbatim) @verbatim_name)
(push_verbatim) @type)
(with_group
variables: (_
name: (identifier) @variable))
(comment_content) @comment
(template_comment) @comment
(attribute) @attribute
; Literals
[
(binaryOperator)
("is")
("not")
("as")
("in")
("=")
("|")
(".")] @operator
[
("{{")
("{#")
("{%")
("}}")
("#}")
("%}")
(",")] @punctuation
(number) @number
(string) @string
; Constants
(library
(identifier) @module)
(template_block_groups
tag: (_) @tag)
tag: [
("autoescape")
("endautoescape")
("block")
("endblock")
("comment")
("endcomment")
("csrf_token")
("cycle")
("debug")
("extends")
("filter")
("endfilter")
("firstof")
("for")
("empty")
("endfor")
("for")
("empty")
("endfor")
("if")
("elif")
("else")
("endif")
("ifchanged")
("endifchanged")
("include")
("lorem")
("load")
("now")
("partial")
("partialdef")
("endpartialdef")
("querystring")
("regroup")
("resetcycle")
("spaceless")
("endspaceless")
("templatetag")
("url")
("verbatim")
("endverbatim")
("with")
("endwith")] @function
(filter . (_) @filter)
(filter .
[
("add:")
("addslashes")
("capfirst")
("center:")
("cut:")
("date")
("date:")
("default:")
("default_if_none:")
("dictsort:")
("dictsortreversed:")
("divisibleby:")
("escape")
("escapejs")
("filesizeformat")
("first")
("floatformat")
("floatformat:")
("force_escape")
("get_digit:")
("iriencode")
("join:")
("json_script")
("json_script:")
("last")
("length")
("length_is:")
("linebreaks")
("linebreaksbr")
("linenumbers")
("ljust:")
("lower")
("make_list")
("phone2numeric")
("pluralize")
("pluralize:")
("pprint")
("random")
("rjust:")
("safe")
("safeseq")
("slice:")
("slugify")
("stringformat:")
("striptags")
("time")
("time:")
("timesince")
("timesince:")
("timeuntil")
("timeuntil:")
("title")
("truncatechars:")
("truncatechars_html:")
("truncatewords:")
("truncatewords_html:")
("unordered_list")
("upper")
("urlencode")
("urlencode:")
("urlize")
("urlizetrunc:")
("wordcount")
("wordwrap:")
("yesno")
("yesno:")] @function)
(load
(identifier) @function)
+1
View File
@@ -0,0 +1 @@
[(content) (verbatim_content)] @injection.content @injection.combined
+7
View File
@@ -0,0 +1,7 @@
(identifier) @local.reference
variable: (identifier) @local.definition
(with_group) @local.scope
(for_scope) @local.scope
+15
View File
@@ -0,0 +1,15 @@
(load
(identifier) @name) @definition.function
(partialdef_group (push_partial) @name) @definition.method
(partial (identifier) @name) @reference.call
(template_block_groups
[
(_
tag: _ @name) @reference.call
(for_group
(for_scope
tag: "for" @reference.call))])
(filter) @reference.call
+242 -138
View File
@@ -392,6 +392,10 @@
"type": "SYMBOL",
"name": "include"
},
{
"type": "SYMBOL",
"name": "load"
},
{
"type": "SYMBOL",
"name": "lorem"
@@ -436,6 +440,10 @@
"type": "SYMBOL",
"name": "verbatim_group"
},
{
"type": "SYMBOL",
"name": "width_ratio"
},
{
"type": "SYMBOL",
"name": "with_group"
@@ -1218,29 +1226,25 @@
]
},
{
"type": "PREC",
"value": 1,
"content": {
"type": "SEQ",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "{%"
},
{
"type": "FIELD",
"name": "tag",
"content": {
"type": "STRING",
"value": "{%"
},
{
"type": "FIELD",
"name": "tag",
"content": {
"type": "STRING",
"value": "endcomment"
}
},
{
"type": "STRING",
"value": "%}"
"value": "endcomment"
}
]
}
},
{
"type": "STRING",
"value": "%}"
}
]
}
]
},
@@ -1299,7 +1303,7 @@
},
{
"type": "FIELD",
"name": "name",
"name": "variable",
"content": {
"type": "SYMBOL",
"name": "identifier"
@@ -1488,77 +1492,90 @@
}
]
},
"for_scope": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "{%"
},
{
"type": "FIELD",
"name": "tag",
"content": {
"type": "STRING",
"value": "for"
}
},
{
"type": "FIELD",
"name": "variable",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "FIELD",
"name": "variable",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
}
]
}
},
{
"type": "STRING",
"value": "in"
},
{
"type": "SYMBOL",
"name": "filtered_value"
},
{
"type": "STRING",
"value": "%}"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "template"
},
{
"type": "BLANK"
}
]
}
]
}
},
"for_group": {
"type": "SEQ",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "{%"
},
{
"type": "FIELD",
"name": "tag",
"content": {
"type": "STRING",
"value": "for"
}
},
{
"type": "FIELD",
"name": "variables",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "FIELD",
"name": "variables",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
}
]
}
},
{
"type": "STRING",
"value": "in"
},
{
"type": "SYMBOL",
"name": "filtered_value"
},
{
"type": "STRING",
"value": "%}"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "template"
},
{
"type": "BLANK"
}
]
"type": "SYMBOL",
"name": "for_scope"
},
{
"type": "CHOICE",
@@ -1874,6 +1891,43 @@
}
]
},
"library": {
"type": "PREC",
"value": -1,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "STRING",
"value": "."
}
},
{
"type": "SYMBOL",
"name": "identifier"
}
]
},
{
"type": "BLANK"
}
]
}
]
}
},
"load": {
"type": "SEQ",
"members": [
@@ -1892,13 +1946,6 @@
{
"type": "CHOICE",
"members": [
{
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "variable_attribute"
}
},
{
"type": "SEQ",
"members": [
@@ -1915,9 +1962,16 @@
},
{
"type": "SYMBOL",
"name": "variable_attribute"
"name": "library"
}
]
},
{
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "library"
}
}
]
},
@@ -2012,7 +2066,7 @@
},
{
"type": "FIELD",
"name": "variable",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "identifier"
@@ -2047,12 +2101,8 @@
}
},
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "STRING",
@@ -2079,12 +2129,8 @@
}
},
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "push_partial"
}
"type": "SYMBOL",
"name": "push_partial"
},
{
"type": "CHOICE",
@@ -2517,12 +2563,8 @@
}
},
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "push_verbatim"
}
"type": "SYMBOL",
"name": "push_verbatim"
},
{
"type": "STRING",
@@ -2569,6 +2611,64 @@
}
]
},
"width_ratio": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "{%"
},
{
"type": "FIELD",
"name": "tag",
"content": {
"type": "STRING",
"value": "widthratio"
}
},
{
"type": "SYMBOL",
"name": "filtered_value"
},
{
"type": "SYMBOL",
"name": "filtered_value"
},
{
"type": "SYMBOL",
"name": "filtered_value"
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "as"
},
{
"type": "FIELD",
"name": "variable",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "%}"
}
]
},
"with_group": {
"type": "SEQ",
"members": [
@@ -2588,31 +2688,27 @@
}
},
{
"type": "FIELD",
"name": "variables",
"type": "REPEAT1",
"content": {
"type": "REPEAT1",
"content": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "STRING",
"value": "="
},
{
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "variable",
"content": {
"type": "SYMBOL",
"name": "filtered_value"
"name": "identifier"
}
]
}
},
{
"type": "STRING",
"value": "="
},
{
"type": "SYMBOL",
"name": "filtered_value"
}
]
}
},
{
@@ -2733,6 +2829,14 @@
{
"type": "STRING",
"value": "as"
},
{
"type": "STRING",
"value": "for"
},
{
"type": "STRING",
"value": "from"
}
]
}
+174 -73
View File
@@ -55,6 +55,10 @@
"type": "include",
"named": true
},
{
"type": "load",
"named": true
},
{
"type": "lorem",
"named": true
@@ -99,6 +103,10 @@
"type": "verbatim_group",
"named": true
},
{
"type": "width_ratio",
"named": true
},
{
"type": "with_group",
"named": true
@@ -256,16 +264,6 @@
"type": "cycle",
"named": true,
"fields": {
"name": {
"multiple": false,
"required": false,
"types": [
{
"type": "identifier",
"named": true
}
]
},
"tag": {
"multiple": false,
"required": true,
@@ -275,6 +273,16 @@
"named": false
}
]
},
"variable": {
"multiple": false,
"required": false,
"types": [
{
"type": "identifier",
"named": true
}
]
}
},
"children": {
@@ -458,14 +466,40 @@
{
"type": "endfor",
"named": false
},
}
]
}
},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "for_scope",
"named": true
},
{
"type": "template",
"named": true
}
]
}
},
{
"type": "for_scope",
"named": true,
"fields": {
"tag": {
"multiple": false,
"required": true,
"types": [
{
"type": "for",
"named": false
}
]
},
"variables": {
"variable": {
"multiple": true,
"required": true,
"types": [
@@ -593,6 +627,21 @@
]
}
},
{
"type": "library",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
}
},
{
"type": "literal",
"named": true,
@@ -612,6 +661,36 @@
]
}
},
{
"type": "load",
"named": true,
"fields": {
"tag": {
"multiple": false,
"required": true,
"types": [
{
"type": "load",
"named": false
}
]
}
},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "identifier",
"named": true
},
{
"type": "library",
"named": true
}
]
}
},
{
"type": "lorem",
"named": true,
@@ -642,6 +721,16 @@
"type": "now",
"named": true,
"fields": {
"name": {
"multiple": false,
"required": false,
"types": [
{
"type": "identifier",
"named": true
}
]
},
"tag": {
"multiple": false,
"required": true,
@@ -651,16 +740,6 @@
"named": false
}
]
},
"variable": {
"multiple": false,
"required": false,
"types": [
{
"type": "identifier",
"named": true
}
]
}
},
"children": {
@@ -678,16 +757,6 @@
"type": "partial",
"named": true,
"fields": {
"name": {
"multiple": false,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
},
"tag": {
"multiple": false,
"required": true,
@@ -698,22 +767,22 @@
}
]
}
},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
}
},
{
"type": "partialdef_group",
"named": true,
"fields": {
"name": {
"multiple": false,
"required": true,
"types": [
{
"type": "push_partial",
"named": true
}
]
},
"tag": {
"multiple": true,
"required": true,
@@ -737,6 +806,10 @@
"type": "pop_partial",
"named": true
},
{
"type": "push_partial",
"named": true
},
{
"type": "template",
"named": true
@@ -1031,16 +1104,6 @@
"type": "verbatim_group",
"named": true,
"fields": {
"name": {
"multiple": false,
"required": true,
"types": [
{
"type": "push_verbatim",
"named": true
}
]
},
"tag": {
"multiple": true,
"required": true,
@@ -1064,6 +1127,10 @@
"type": "pop_verbatim",
"named": true
},
{
"type": "push_verbatim",
"named": true
},
{
"type": "verbatim_content",
"named": true
@@ -1071,20 +1138,46 @@
]
}
},
{
"type": "width_ratio",
"named": true,
"fields": {
"tag": {
"multiple": false,
"required": true,
"types": [
{
"type": "widthratio",
"named": false
}
]
},
"variable": {
"multiple": false,
"required": false,
"types": [
{
"type": "identifier",
"named": true
}
]
}
},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "filtered_value",
"named": true
}
]
}
},
{
"type": "with_group",
"named": true,
"fields": {
"name": {
"multiple": true,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
},
"tag": {
"multiple": true,
"required": true,
@@ -1099,18 +1192,10 @@
}
]
},
"variables": {
"variable": {
"multiple": true,
"required": true,
"types": [
{
"type": "=",
"named": false
},
{
"type": "filtered_value",
"named": true
},
{
"type": "identifier",
"named": true
@@ -1119,9 +1204,13 @@
}
},
"children": {
"multiple": false,
"required": false,
"multiple": true,
"required": true,
"types": [
{
"type": "filtered_value",
"named": true
},
{
"type": "template",
"named": true
@@ -1389,6 +1478,10 @@
"type": "force_escape",
"named": false
},
{
"type": "from",
"named": false
},
{
"type": "get_digit:",
"named": false
@@ -1465,6 +1558,10 @@
"type": "ljust:",
"named": false
},
{
"type": "load",
"named": false
},
{
"type": "lorem",
"named": false
@@ -1713,6 +1810,10 @@
"type": "w",
"named": false
},
{
"type": "widthratio",
"named": false
},
{
"type": "with",
"named": false
+9904 -10646
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -44,7 +44,7 @@ Cycle With As
(value
(literal
(string))))
name: (identifier))
variable: (identifier))
(content))
==================
@@ -69,7 +69,7 @@ Cycle With As And Silent
(value
(literal
(string))))
name: (identifier))
variable: (identifier))
(content))
==================
+43 -40
View File
@@ -13,19 +13,20 @@ For Basic
(template
(content)
(for_group
variables: (identifier)
(filtered_value
(value
(variable_attribute
(identifier))))
(template
(content)
(template_variable
(filtered_value
(value
(variable_attribute
(identifier)))))
(content)))
(for_scope
variable: (identifier)
(filtered_value
(value
(variable_attribute
(identifier))))
(template
(content)
(template_variable
(filtered_value
(value
(variable_attribute
(identifier)))))
(content))))
(content))
==================
@@ -43,20 +44,21 @@ For With Multiple Variables
(template
(content)
(for_group
variables: (identifier)
variables: (identifier)
(filtered_value
(value
(variable_attribute
(identifier))))
(template
(content)
(template_variable
(filtered_value
(value
(variable_attribute
(identifier)))))
(content)))
(for_scope
variable: (identifier)
variable: (identifier)
(filtered_value
(value
(variable_attribute
(identifier))))
(template
(content)
(template_variable
(filtered_value
(value
(variable_attribute
(identifier)))))
(content))))
(content))
==================
@@ -76,19 +78,20 @@ For With Empty
(template
(content)
(for_group
variables: (identifier)
(filtered_value
(value
(variable_attribute
(identifier))))
(template
(content)
(template_variable
(filtered_value
(value
(variable_attribute
(identifier)))))
(content))
(for_scope
variable: (identifier)
(filtered_value
(value
(variable_attribute
(identifier))))
(template
(content)
(template_variable
(filtered_value
(value
(variable_attribute
(identifier)))))
(content)))
(template
(content)))
(content))
+1 -1
View File
@@ -9,5 +9,5 @@ Partial Basic
(template
(content)
(partial
name: (identifier))
(identifier))
(content))
+2 -2
View File
@@ -13,7 +13,7 @@ Partialdef Basic
(template
(content)
(partialdef_group
name: (push_partial)
(push_partial)
(template
(content))
(pop_partial))
@@ -34,7 +34,7 @@ Partialdef Inline
(template
(content)
(partialdef_group
name: (push_partial)
(push_partial)
(template
(content))
(pop_partial))
+5 -5
View File
@@ -9,7 +9,7 @@ Verbatim Basic
(template
(content)
(verbatim_group
name: (push_verbatim)
(push_verbatim)
(verbatim_content)
(pop_verbatim))
(content))
@@ -25,7 +25,7 @@ Verbatim Empty
(template
(content)
(verbatim_group
name: (push_verbatim)
(push_verbatim)
(pop_verbatim))
(content))
@@ -43,7 +43,7 @@ Verbatim Ignores Tags
(template
(content)
(verbatim_group
name: (push_verbatim)
(push_verbatim)
(verbatim_content)
(pop_verbatim))
(content))
@@ -59,7 +59,7 @@ Verbatim With Name
(template
(content)
(verbatim_group
name: (push_verbatim)
(push_verbatim)
(verbatim_content)
(pop_verbatim))
(content))
@@ -77,7 +77,7 @@ Avoid template rendering via the {% verbatim %}{% endverbatim %} block.
(template
(content)
(verbatim_group
name: (push_verbatim)
(push_verbatim)
(verbatim_content)
(pop_verbatim))
(content))
+6 -6
View File
@@ -11,8 +11,8 @@ With Basic
(template
(content)
(with_group
name: (identifier)
variables: (filtered_value
variable: (identifier)
(filtered_value
(value
(variable_attribute
(identifier)
@@ -40,13 +40,13 @@ With Multiple Variables
(template
(content)
(with_group
name: (identifier)
variables: (filtered_value
variable: (identifier)
(filtered_value
(value
(literal
(number))))
name: (identifier)
variables: (filtered_value
variable: (identifier)
(filtered_value
(value
(literal
(number))))
+14 -9
View File
@@ -1,27 +1,32 @@
{% load greet from custom.tags %}
{% partialdef url %}
<li>{% greet %} {{ user }}</li>
{% endpartialdef %}
<body>
{# hello this is an example file #}
<header>
<h1>{{ page.title|title }}</h1>
<nav>
{% if page.links|length > 0 %}
{% if page.links|length > 0 %}
<ul>
{% for label, link in page.links %}
{% for label, link in page.links %}
<li>
{% url 'nav-pages' link as href %}
{% url 'nav-pages' link as href %}
<a href="{{href}}">{{label}}</a>
</li>
{% endfor %}
{% endfor %}
</ul>
{% endif %}
{% endif %}
</nav>
</header>
{% block content %}
{% endblock %}
{% block content %}
<h1>EMPTY</h1>
{% endblock %}
<footer>
{% for foot in page.footer %}
{% for user in page.footer %}
{% partial url %}
{% endfor %}
</footer>
</body>
+11 -5
View File
@@ -8,7 +8,10 @@
"scope": "source.django",
"file-types": ["html", "txt", "md"],
"injection-regex": "^django$",
"class-name": "TreeSitterDjango"
"class-name": "TreeSitterDjango",
"highlights": "queries/highlights.scm",
"locals": "queries/locals.scm",
"injections": "queries/injections.scm"
}
],
"bindings": {
@@ -17,10 +20,13 @@
"metadata": {
"version": "0.0.1",
"description": "DJango grammar for tree-sitter",
"authors": [{
"name": "Daniel Hanson",
"url": "https://github.com/danhanson"
}],
"license": "MIT",
"authors": [
{
"name": "Daniel Hanson",
"url": "https://github.com/danhanson"
}
],
"links": {
"repository": "https://github.com/danhanson/tree-sitter-django"
}