diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 9fc0f098c6..e5c5d788d8 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -1903,24 +1903,21 @@ RefPtr Parser::parse_a_rule(TokenStream& tokens) return {}; } -NonnullRefPtrVector Parser::parse_as_list_of_rules() -{ - return parse_a_list_of_rules(m_token_stream); -} - +// 5.3.4. Parse a list of rules +// https://www.w3.org/TR/css-syntax-3/#parse-list-of-rules template -NonnullRefPtrVector Parser::parse_a_list_of_rules(TokenStream& tokens) +NonnullRefPtrVector Parser::parse_a_list_of_rules(TokenStream& tokens) { - auto parsed_rules = consume_a_list_of_rules(tokens, TopLevel::No); - NonnullRefPtrVector rules; + // To parse a list of rules from input: - for (auto& rule : parsed_rules) { - auto converted_rule = convert_to_rule(rule); - if (converted_rule) - rules.append(*converted_rule); - } + // 1. Normalize input, and set input to the result. + // Note: This is done when initializing the Parser. - return rules; + // 2. Consume a list of rules from the input, with the top-level flag unset. + auto list_of_rules = consume_a_list_of_rules(tokens, TopLevel::No); + + // 3. Return the returned list. + return list_of_rules; } Optional Parser::parse_as_declaration() diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h index 20ac61d0ca..5f37f05e4b 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 content of at-rules such as @media. It differs from "Parse a stylesheet" in the handling of and . - NonnullRefPtrVector parse_as_list_of_rules(); // For use by the CSSStyleSheet#insertRule method, and similar functions which might exist, which parse text into a single rule. RefPtr parse_as_rule(); // Used in @supports conditions. [CSS3-CONDITIONAL] @@ -141,8 +139,9 @@ private: template ParsedStyleSheet parse_a_stylesheet(TokenStream&, Optional location); + // For the content of at-rules such as @media. It differs from "Parse a stylesheet" in the handling of and . template - NonnullRefPtrVector parse_a_list_of_rules(TokenStream&); + NonnullRefPtrVector parse_a_list_of_rules(TokenStream&); template RefPtr parse_a_rule(TokenStream&); template