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
+54309 -54394

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))),
);
} else if (kwargs) {
parts.unshift($._tag_open);
// a known signature: any of the names it accepts, in any order, none twice
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($)));
}
+18 -26
View File
@@ -2501,6 +2501,10 @@
"value": "csp_nonce_attr"
}
},
{
"type": "SYMBOL",
"name": "_tag_open"
},
{
"type": "CHOICE",
"members": [
@@ -2523,6 +2527,8 @@
]
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
@@ -2535,6 +2541,10 @@
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_kwarg_name"
},
{
"type": "STRING",
"value": "media"
@@ -2550,11 +2560,9 @@
]
}
]
},
{
"type": "BLANK"
}
]
}
},
{
"type": "CHOICE",
@@ -7953,25 +7961,12 @@
},
"extras": [],
"conflicts": [
[
"template"
],
[
"predicate"
],
[
"library",
"load"
],
[
"_translate_option"
],
[
"_filtered_value_spaced"
],
[
"_filter_expression_spaced"
]
["template"],
["predicate"],
["library", "load"],
["_translate_option"],
["_filtered_value_spaced"],
["_filter_expression_spaced"]
],
"precedences": [],
"externals": [
@@ -8025,10 +8020,7 @@
}
],
"inline": [],
"supertypes": [
"template_tag",
"template_block_groups"
],
"supertypes": ["template_tag", "template_block_groups"],
"reserved": {
"global": [
{
+54280 -54358
View File
File diff suppressed because it is too large. Load diff
+8 -8
View File
@@ -68,14 +68,16 @@ struct Scanner {
/* 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
* storage with each other. */
uint8_t translate_seen;
/* 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
* 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. */
Name seen_kwargs;
union {
struct {
uint8_t translate_seen;
Name seen_kwargs;
Stack stack;
};
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) {
if (scanner->has_error) {
// sets everything to 0 values: 0, '\0', false, null
memset(&scanner, 0, sizeof(scanner));
} else {
scanner->translate_seen = 0;
array_delete(&scanner->seen_kwargs);
if (scanner->has_error) {
scanner->error[0] = '\0';
scanner->has_error = false;
// the error shares storage with the stack, which is now meaningless
memset(&scanner->stack, 0, sizeof(scanner->stack));
} else {
for (unsigned i = 0; i < scanner->stack.size; ++i) {
array_delete(&array_get(&scanner->stack, i)->name);
}