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))), 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($)));
} }
+18 -26
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,6 +2527,8 @@
] ]
}, },
{ {
"type": "REPEAT",
"content": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
@@ -2535,6 +2541,10 @@
{ {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{
"type": "SYMBOL",
"name": "_kwarg_name"
},
{ {
"type": "STRING", "type": "STRING",
"value": "media" "value": "media"
@@ -2550,11 +2560,9 @@
] ]
} }
] ]
},
{
"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
+8 -8
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 {
struct {
uint8_t translate_seen;
Name seen_kwargs;
Stack stack; 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) {
if (scanner->has_error) {
// sets everything to 0 values: 0, '\0', false, null
memset(&scanner, 0, sizeof(scanner));
} else {
scanner->translate_seen = 0; scanner->translate_seen = 0;
array_delete(&scanner->seen_kwargs); 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) { 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);
} }