diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2022-03-30 12:39:36 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-30 18:43:07 +0200 |
commit | 6ec92f5527bb797f842d4e96fec835715639d59b (patch) | |
tree | 126caf3510de94d05cf88c344bca268d1ed53a8f | |
parent | 34b3c094628e381d53c3a3caa6d77611d71217d0 (diff) | |
download | serenity-6ec92f5527bb797f842d4e96fec835715639d59b.zip |
LibWeb: Spec-comment `parse_a_list_of_component_values()`
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 21 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/Parser.h | 5 |
2 files changed, 15 insertions, 11 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 5f506ef495..c5a8bd51b4 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -2008,25 +2008,28 @@ Optional<StyleComponentValueRule> Parser::parse_a_component_value(TokenStream<T> return {}; } -Vector<StyleComponentValueRule> Parser::parse_as_list_of_component_values() -{ - return parse_a_list_of_component_values(m_token_stream); -} - +// 5.3.10. Parse a list of component values +// https://www.w3.org/TR/css-syntax-3/#parse-list-of-component-values template<typename T> Vector<StyleComponentValueRule> Parser::parse_a_list_of_component_values(TokenStream<T>& tokens) { - Vector<StyleComponentValueRule> rules; + // To parse a list of component values from input: + + // 1. Normalize input, and set input to the result. + // Note: This is done when initializing the Parser. + + // 2. Repeatedly consume a component value from input until an <EOF-token> is returned, appending the returned values (except the final <EOF-token>) into a list. Return the list. + Vector<StyleComponentValueRule> component_values; for (;;) { if (tokens.peek_token().is(Token::Type::EndOfFile)) { break; } - rules.append(consume_a_component_value(tokens)); + component_values.append(consume_a_component_value(tokens)); } - return rules; + return component_values; } Vector<Vector<StyleComponentValueRule>> Parser::parse_as_comma_separated_list_of_component_values() @@ -4322,7 +4325,7 @@ RefPtr<StyleValue> Parser::parse_transform_origin_value(Vector<StyleComponentVal RefPtr<StyleValue> Parser::parse_as_css_value(PropertyID property_id) { - auto component_values = parse_as_list_of_component_values(); + auto component_values = parse_a_list_of_component_values(m_token_stream); auto tokens = TokenStream(component_values); auto parsed_value = parse_css_value(property_id, tokens); if (parsed_value.is_error()) diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h index 66c178f9b3..116f3d24d7 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h @@ -89,8 +89,6 @@ public: Parser(ParsingContext const&, StringView input, String const& encoding = "utf-8"); ~Parser() = default; - // For the contents of presentational attributes, which parse text into a single declaration’s value, or for parsing a stand-alone selector [SELECT] or list of Media Queries [MEDIAQ], as in Selectors API or the media HTML attribute. - Vector<StyleComponentValueRule> parse_as_list_of_component_values(); Vector<Vector<StyleComponentValueRule>> parse_as_comma_separated_list_of_component_values(); NonnullRefPtr<CSSStyleSheet> parse_as_css_stylesheet(Optional<AK::URL> location); @@ -152,8 +150,11 @@ private: // "Parse a component value" is for things that need to consume a single value, like the parsing rules for attr(). template<typename T> Optional<StyleComponentValueRule> parse_a_component_value(TokenStream<T>&); + + // "Parse a list of component values" is for the contents of presentational attributes, which parse text into a single declaration’s value, or for parsing a stand-alone selector [SELECT] or list of Media Queries [MEDIAQ], as in Selectors API or the media HTML attribute. template<typename T> Vector<StyleComponentValueRule> parse_a_list_of_component_values(TokenStream<T>&); + template<typename T> Vector<Vector<StyleComponentValueRule>> parse_a_comma_separated_list_of_component_values(TokenStream<T>&); |