LibWeb: Parse descriptors as style values, using the JSON data

The goal here is to do something a bit smarter with the parsing here
than we do for properties. Instead of the JSON saying "here are the
values, and here are the keywords, and we can have up to 3", here we
place the syntax in the JSON directly (though currently broken up as
one string per option) and then we attempt to parse each one in
sequence. It's something we'll need eventually for `@property` among
other things.

...However, in this first pass, I've gone with the simplest option of
hard-coding the types instead of figuring them out properly. So there's
a PositivePercentage type and a UnicodeRangeTokens type, instead of
properly implementing the grammar for those in a generic way.
This commit is contained in:
Sam Atkins 2025-04-02 17:05:48 +01:00
parent 60c536bdd5
commit fd45c53c11
Notes: github-actions[bot] 2025-04-04 09:42:11 +00:00
9 changed files with 356 additions and 7 deletions

View file

@ -64,6 +64,13 @@ CSS::Parser::Parser::PropertiesAndCustomProperties parse_css_style_attribute(CSS
return CSS::Parser::Parser::create(context, css).parse_as_style_attribute();
}
Vector<CSS::Descriptor> parse_css_list_of_descriptors(CSS::Parser::ParsingParams const& parsing_params, CSS::AtRuleID at_rule_id, StringView css)
{
if (css.is_empty())
return {};
return CSS::Parser::Parser::create(parsing_params, css).parse_as_list_of_descriptors(at_rule_id);
}
RefPtr<CSS::CSSStyleValue> parse_css_value(CSS::Parser::ParsingParams const& context, StringView string, CSS::PropertyID property_id)
{
if (string.is_empty())
@ -71,6 +78,13 @@ RefPtr<CSS::CSSStyleValue> parse_css_value(CSS::Parser::ParsingParams const& con
return CSS::Parser::Parser::create(context, string).parse_as_css_value(property_id);
}
RefPtr<CSS::CSSStyleValue> parse_css_descriptor(CSS::Parser::ParsingParams const& parsing_params, CSS::AtRuleID at_rule_id, CSS::DescriptorID descriptor_id, StringView string)
{
if (string.is_empty())
return nullptr;
return CSS::Parser::Parser::create(parsing_params, string).parse_as_descriptor_value(at_rule_id, descriptor_id);
}
CSS::CSSRule* parse_css_rule(CSS::Parser::ParsingParams const& context, StringView css_text)
{
return CSS::Parser::Parser::create(context, css_text).parse_as_css_rule();