fix scanner and update regexes

This commit is contained in:
danhanson committed 2026-09-06 05:01:03 -05:00
1 parent 140e099275
commit d86f6533a8
6 files changed
+1312 -1270

No files matched your search

+2 -2
View File
@@ -73,8 +73,8 @@ const django = grammar({
seq($.filter, repeat(seq(token.immediate("|"), $.filter))),
value: ($) => choice($.literal, $.variable_attribute),
literal: ($) => seq(choice($.number, $.string), $._after_literal),
number: ($) => /-?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[eE]-?[0-9]+)?/,
string: ($) => /"(?:[^"\\]|\\\\|\\")*"|'(?:[^'\\]|\\\\|\\')*'/,
number: ($) => /[-+]?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[eE][0-9]+)?/,
string: ($) => /"(?:[^"\\]|\\[^\n])*"|'(?:[^'\\]|\\[^\n])*'/,
attribute: ($) => /[a-zA-Z0-9_]+(?:\.[a-zA-Z0-9_]+)*/,
variable_attribute: ($) =>
seq($.identifier, optional(seq(token.immediate("."), $.attribute))),
+2 -2
View File
@@ -138,11 +138,11 @@
},
"number": {
"type": "PATTERN",
"value": "-?(?:[0-9]+(?:\\.[0-9]*)?|\\.[0-9]+)(?:[eE]-?[0-9]+)?"
"value": "[-+]?(?:[0-9]+(?:\\.[0-9]*)?|\\.[0-9]+)(?:[eE][0-9]+)?"
},
"string": {
"type": "PATTERN",
"value": "\"(?:[^\"\\\\]|\\\\\\\\|\\\\\")*\"|'(?:[^'\\\\]|\\\\\\\\|\\\\')*'"
"value": "\"(?:[^\"\\\\]|\\\\[^\\n])*\"|'(?:[^'\\\\]|\\\\[^\\n])*'"
},
"attribute": {
"type": "PATTERN",
+1259 -1265
View File
File diff suppressed because it is too large. Load diff
+3 -1
View File
@@ -471,7 +471,9 @@ static bool scan_verbatim_content(struct Scanner *const scanner, TSLexer *const
* it, which leaves this the only place to catch the run-on. */
static bool scan_after_literal(TSLexer *const lexer) {
int32_t next = lexer->lookahead;
if (check_name_char(next) || next == '\'' || next == '"' || next == '-') {
// anything that could begin another value: a name, a quote, or a sign or
// point that would start a second number ("{% cycle 1.2.3 %}")
if (check_name_char(next) || next == '\'' || next == '"' || next == '-' || next == '+' || next == '.') {
return false;
}
lexer->mark_end(lexer);
+11
View File
@@ -113,3 +113,14 @@ Cycle Value Adjacent To Value
---
(ERROR)
==================
Cycle Number Run On To Number
:error
==================
{% cycle 1.2.3 %}
---
(ERROR)
+35
View File
@@ -211,3 +211,38 @@ Template Variable Literal Adjacent To Name
---
(ERROR)
==================
Template Variable With Escaped String
==================
{{ "a\nb\"c" }}
---
(template
(content)
(template_variable
(filtered_value
(value
(literal
(string)))))
(content))
==================
Template Variable Signed Number
==================
{{ +1.5 }}
---
(template
(content)
(template_variable
(filtered_value
(value
(literal
(number)))))
(content))