Fix conflict between custom and reserved statement names

This commit is contained in:
William Vandervalk 2023-10-30 17:19:07 -04:00
parent 717e83aefd
commit 8873e3df89
No known key found for this signature in database
6 changed files with 20986 additions and 14217 deletions

View file

@ -1,7 +1,7 @@
[package]
name = "tree-sitter-htmldjango"
description = "htmldjango grammar for the tree-sitter parsing library"
version = "0.0.1"
version = "0.1.1"
keywords = ["incremental", "parsing", "htmldjango"]
categories = ["parsing", "text-editors"]
repository = "https://github.com/interdependence/tree-sitter-htmldjango"

View file

@ -73,13 +73,13 @@ module.exports = grammar({
];
return choice(...tag_names.map((tag_name) => seq(
"{%", $._ws, alias(tag_name, $.tag_name), $._ws, repeat($._attribute), "%}",
"{%", $._ws, alias(tag_name + " ", $.tag_name), optional($._ws), repeat($._attribute), "%}",
repeat($._node),
"{%", $._ws, "end", alias(tag_name, $.tag_name), $._ws, repeat($._attribute), alias("%}", $.end_paired_statement))));
"{%", $._ws, "end", alias(tag_name + " ", $.tag_name), optional($._ws), repeat($._attribute), alias("%}", $.end_paired_statement))));
},
if_statement: $ => seq(
"{%", $._ws, alias("if", $.tag_name), $._ws, repeat($._attribute), "%}",
"{%", $._ws, alias("if ", $.tag_name), optional($._ws), repeat($._attribute), "%}",
repeat($._node),
repeat(prec.left(seq(
alias($.elif_statement, $.branch_statement),
@ -89,26 +89,26 @@ module.exports = grammar({
alias($.else_statement, $.branch_statement),
repeat($._node),
)),
"{%", $._ws, "end", alias("if", $.tag_name), $._ws, alias("%}", $.end_paired_statement)
"{%", $._ws, "end", alias("if ", $.tag_name), optional($._ws), alias("%}", $.end_paired_statement)
),
elif_statement: $ => seq("{%", $._ws, alias("elif", $.tag_name), $._ws, repeat($._attribute), "%}"),
else_statement: $ => seq("{%", $._ws, alias("else", $.tag_name), $._ws, "%}"),
elif_statement: $ => seq("{%", $._ws, alias("elif ", $.tag_name), optional($._ws), repeat($._attribute), "%}"),
else_statement: $ => seq("{%", $._ws, alias("else ", $.tag_name), optional($._ws), "%}"),
for_statement: $ => seq(
"{%", $._ws, alias("for", $.tag_name), $._ws, repeat($._attribute), "%}",
"{%", $._ws, alias("for ", $.tag_name), optional($._ws), repeat($._attribute), "%}",
repeat($._node),
optional(seq(
alias($.empty_statement, $.branch_statement),
repeat($._node),
)),
"{%", $._ws, "end", alias("for", $.tag_name), $._ws, alias("%}", $.end_paired_statement)
"{%", $._ws, "end", alias("for ", $.tag_name), optional($._ws), alias("%}", $.end_paired_statement)
),
empty_statement: $ => seq("{%", $._ws, alias("empty", $.tag_name), $._ws, repeat($._attribute), "%}"),
empty_statement: $ => seq("{%", $._ws, alias("empty ", $.tag_name), optional($._ws), repeat($._attribute), "%}"),
filter_statement: $ => seq(
"{%", $._ws, alias("filter", $.tag_name), $._ws, $.filter, repeat(seq("|", $.filter)), $._ws, "%}",
"{%", $._ws, alias("filter ", $.tag_name), optional($._ws), $.filter, repeat(seq("|", $.filter)), $._ws, "%}",
repeat($._node),
"{%", $._ws, "end", alias("filter", $.tag_name), $._ws, alias("%}", $.end_paired_statement)
"{%", $._ws, "end", alias("filter ", $.tag_name), optional($._ws), alias("%}", $.end_paired_statement)
),
unpaired_statement: $ => seq("{%", $._ws, alias($._word, $.tag_name), $._ws, repeat($._attribute), "%}"),

View file

@ -1,6 +1,6 @@
{
"name": "tree-sitter-htmldjango",
"version": "0.1.0",
"version": "0.1.1",
"description": "A tree-sitter grammar for the Django template language",
"main": "bindings/node",
"scripts": {
@ -25,4 +25,4 @@
"devDependencies": {
"tree-sitter-cli": "^0.20.4"
}
}
}

View file

@ -527,14 +527,22 @@
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "autoescape"
"value": "autoescape "
},
"named": true,
"value": "tag_name"
},
{
"type": "SYMBOL",
"name": "_ws"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_ws"
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
@ -570,14 +578,22 @@
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "autoescape"
"value": "autoescape "
},
"named": true,
"value": "tag_name"
},
{
"type": "SYMBOL",
"name": "_ws"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_ws"
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
@ -612,14 +628,22 @@
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "block"
"value": "block "
},
"named": true,
"value": "tag_name"
},
{
"type": "SYMBOL",
"name": "_ws"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_ws"
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
@ -655,14 +679,22 @@
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "block"
"value": "block "
},
"named": true,
"value": "tag_name"
},
{
"type": "SYMBOL",
"name": "_ws"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_ws"
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
@ -697,14 +729,22 @@
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "blocktranslate"
"value": "blocktranslate "
},
"named": true,
"value": "tag_name"
},
{
"type": "SYMBOL",
"name": "_ws"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_ws"
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
@ -740,14 +780,22 @@
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "blocktranslate"
"value": "blocktranslate "
},
"named": true,
"value": "tag_name"
},
{
"type": "SYMBOL",
"name": "_ws"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_ws"
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
@ -782,14 +830,22 @@
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "ifchanged"
"value": "ifchanged "
},
"named": true,
"value": "tag_name"
},
{
"type": "SYMBOL",
"name": "_ws"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_ws"
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
@ -825,14 +881,22 @@
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "ifchanged"
"value": "ifchanged "
},
"named": true,
"value": "tag_name"
},
{
"type": "SYMBOL",
"name": "_ws"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_ws"
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
@ -867,14 +931,22 @@
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "spaceless"
"value": "spaceless "
},
"named": true,
"value": "tag_name"
},
{
"type": "SYMBOL",
"name": "_ws"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_ws"
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
@ -910,14 +982,22 @@
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "spaceless"
"value": "spaceless "
},
"named": true,
"value": "tag_name"
},
{
"type": "SYMBOL",
"name": "_ws"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_ws"
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
@ -952,14 +1032,22 @@
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "verbatim"
"value": "verbatim "
},
"named": true,
"value": "tag_name"
},
{
"type": "SYMBOL",
"name": "_ws"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_ws"
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
@ -995,14 +1083,22 @@
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "verbatim"
"value": "verbatim "
},
"named": true,
"value": "tag_name"
},
{
"type": "SYMBOL",
"name": "_ws"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_ws"
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
@ -1037,14 +1133,22 @@
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "with"
"value": "with "
},
"named": true,
"value": "tag_name"
},
{
"type": "SYMBOL",
"name": "_ws"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_ws"
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
@ -1080,14 +1184,22 @@
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "with"
"value": "with "
},
"named": true,
"value": "tag_name"
},
{
"type": "SYMBOL",
"name": "_ws"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_ws"
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
@ -1124,14 +1236,22 @@
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "if"
"value": "if "
},
"named": true,
"value": "tag_name"
},
{
"type": "SYMBOL",
"name": "_ws"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_ws"
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
@ -1224,14 +1344,22 @@
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "if"
"value": "if "
},
"named": true,
"value": "tag_name"
},
{
"type": "SYMBOL",
"name": "_ws"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_ws"
},
{
"type": "BLANK"
}
]
},
{
"type": "ALIAS",
@ -1259,14 +1387,22 @@
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "elif"
"value": "elif "
},
"named": true,
"value": "tag_name"
},
{
"type": "SYMBOL",
"name": "_ws"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_ws"
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
@ -1296,14 +1432,22 @@
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "else"
"value": "else "
},
"named": true,
"value": "tag_name"
},
{
"type": "SYMBOL",
"name": "_ws"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_ws"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
@ -1326,14 +1470,22 @@
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "for"
"value": "for "
},
"named": true,
"value": "tag_name"
},
{
"type": "SYMBOL",
"name": "_ws"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_ws"
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
@ -1398,14 +1550,22 @@
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "for"
"value": "for "
},
"named": true,
"value": "tag_name"
},
{
"type": "SYMBOL",
"name": "_ws"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_ws"
},
{
"type": "BLANK"
}
]
},
{
"type": "ALIAS",
@ -1433,14 +1593,22 @@
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "empty"
"value": "empty "
},
"named": true,
"value": "tag_name"
},
{
"type": "SYMBOL",
"name": "_ws"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_ws"
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
@ -1470,14 +1638,22 @@
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "filter"
"value": "filter "
},
"named": true,
"value": "tag_name"
},
{
"type": "SYMBOL",
"name": "_ws"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_ws"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
@ -1530,14 +1706,22 @@
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "filter"
"value": "filter "
},
"named": true,
"value": "tag_name"
},
{
"type": "SYMBOL",
"name": "_ws"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_ws"
},
{
"type": "BLANK"
}
]
},
{
"type": "ALIAS",

34837
src/parser.c

File diff suppressed because it is too large Load diff

View file

@ -595,6 +595,12 @@ custom
{% paired %}
content
{% endpaired %}
{% if_paired %}
content
{% endif_paired %}
{% for_paired %}
content
{% endfor_paired %}
</html>
---
@ -606,6 +612,16 @@ custom
(unpaired_statement
(tag_name))
(content)
(detatched_end_statement
(tag_name))
(unpaired_statement
(tag_name))
(content)
(detatched_end_statement
(tag_name))
(unpaired_statement
(tag_name))
(content)
(detatched_end_statement
(tag_name))
(content))