mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:07:34 +00:00
LibWeb: Bring parse_a_declaration()
to spec and add comments
User code now calls `parse_as_supports_condition()` which actually does the conversion to a StyleProperty.
This commit is contained in:
parent
239c36a19e
commit
2aac9f9258
3 changed files with 22 additions and 12 deletions
|
@ -1932,26 +1932,36 @@ NonnullRefPtrVector<StyleRule> Parser::parse_a_list_of_rules(TokenStream<T>& tok
|
||||||
return list_of_rules;
|
return list_of_rules;
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<StyleProperty> Parser::parse_as_declaration()
|
Optional<StyleProperty> Parser::parse_as_supports_condition()
|
||||||
{
|
{
|
||||||
return parse_a_declaration(m_token_stream);
|
auto maybe_declaration = parse_a_declaration(m_token_stream);
|
||||||
|
if (maybe_declaration.has_value())
|
||||||
|
return convert_to_style_property(maybe_declaration.release_value());
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 5.3.6. Parse a declaration
|
||||||
|
// https://www.w3.org/TR/css-syntax-3/#parse-a-declaration
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Optional<StyleProperty> Parser::parse_a_declaration(TokenStream<T>& tokens)
|
Optional<StyleDeclarationRule> Parser::parse_a_declaration(TokenStream<T>& tokens)
|
||||||
{
|
{
|
||||||
|
// To parse a declaration from input:
|
||||||
|
|
||||||
|
// 1. Normalize input, and set input to the result.
|
||||||
|
// Note: This is done when initializing the Parser.
|
||||||
|
|
||||||
|
// 2. While the next input token from input is a <whitespace-token>, consume the next input token.
|
||||||
tokens.skip_whitespace();
|
tokens.skip_whitespace();
|
||||||
|
|
||||||
|
// 3. If the next input token from input is not an <ident-token>, return a syntax error.
|
||||||
auto& token = tokens.peek_token();
|
auto& token = tokens.peek_token();
|
||||||
|
|
||||||
if (!token.is(Token::Type::Ident)) {
|
if (!token.is(Token::Type::Ident)) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto declaration = consume_a_declaration(tokens);
|
// 4. Consume a declaration from input. If anything was returned, return it. Otherwise, return a syntax error.
|
||||||
if (declaration.has_value())
|
if (auto declaration = consume_a_declaration(tokens); declaration.has_value())
|
||||||
return convert_to_style_property(declaration.value());
|
return declaration.release_value();
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,8 +89,6 @@ public:
|
||||||
Parser(ParsingContext const&, StringView input, String const& encoding = "utf-8");
|
Parser(ParsingContext const&, StringView input, String const& encoding = "utf-8");
|
||||||
~Parser() = default;
|
~Parser() = default;
|
||||||
|
|
||||||
// Used in @supports conditions. [CSS3-CONDITIONAL]
|
|
||||||
Optional<StyleProperty> parse_as_declaration();
|
|
||||||
// For the contents of a style attribute, which parses text into the contents of a single style rule.
|
// For the contents of a style attribute, which parses text into the contents of a single style rule.
|
||||||
Vector<DeclarationOrAtRule> parse_as_list_of_declarations();
|
Vector<DeclarationOrAtRule> parse_as_list_of_declarations();
|
||||||
// For things that need to consume a single value, like the parsing rules for attr().
|
// For things that need to consume a single value, like the parsing rules for attr().
|
||||||
|
@ -102,6 +100,7 @@ public:
|
||||||
NonnullRefPtr<CSSStyleSheet> parse_as_css_stylesheet(Optional<AK::URL> location);
|
NonnullRefPtr<CSSStyleSheet> parse_as_css_stylesheet(Optional<AK::URL> location);
|
||||||
RefPtr<ElementInlineCSSStyleDeclaration> parse_as_style_attribute(DOM::Element&);
|
RefPtr<ElementInlineCSSStyleDeclaration> parse_as_style_attribute(DOM::Element&);
|
||||||
RefPtr<CSSRule> parse_as_css_rule();
|
RefPtr<CSSRule> parse_as_css_rule();
|
||||||
|
Optional<StyleProperty> parse_as_supports_condition();
|
||||||
|
|
||||||
enum class SelectorParsingMode {
|
enum class SelectorParsingMode {
|
||||||
Standard,
|
Standard,
|
||||||
|
@ -146,8 +145,9 @@ private:
|
||||||
template<typename T>
|
template<typename T>
|
||||||
RefPtr<StyleRule> parse_a_rule(TokenStream<T>&);
|
RefPtr<StyleRule> parse_a_rule(TokenStream<T>&);
|
||||||
|
|
||||||
|
// "Parse a declaration" is used in @supports conditions. [CSS3-CONDITIONAL]
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Optional<StyleProperty> parse_a_declaration(TokenStream<T>&);
|
Optional<StyleDeclarationRule> parse_a_declaration(TokenStream<T>&);
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Vector<DeclarationOrAtRule> parse_a_list_of_declarations(TokenStream<T>&);
|
Vector<DeclarationOrAtRule> parse_a_list_of_declarations(TokenStream<T>&);
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
|
@ -52,7 +52,7 @@ bool Supports::InParens::evaluate() const
|
||||||
|
|
||||||
bool Supports::Declaration::evaluate() const
|
bool Supports::Declaration::evaluate() const
|
||||||
{
|
{
|
||||||
auto style_property = Parser({}, declaration).parse_as_declaration();
|
auto style_property = Parser({}, declaration).parse_as_supports_condition();
|
||||||
return style_property.has_value();
|
return style_property.has_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue