summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/CSS
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-03-30 12:56:15 +0100
committerAndreas Kling <kling@serenityos.org>2022-03-30 18:43:07 +0200
commita4f805682874a7a6b60d75e78494921c23dc09dd (patch)
tree84a2ea833e9783b463b50feaffc96aaa0207fdce /Userland/Libraries/LibWeb/CSS
parent6ec92f5527bb797f842d4e96fec835715639d59b (diff)
downloadserenity-a4f805682874a7a6b60d75e78494921c23dc09dd.zip
LibWeb: Spec-comment `parse_a_comma_separated_list_of_component_values`
The code had to change a bit to match. Previously, we appended an empty sub-list immediately, but now we append it at the end. The difference is that if there are no tokens, we now correctly return an empty list-of-lists, instead of a list containing an empty list.
Diffstat (limited to 'Userland/Libraries/LibWeb/CSS')
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp41
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Parser.h2
2 files changed, 25 insertions, 18 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
index c5a8bd51b4..0fa1bbbab8 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
@@ -2032,33 +2032,42 @@ Vector<StyleComponentValueRule> Parser::parse_a_list_of_component_values(TokenSt
return component_values;
}
-Vector<Vector<StyleComponentValueRule>> Parser::parse_as_comma_separated_list_of_component_values()
-{
- return parse_a_comma_separated_list_of_component_values(m_token_stream);
-}
-
+// 5.3.11. Parse a comma-separated list of component values
+// https://www.w3.org/TR/css-syntax-3/#parse-comma-separated-list-of-component-values
template<typename T>
Vector<Vector<StyleComponentValueRule>> Parser::parse_a_comma_separated_list_of_component_values(TokenStream<T>& tokens)
{
- Vector<Vector<StyleComponentValueRule>> lists;
- lists.append({});
+ // To parse a comma-separated list of component values from input:
+
+ // 1. Normalize input, and set input to the result.
+ // Note: This is done when initializing the Parser.
+
+ // 2. Let list of cvls be an initially empty list of component value lists.
+ Vector<Vector<StyleComponentValueRule>> list_of_component_value_lists;
+ // 3. Repeatedly consume a component value from input until an <EOF-token> or <comma-token> is returned,
+ // appending the returned values (except the final <EOF-token> or <comma-token>) into a list.
+ // Append the list to list of cvls.
+ // If it was a <comma-token> that was returned, repeat this step.
+ Vector<StyleComponentValueRule> current_list;
for (;;) {
- auto& next = tokens.next_token();
+ auto component_value = consume_a_component_value(tokens);
- if (next.is(Token::Type::Comma)) {
- lists.append({});
- continue;
- } else if (next.is(Token::Type::EndOfFile)) {
+ if (component_value.is(Token::Type::EndOfFile)) {
+ list_of_component_value_lists.append(move(current_list));
break;
}
+ if (component_value.is(Token::Type::Comma)) {
+ list_of_component_value_lists.append(move(current_list));
+ current_list = {};
+ continue;
+ }
- tokens.reconsume_current_input_token();
- auto component_value = consume_a_component_value(tokens);
- lists.last().append(component_value);
+ current_list.append(component_value);
}
- return lists;
+ // 4. Return list of cvls.
+ return list_of_component_value_lists;
}
RefPtr<ElementInlineCSSStyleDeclaration> Parser::parse_as_style_attribute(DOM::Element& element)
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h
index 116f3d24d7..c7b3ce853c 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;
- Vector<Vector<StyleComponentValueRule>> parse_as_comma_separated_list_of_component_values();
-
NonnullRefPtr<CSSStyleSheet> parse_as_css_stylesheet(Optional<AK::URL> location);
RefPtr<ElementInlineCSSStyleDeclaration> parse_as_style_attribute(DOM::Element&);
RefPtr<CSSRule> parse_as_css_rule();