From 34b3c094628e381d53c3a3caa6d77611d71217d0 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 30 Mar 2022 12:32:42 +0100 Subject: [PATCH] LibWeb: Spec-comment `parse_a_component_value()` --- .../Libraries/LibWeb/CSS/Parser/Parser.cpp | 27 ++++++++++--------- Userland/Libraries/LibWeb/CSS/Parser/Parser.h | 4 +-- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 9a5b7a0ff6..5f506ef495 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -1979,31 +1979,32 @@ Vector Parser::parse_a_list_of_declarations(TokenStream& return consume_a_list_of_declarations(tokens); } -Optional Parser::parse_as_component_value() -{ - return parse_a_component_value(m_token_stream); -} - +// 5.3.9. Parse a component value +// https://www.w3.org/TR/css-syntax-3/#parse-component-value template Optional Parser::parse_a_component_value(TokenStream& tokens) { + // To parse a component value 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 , consume the next input token from input. tokens.skip_whitespace(); - auto& token = tokens.peek_token(); - - if (token.is(Token::Type::EndOfFile)) { + // 3. If the next input token from input is an , return a syntax error. + if (tokens.peek_token().is(Token::Type::EndOfFile)) return {}; - } + // 4. Consume a component value from input and let value be the return value. auto value = consume_a_component_value(tokens); + // 5. While the next input token from input is a , consume the next input token. tokens.skip_whitespace(); - auto& maybe_eof = tokens.peek_token(); - if (maybe_eof.is(Token::Type::EndOfFile)) { + // 6. If the next input token from input is an , return value. Otherwise, return a syntax error. + if (tokens.peek_token().is(Token::Type::EndOfFile)) return value; - } - return {}; } diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h index 457d2bd3f4..66c178f9b3 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 things that need to consume a single value, like the parsing rules for attr(). - Optional parse_as_component_value(); // 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 parse_as_list_of_component_values(); Vector> parse_as_comma_separated_list_of_component_values(); @@ -150,6 +148,8 @@ private: // "Parse a list of declarations" is for the contents of a style attribute, which parses text into the contents of a single style rule. template Vector parse_a_list_of_declarations(TokenStream&); + + // "Parse a component value" is for things that need to consume a single value, like the parsing rules for attr(). template Optional parse_a_component_value(TokenStream&); template