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": ["."]
}
+97 -52
View File
@@ -28,28 +28,24 @@ const django = grammar({
$.matcher_error, $.matcher_error,
], ],
reserved: { reserved: {
global: ($) => ["not", "if", "in", "is", "as"], global: ($) => ["not", "if", "in", "is", "as", "for", "from"],
}, },
rules: { rules: {
template: ($) => repeat1(choice($.template_tag, $.content)), template: ($) => repeat1(choice($.template_tag, $.content)),
content: ($) => /(?:[^\{]|\{[^\{#%}])+/, content: ($) => /(?:[^\{]|\{[^\{#%}])+/,
template_tag: ($) => choice($.template_block_groups, $.template_variable, $.template_comment), template_tag: ($) =>
filtered_value: ($) => seq( choice($.template_block_groups, $.template_variable, $.template_comment),
$.value, filtered_value: ($) =>
optional( seq($.value, optional(seq(token.immediate("|"), $.filter_expression))),
seq( filter_expression: ($) =>
token.immediate("|"), seq($.filter, repeat(seq(token.immediate("|"), $.filter))),
$.filter_expression
),
),
),
filter_expression: ($) => seq($.filter, repeat(seq(token.immediate("|"), $.filter))),
value: ($) => choice($.literal, $.variable_attribute), value: ($) => choice($.literal, $.variable_attribute),
literal: ($) => choice($.number, $.string), literal: ($) => choice($.number, $.string),
number: ($) => /-?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[eE]-?[0-9]+)?/, number: ($) => /-?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[eE]-?[0-9]+)?/,
string: ($) => /"(?:[^"\\]|\\\\|\\")*"|'(?:[^'\\]|\\\\|\\')*'/, string: ($) => /"(?:[^"\\]|\\\\|\\")*"|'(?:[^'\\]|\\\\|\\')*'/,
attribute: ($) => /[a-zA-Z0-9_]+(?:\.[a-zA-Z0-9_]+)*/, 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_]*/, identifier: ($) => /[a-zA-Z][a-zA-Z0-9_]*/,
binaryOperator: ($) => binaryOperator: ($) =>
choice( choice(
@@ -64,13 +60,13 @@ const django = grammar({
"in", "in",
prec(1, seq("not", "in")), prec(1, seq("not", "in")),
"is", "is",
prec(1, seq("is", "not")) prec(1, seq("is", "not")),
), ),
predicate: ($) => predicate: ($) =>
seq( seq(
optional("not"), optional("not"),
$.filtered_value, $.filtered_value,
repeat(seq($.binaryOperator, optional("not"), $.filtered_value)) repeat(seq($.binaryOperator, optional("not"), $.filtered_value)),
), ),
template_variable: ($) => seq("{{", $.filtered_value, "}}"), template_variable: ($) => seq("{{", $.filtered_value, "}}"),
template_comment: ($) => seq("{#", /(?:[^#]|#[^}])*/, "#}"), template_comment: ($) => seq("{#", /(?:[^#]|#[^}])*/, "#}"),
@@ -89,6 +85,7 @@ const django = grammar({
$.if_group, $.if_group,
$.ifchanged_group, $.ifchanged_group,
$.include, $.include,
$.load,
$.lorem, $.lorem,
$.now, $.now,
$.partial, $.partial,
@@ -100,9 +97,11 @@ const django = grammar({
$.template_tag_block, $.template_tag_block,
$.url_block, $.url_block,
$.verbatim_group, $.verbatim_group,
$.with_group $.width_ratio,
$.with_group,
), ),
filter: ($) => choice( filter: ($) =>
choice(
seq("add:", $.value), seq("add:", $.value),
"addslashes", "addslashes",
"capfirst", "capfirst",
@@ -162,44 +161,63 @@ const django = grammar({
choice(seq("yesno:", $.value), "yesno"), choice(seq("yesno:", $.value), "yesno"),
), ),
autoescape_group: ($) => autoescape_group: ($) =>
seq(block("autoescape", choice("on", "off")), optional($.template), block("endautoescape")), seq(
block("autoescape", choice("on", "off")),
optional($.template),
block("endautoescape"),
),
block_group: ($) => block_group: ($) =>
seq( seq(
block("block", field("name", $.push_block)), block("block", field("name", $.push_block)),
optional($.template), optional($.template),
block("endblock", $.pop_block) block("endblock", $.pop_block),
), ),
comment_group: ($) => comment_group: ($) =>
seq( seq(
block("comment", optional($.string)), block("comment", optional($.string)),
optional($.comment_content), optional($.comment_content),
prec(1, block("endcomment")) block("endcomment"),
), ),
csrf_token: ($) => block("csrf_token"), csrf_token: ($) => block("csrf_token"),
cycle: ($) => cycle: ($) =>
block( block(
"cycle", "cycle",
repeat1($.filtered_value), repeat1($.filtered_value),
optional(seq("as", field("name", $.identifier))), optional(seq("as", field("variable", $.identifier))),
optional("silent") optional("silent"),
), ),
debug: ($) => block("debug"), debug: ($) => block("debug"),
extends: ($) => block("extends", $.filtered_value), extends: ($) => block("extends", $.filtered_value),
filter_group: ($) => filter_group: ($) =>
seq(block("filter", $.filter_expression), optional($.template), block("endfilter")), seq(
firstof: ($) => block("firstof", repeat1($.filtered_value), optional(seq("as", $.identifier))), block("filter", $.filter_expression),
for_group: ($) => optional($.template),
block("endfilter"),
),
firstof: ($) =>
block(
"firstof",
repeat1($.filtered_value),
optional(seq("as", $.identifier)),
),
for_scope: ($) =>
prec.left(
seq( seq(
block( block(
"for", "for",
field("variables", $.identifier), field("variable", $.identifier),
repeat(seq(",", field("variables", $.identifier))), repeat(seq(",", field("variable", $.identifier))),
"in", "in",
$.filtered_value $.filtered_value,
), ),
optional($.template), optional($.template),
),
),
for_group: ($) =>
seq(
$.for_scope,
optional(seq(block("empty"), optional($.template))), optional(seq(block("empty"), optional($.template))),
block("endfor") block("endfor"),
), ),
if_group: ($) => if_group: ($) =>
seq( seq(
@@ -207,44 +225,61 @@ const django = grammar({
optional($.template), optional($.template),
repeat(seq(block("elif", $.predicate), optional($.template))), repeat(seq(block("elif", $.predicate), optional($.template))),
optional(seq(block("else"), optional($.template))), optional(seq(block("else"), optional($.template))),
block("endif") block("endif"),
), ),
ifchanged_group: ($) => ifchanged_group: ($) =>
seq( seq(
block("ifchanged", repeat($.filtered_value)), block("ifchanged", repeat($.filtered_value)),
optional($.template), optional($.template),
block("endifchanged") block("endifchanged"),
), ),
include: ($) => block("include", $.filtered_value), include: ($) => block("include", $.filtered_value),
library: ($) =>
prec(
-1,
seq($.identifier, optional(seq(token.immediate("."), $.identifier))),
),
load: ($) => load: ($) =>
block( block(
"load", "load",
choice( choice(
repeat1($.variable_attribute), seq(repeat1($.identifier), "from", $.library),
seq(repeat1($.identifier), "from", $.variable_attribute) repeat1($.library),
)
), ),
lorem: ($) => block("lorem", $.filtered_value, choice("w", "p", "b"), optional("random")), ),
now: ($) => block("now", $.string, optional(seq("as", field("variable", $.identifier)))), lorem: ($) =>
partial: ($) => block("partial", field("name", $.identifier)), 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: ($) => partialdef_group: ($) =>
seq( seq(
block("partialdef", field("name", $.push_partial), optional("inline")), block("partialdef", $.push_partial, optional("inline")),
optional($.template), optional($.template),
block("endpartialdef", $.pop_partial) block("endpartialdef", $.pop_partial),
), ),
query_string: ($) => query_string: ($) =>
block("querystring", repeat($.identifier), repeat(seq($.identifier, "=", $.filtered_value))), block(
"querystring",
repeat($.identifier),
repeat(seq($.identifier, "=", $.filtered_value)),
),
regroup: ($) => regroup: ($) =>
block( block(
"regroup", "regroup",
$.filtered_value, $.filtered_value,
"by", "by",
$.attribute, $.attribute,
optional(seq("as", field("variable", $.identifier))) optional(seq("as", field("variable", $.identifier))),
), ),
reset_cycle: ($) => block("resetcycle", optional($.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: ($) => template_tag_block: ($) =>
block( block(
"templatetag", "templatetag",
@@ -256,33 +291,43 @@ const django = grammar({
"openbrace", "openbrace",
"closebrace", "closebrace",
"opencomment", "opencomment",
"closecomment" "closecomment",
)
), ),
url_block: $ => block( ),
url_block: ($) =>
block(
"url", "url",
choice($.string, $.identifier), choice($.string, $.identifier),
optional( optional(
choice( choice(
repeat1($.filtered_value), repeat1($.filtered_value),
repeat1(seq($.identifier, '=', $.filtered_value)), repeat1(seq($.identifier, "=", $.filtered_value)),
), ),
), ),
optional( optional(seq("as", field("variable", $.identifier))),
seq("as", field("variable", $.identifier)),
),
), ),
verbatim_group: ($) => verbatim_group: ($) =>
seq( seq(
block("verbatim", field("name", $.push_verbatim)), block("verbatim", $.push_verbatim),
optional($.verbatim_content), optional($.verbatim_content),
block("endverbatim", $.pop_verbatim), block("endverbatim", $.pop_verbatim),
), ),
width_ratio: ($) =>
block(
"widthratio",
$.filtered_value,
$.filtered_value,
$.filtered_value,
optional(seq("as", field("variable", $.identifier))),
),
with_group: ($) => with_group: ($) =>
seq( seq(
block("with", field("variables", repeat1(seq(field("name", $.identifier), "=", $.filtered_value)))), block(
"with",
repeat1(seq(field("variable", $.identifier), "=", $.filtered_value)),
),
optional($.template), optional($.template),
block("endwith") block("endwith"),
), ),
}, },
}); });
+2
View File
@@ -12,6 +12,8 @@
"parser-test": "tree-sitter test", "parser-test": "tree-sitter test",
"parser-generate": "tree-sitter generate", "parser-generate": "tree-sitter generate",
"parser-build": "tree-sitter build --wasm", "parser-build": "tree-sitter build --wasm",
"highlight": "tree-sitter highlight",
"tag": "tree-sitter tag",
"playground": "tree-sitter playground" "playground": "tree-sitter playground"
}, },
"dependencies": { "dependencies": {
+145 -14
View File
@@ -1,29 +1,160 @@
; Identifiers
(cycle name: (identifier) @variable
name: (identifier) @variable)
variable: (identifier) @variable.parameter
(block_group (block_group
name: (push_block) @block_name) (push_block) @type)
(partialdef_group (partialdef_group
name: (push_partial) @partial_name) (push_partial) @type)
(verbatim_group (verbatim_group
name: (push_verbatim) @verbatim_name) (push_verbatim) @type)
(with_group (comment_content) @comment
variables: (_ (template_comment) @comment
name: (identifier) @variable)) (attribute) @attribute
; Literals [
(binaryOperator)
("is")
("not")
("as")
("in")
("=")
("|")
(".")] @operator
[
("{{")
("{#")
("{%")
("}}")
("#}")
("%}")
(",")] @punctuation
(number) @number (number) @number
(string) @string (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
+138 -34
View File
@@ -392,6 +392,10 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "include" "name": "include"
}, },
{
"type": "SYMBOL",
"name": "load"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "lorem" "name": "lorem"
@@ -436,6 +440,10 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "verbatim_group" "name": "verbatim_group"
}, },
{
"type": "SYMBOL",
"name": "width_ratio"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "with_group" "name": "with_group"
@@ -1218,9 +1226,6 @@
] ]
}, },
{ {
"type": "PREC",
"value": 1,
"content": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
@@ -1241,7 +1246,6 @@
} }
] ]
} }
}
] ]
}, },
"csrf_token": { "csrf_token": {
@@ -1299,7 +1303,7 @@
}, },
{ {
"type": "FIELD", "type": "FIELD",
"name": "name", "name": "variable",
"content": { "content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "identifier" "name": "identifier"
@@ -1488,7 +1492,10 @@
} }
] ]
}, },
"for_group": { "for_scope": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
@@ -1508,7 +1515,7 @@
}, },
{ {
"type": "FIELD", "type": "FIELD",
"name": "variables", "name": "variable",
"content": { "content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "identifier" "name": "identifier"
@@ -1525,7 +1532,7 @@
}, },
{ {
"type": "FIELD", "type": "FIELD",
"name": "variables", "name": "variable",
"content": { "content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "identifier" "name": "identifier"
@@ -1559,6 +1566,16 @@
"type": "BLANK" "type": "BLANK"
} }
] ]
}
]
}
},
"for_group": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "for_scope"
}, },
{ {
"type": "CHOICE", "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": { "load": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
@@ -1892,13 +1946,6 @@
{ {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "variable_attribute"
}
},
{ {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
@@ -1915,9 +1962,16 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "variable_attribute" "name": "library"
} }
] ]
},
{
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "library"
}
} }
] ]
}, },
@@ -2012,7 +2066,7 @@
}, },
{ {
"type": "FIELD", "type": "FIELD",
"name": "variable", "name": "name",
"content": { "content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "identifier" "name": "identifier"
@@ -2047,12 +2101,8 @@
} }
}, },
{ {
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "identifier" "name": "identifier"
}
}, },
{ {
"type": "STRING", "type": "STRING",
@@ -2079,12 +2129,8 @@
} }
}, },
{ {
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "push_partial" "name": "push_partial"
}
}, },
{ {
"type": "CHOICE", "type": "CHOICE",
@@ -2517,12 +2563,8 @@
} }
}, },
{ {
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "push_verbatim" "name": "push_verbatim"
}
}, },
{ {
"type": "STRING", "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": { "with_group": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
@@ -2588,16 +2688,13 @@
} }
}, },
{ {
"type": "FIELD",
"name": "variables",
"content": {
"type": "REPEAT1", "type": "REPEAT1",
"content": { "content": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
"type": "FIELD", "type": "FIELD",
"name": "name", "name": "variable",
"content": { "content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "identifier" "name": "identifier"
@@ -2613,7 +2710,6 @@
} }
] ]
} }
}
}, },
{ {
"type": "STRING", "type": "STRING",
@@ -2733,6 +2829,14 @@
{ {
"type": "STRING", "type": "STRING",
"value": "as" "value": "as"
},
{
"type": "STRING",
"value": "for"
},
{
"type": "STRING",
"value": "from"
} }
] ]
} }
+173 -72
View File
@@ -55,6 +55,10 @@
"type": "include", "type": "include",
"named": true "named": true
}, },
{
"type": "load",
"named": true
},
{ {
"type": "lorem", "type": "lorem",
"named": true "named": true
@@ -99,6 +103,10 @@
"type": "verbatim_group", "type": "verbatim_group",
"named": true "named": true
}, },
{
"type": "width_ratio",
"named": true
},
{ {
"type": "with_group", "type": "with_group",
"named": true "named": true
@@ -256,16 +264,6 @@
"type": "cycle", "type": "cycle",
"named": true, "named": true,
"fields": { "fields": {
"name": {
"multiple": false,
"required": false,
"types": [
{
"type": "identifier",
"named": true
}
]
},
"tag": { "tag": {
"multiple": false, "multiple": false,
"required": true, "required": true,
@@ -275,6 +273,16 @@
"named": false "named": false
} }
] ]
},
"variable": {
"multiple": false,
"required": false,
"types": [
{
"type": "identifier",
"named": true
}
]
} }
}, },
"children": { "children": {
@@ -458,14 +466,40 @@
{ {
"type": "endfor", "type": "endfor",
"named": false "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", "type": "for",
"named": false "named": false
} }
] ]
}, },
"variables": { "variable": {
"multiple": true, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
@@ -593,6 +627,21 @@
] ]
} }
}, },
{
"type": "library",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
}
},
{ {
"type": "literal", "type": "literal",
"named": true, "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", "type": "lorem",
"named": true, "named": true,
@@ -642,6 +721,16 @@
"type": "now", "type": "now",
"named": true, "named": true,
"fields": { "fields": {
"name": {
"multiple": false,
"required": false,
"types": [
{
"type": "identifier",
"named": true
}
]
},
"tag": { "tag": {
"multiple": false, "multiple": false,
"required": true, "required": true,
@@ -651,16 +740,6 @@
"named": false "named": false
} }
] ]
},
"variable": {
"multiple": false,
"required": false,
"types": [
{
"type": "identifier",
"named": true
}
]
} }
}, },
"children": { "children": {
@@ -678,16 +757,6 @@
"type": "partial", "type": "partial",
"named": true, "named": true,
"fields": { "fields": {
"name": {
"multiple": false,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
},
"tag": { "tag": {
"multiple": false, "multiple": false,
"required": true, "required": true,
@@ -698,22 +767,22 @@
} }
] ]
} }
},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
} }
}, },
{ {
"type": "partialdef_group", "type": "partialdef_group",
"named": true, "named": true,
"fields": { "fields": {
"name": {
"multiple": false,
"required": true,
"types": [
{
"type": "push_partial",
"named": true
}
]
},
"tag": { "tag": {
"multiple": true, "multiple": true,
"required": true, "required": true,
@@ -737,6 +806,10 @@
"type": "pop_partial", "type": "pop_partial",
"named": true "named": true
}, },
{
"type": "push_partial",
"named": true
},
{ {
"type": "template", "type": "template",
"named": true "named": true
@@ -1031,16 +1104,6 @@
"type": "verbatim_group", "type": "verbatim_group",
"named": true, "named": true,
"fields": { "fields": {
"name": {
"multiple": false,
"required": true,
"types": [
{
"type": "push_verbatim",
"named": true
}
]
},
"tag": { "tag": {
"multiple": true, "multiple": true,
"required": true, "required": true,
@@ -1064,6 +1127,10 @@
"type": "pop_verbatim", "type": "pop_verbatim",
"named": true "named": true
}, },
{
"type": "push_verbatim",
"named": true
},
{ {
"type": "verbatim_content", "type": "verbatim_content",
"named": true "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", "type": "with_group",
"named": true, "named": true,
"fields": { "fields": {
"name": {
"multiple": true,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
},
"tag": { "tag": {
"multiple": true, "multiple": true,
"required": true, "required": true,
@@ -1099,18 +1192,10 @@
} }
] ]
}, },
"variables": { "variable": {
"multiple": true, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
{
"type": "=",
"named": false
},
{
"type": "filtered_value",
"named": true
},
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
@@ -1119,9 +1204,13 @@
} }
}, },
"children": { "children": {
"multiple": false, "multiple": true,
"required": false, "required": true,
"types": [ "types": [
{
"type": "filtered_value",
"named": true
},
{ {
"type": "template", "type": "template",
"named": true "named": true
@@ -1389,6 +1478,10 @@
"type": "force_escape", "type": "force_escape",
"named": false "named": false
}, },
{
"type": "from",
"named": false
},
{ {
"type": "get_digit:", "type": "get_digit:",
"named": false "named": false
@@ -1465,6 +1558,10 @@
"type": "ljust:", "type": "ljust:",
"named": false "named": false
}, },
{
"type": "load",
"named": false
},
{ {
"type": "lorem", "type": "lorem",
"named": false "named": false
@@ -1713,6 +1810,10 @@
"type": "w", "type": "w",
"named": false "named": false
}, },
{
"type": "widthratio",
"named": false
},
{ {
"type": "with", "type": "with",
"named": false "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 (value
(literal (literal
(string)))) (string))))
name: (identifier)) variable: (identifier))
(content)) (content))
================== ==================
@@ -69,7 +69,7 @@ Cycle With As And Silent
(value (value
(literal (literal
(string)))) (string))))
name: (identifier)) variable: (identifier))
(content)) (content))
================== ==================
+10 -7
View File
@@ -13,7 +13,8 @@ For Basic
(template (template
(content) (content)
(for_group (for_group
variables: (identifier) (for_scope
variable: (identifier)
(filtered_value (filtered_value
(value (value
(variable_attribute (variable_attribute
@@ -25,7 +26,7 @@ For Basic
(value (value
(variable_attribute (variable_attribute
(identifier))))) (identifier)))))
(content))) (content))))
(content)) (content))
================== ==================
@@ -43,8 +44,9 @@ For With Multiple Variables
(template (template
(content) (content)
(for_group (for_group
variables: (identifier) (for_scope
variables: (identifier) variable: (identifier)
variable: (identifier)
(filtered_value (filtered_value
(value (value
(variable_attribute (variable_attribute
@@ -56,7 +58,7 @@ For With Multiple Variables
(value (value
(variable_attribute (variable_attribute
(identifier))))) (identifier)))))
(content))) (content))))
(content)) (content))
================== ==================
@@ -76,7 +78,8 @@ For With Empty
(template (template
(content) (content)
(for_group (for_group
variables: (identifier) (for_scope
variable: (identifier)
(filtered_value (filtered_value
(value (value
(variable_attribute (variable_attribute
@@ -88,7 +91,7 @@ For With Empty
(value (value
(variable_attribute (variable_attribute
(identifier))))) (identifier)))))
(content)) (content)))
(template (template
(content))) (content)))
(content)) (content))
+1 -1
View File
@@ -9,5 +9,5 @@ Partial Basic
(template (template
(content) (content)
(partial (partial
name: (identifier)) (identifier))
(content)) (content))
+2 -2
View File
@@ -13,7 +13,7 @@ Partialdef Basic
(template (template
(content) (content)
(partialdef_group (partialdef_group
name: (push_partial) (push_partial)
(template (template
(content)) (content))
(pop_partial)) (pop_partial))
@@ -34,7 +34,7 @@ Partialdef Inline
(template (template
(content) (content)
(partialdef_group (partialdef_group
name: (push_partial) (push_partial)
(template (template
(content)) (content))
(pop_partial)) (pop_partial))
+5 -5
View File
@@ -9,7 +9,7 @@ Verbatim Basic
(template (template
(content) (content)
(verbatim_group (verbatim_group
name: (push_verbatim) (push_verbatim)
(verbatim_content) (verbatim_content)
(pop_verbatim)) (pop_verbatim))
(content)) (content))
@@ -25,7 +25,7 @@ Verbatim Empty
(template (template
(content) (content)
(verbatim_group (verbatim_group
name: (push_verbatim) (push_verbatim)
(pop_verbatim)) (pop_verbatim))
(content)) (content))
@@ -43,7 +43,7 @@ Verbatim Ignores Tags
(template (template
(content) (content)
(verbatim_group (verbatim_group
name: (push_verbatim) (push_verbatim)
(verbatim_content) (verbatim_content)
(pop_verbatim)) (pop_verbatim))
(content)) (content))
@@ -59,7 +59,7 @@ Verbatim With Name
(template (template
(content) (content)
(verbatim_group (verbatim_group
name: (push_verbatim) (push_verbatim)
(verbatim_content) (verbatim_content)
(pop_verbatim)) (pop_verbatim))
(content)) (content))
@@ -77,7 +77,7 @@ Avoid template rendering via the {% verbatim %}{% endverbatim %} block.
(template (template
(content) (content)
(verbatim_group (verbatim_group
name: (push_verbatim) (push_verbatim)
(verbatim_content) (verbatim_content)
(pop_verbatim)) (pop_verbatim))
(content)) (content))
+6 -6
View File
@@ -11,8 +11,8 @@ With Basic
(template (template
(content) (content)
(with_group (with_group
name: (identifier) variable: (identifier)
variables: (filtered_value (filtered_value
(value (value
(variable_attribute (variable_attribute
(identifier) (identifier)
@@ -40,13 +40,13 @@ With Multiple Variables
(template (template
(content) (content)
(with_group (with_group
name: (identifier) variable: (identifier)
variables: (filtered_value (filtered_value
(value (value
(literal (literal
(number)))) (number))))
name: (identifier) variable: (identifier)
variables: (filtered_value (filtered_value
(value (value
(literal (literal
(number)))) (number))))
+11 -6
View File
@@ -1,9 +1,13 @@
{% load greet from custom.tags %}
{% partialdef url %}
<li>{% greet %} {{ user }}</li>
{% endpartialdef %}
<body> <body>
{# hello this is an example file #} {# hello this is an example file #}
<header> <header>
<h1>{{ page.title|title }}</h1> <h1>{{ page.title|title }}</h1>
<nav> <nav>
{% if page.links|length > 0 %} {% if page.links|length > 0 %}
<ul> <ul>
{% for label, link in page.links %} {% for label, link in page.links %}
<li> <li>
@@ -12,16 +16,17 @@
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
{% endif %} {% endif %}
</nav> </nav>
</header> </header>
{% block content %} {% block content %}
<h1>EMPTY</h1>
{% endblock %} {% endblock %}
<footer> <footer>
{% for foot in page.footer %} {% for user in page.footer %}
{% partial url %}
{% endfor %} {% endfor %}
</footer> </footer>
</body> </body>
+9 -3
View File
@@ -8,7 +8,10 @@
"scope": "source.django", "scope": "source.django",
"file-types": ["html", "txt", "md"], "file-types": ["html", "txt", "md"],
"injection-regex": "^django$", "injection-regex": "^django$",
"class-name": "TreeSitterDjango" "class-name": "TreeSitterDjango",
"highlights": "queries/highlights.scm",
"locals": "queries/locals.scm",
"injections": "queries/injections.scm"
} }
], ],
"bindings": { "bindings": {
@@ -17,10 +20,13 @@
"metadata": { "metadata": {
"version": "0.0.1", "version": "0.0.1",
"description": "DJango grammar for tree-sitter", "description": "DJango grammar for tree-sitter",
"authors": [{ "license": "MIT",
"authors": [
{
"name": "Daniel Hanson", "name": "Daniel Hanson",
"url": "https://github.com/danhanson" "url": "https://github.com/danhanson"
}], }
],
"links": { "links": {
"repository": "https://github.com/danhanson/tree-sitter-django" "repository": "https://github.com/danhanson/tree-sitter-django"
} }