replace arrangements with _kwarg_name for simpleTag kwargs

This commit is contained in:
danhanson committed 2026-09-07 20:01:51 -05:00
1 parent 0caa8c104b
commit 6105fd9002
4 files changed
+54339 -54424

No files matched your search

+3 -2
View File
@@ -144,11 +144,12 @@ function simpleTag($, tag, args = true, kwargs = true) {
repeat(part(seq($._kwarg_name, $.identifier, "=", $.filtered_value))), repeat(part(seq($._kwarg_name, $.identifier, "=", $.filtered_value))),
); );
} else if (kwargs) { } else if (kwargs) {
parts.unshift($._tag_open);
// a known signature: any of the names it accepts, in any order, none twice // a known signature: any of the names it accepts, in any order, none twice
const named = Object.entries(kwargs).map(([name, value]) => const named = Object.entries(kwargs).map(([name, value]) =>
part(seq(name, "=", value)), part(seq($._kwarg_name, name, "=", value)),
); );
parts.push(optional(arrangements(named))); parts.push(repeat(choice(...named)));
} }
return block(tag, ...parts, optional(asVariable($))); return block(tag, ...parts, optional(asVariable($)));
} }
+47 -55
View File
@@ -2501,6 +2501,10 @@
"value": "csp_nonce_attr" "value": "csp_nonce_attr"
} }
}, },
{
"type": "SYMBOL",
"name": "_tag_open"
},
{ {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
@@ -2523,38 +2527,42 @@
] ]
}, },
{ {
"type": "CHOICE", "type": "REPEAT",
"members": [ "content": {
{ "type": "CHOICE",
"type": "SEQ", "members": [
"members": [ {
{ "type": "SEQ",
"type": "PATTERN", "members": [
"value": "[ \\t\\r\\n]+" {
}, "type": "PATTERN",
{ "value": "[ \\t\\r\\n]+"
"type": "SEQ", },
"members": [ {
{ "type": "SEQ",
"type": "STRING", "members": [
"value": "media" {
}, "type": "SYMBOL",
{ "name": "_kwarg_name"
"type": "STRING", },
"value": "=" {
}, "type": "STRING",
{ "value": "media"
"type": "SYMBOL", },
"name": "filtered_value" {
} "type": "STRING",
] "value": "="
} },
] {
}, "type": "SYMBOL",
{ "name": "filtered_value"
"type": "BLANK" }
} ]
] }
]
}
]
}
}, },
{ {
"type": "CHOICE", "type": "CHOICE",
@@ -7953,25 +7961,12 @@
}, },
"extras": [], "extras": [],
"conflicts": [ "conflicts": [
[ ["template"],
"template" ["predicate"],
], ["library", "load"],
[ ["_translate_option"],
"predicate" ["_filtered_value_spaced"],
], ["_filter_expression_spaced"]
[
"library",
"load"
],
[
"_translate_option"
],
[
"_filtered_value_spaced"
],
[
"_filter_expression_spaced"
]
], ],
"precedences": [], "precedences": [],
"externals": [ "externals": [
@@ -8025,10 +8020,7 @@
} }
], ],
"inline": [], "inline": [],
"supertypes": [ "supertypes": ["template_tag", "template_block_groups"],
"template_tag",
"template_block_groups"
],
"reserved": { "reserved": {
"global": [ "global": [
{ {
+54280 -54358
View File
File diff suppressed because it is too large. Load diff
+9 -9
View File
@@ -68,14 +68,16 @@ struct Scanner {
/* one bit per option of the blocktranslate tag being read, by the order of /* one bit per option of the blocktranslate tag being read, by the order of
* translate_options. Kept out of the union below, whose members share their * translate_options. Kept out of the union below, whose members share their
* storage with each other. */ * storage with each other. */
uint8_t translate_seen;
/* the "name=value" argument names the tag being read has been given, each /* the "name=value" argument names the tag being read has been given, each
* followed by NAME_SEP. parse_bits refuses a repeated keyword argument, and * followed by NAME_SEP. parse_bits refuses a repeated keyword argument, and
* the set of names is open, so this remembers the names rather than a mask * the set of names is open, so this remembers the names rather than a mask
* of known ones. Kept out of the union, as translate_seen is. */ * of known ones. Kept out of the union, as translate_seen is. */
Name seen_kwargs;
union { union {
Stack stack; struct {
uint8_t translate_seen;
Name seen_kwargs;
Stack stack;
};
char error [ERROR_SIZE]; char error [ERROR_SIZE];
}; };
}; };
@@ -89,14 +91,12 @@ static enum TokenType pop_token_for_kind(TagKind kind) {
} }
static void reset_scanner(struct Scanner *const scanner) { static void reset_scanner(struct Scanner *const scanner) {
scanner->translate_seen = 0;
array_delete(&scanner->seen_kwargs);
if (scanner->has_error) { if (scanner->has_error) {
scanner->error[0] = '\0'; // sets everything to 0 values: 0, '\0', false, null
scanner->has_error = false; memset(&scanner, 0, sizeof(scanner));
// the error shares storage with the stack, which is now meaningless
memset(&scanner->stack, 0, sizeof(scanner->stack));
} else { } else {
scanner->translate_seen = 0;
array_delete(&scanner->seen_kwargs);
for (unsigned i = 0; i < scanner->stack.size; ++i) { for (unsigned i = 0; i < scanner->stack.size; ++i) {
array_delete(&array_get(&scanner->stack, i)->name); array_delete(&array_get(&scanner->stack, i)->name);
} }