LibWeb: Rename "identifier" and "ValueID" to "Keyword" where correct

For a long time, we've used two terms, inconsistently:
- "Identifier" is a spec term, but refers to a sequence of alphanumeric
  characters, which may or may not be a keyword. (Keywords are a
  subset of all identifiers.)
- "ValueID" is entirely non-spec, and is directly called a "keyword" in
  the CSS specs.

So to avoid confusion as much as possible, let's align with the spec
terminology. I've attempted to change variable names as well, but
obviously we use Keywords in a lot of places in LibWeb and so I may
have missed some.

One exception is that I've not renamed "valid-identifiers" in
Properties.json... I'd like to combine that and the "valid-types" array
together eventually, so there's no benefit to doing an extra rename
now.
This commit is contained in:
Sam Atkins 2024-08-14 14:06:03 +01:00 committed by Sam Atkins
commit 6a74b01644
Notes: github-actions[bot] 2024-08-15 12:59:33 +00:00
48 changed files with 702 additions and 702 deletions

View file

@ -223,7 +223,7 @@ enum class ValueType {
Url,
};
bool property_accepts_type(PropertyID, ValueType);
bool property_accepts_identifier(PropertyID, ValueID);
bool property_accepts_keyword(PropertyID, Keyword);
Optional<ValueType> property_resolves_percentages_relative_to(PropertyID);
// These perform range-checking, but are also safe to call with properties that don't accept that type. (They'll just return false.)
@ -811,7 +811,7 @@ bool property_accepts_type(PropertyID property_id, ValueType value_type)
}
}
bool property_accepts_identifier(PropertyID property_id, ValueID identifier)
bool property_accepts_keyword(PropertyID property_id, Keyword keyword)
{
switch (property_id) {
)~~~");
@ -824,12 +824,12 @@ bool property_accepts_identifier(PropertyID property_id, ValueID identifier)
property_generator.appendln(" case PropertyID::@name:titlecase@: {");
if (auto maybe_valid_identifiers = object.get_array("valid-identifiers"sv); maybe_valid_identifiers.has_value() && !maybe_valid_identifiers->is_empty()) {
property_generator.appendln(" switch (identifier) {");
property_generator.appendln(" switch (keyword) {");
auto& valid_identifiers = maybe_valid_identifiers.value();
for (auto& identifier : valid_identifiers.values()) {
auto identifier_generator = generator.fork();
identifier_generator.set("identifier:titlecase", title_casify(identifier.as_string()));
identifier_generator.appendln(" case ValueID::@identifier:titlecase@:");
for (auto& keyword : valid_identifiers.values()) {
auto keyword_generator = generator.fork();
keyword_generator.set("keyword:titlecase", title_casify(keyword.as_string()));
keyword_generator.appendln(" case Keyword::@keyword:titlecase@:");
}
property_generator.append(R"~~~(
return true;
@ -849,7 +849,7 @@ bool property_accepts_identifier(PropertyID property_id, ValueID identifier)
auto type_generator = generator.fork();
type_generator.set("type_name:snakecase", snake_casify(type_name));
type_generator.append(R"~~~(
if (value_id_to_@type_name:snakecase@(identifier).has_value())
if (keyword_to_@type_name:snakecase@(keyword).has_value())
return true;
)~~~");
}