diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2022-03-30 14:34:44 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-30 18:43:07 +0200 |
commit | 512d1df1c4b61f24131f2cca7be390d6c05476e5 (patch) | |
tree | 2969fcf87d999078c2a9a3944bae57c201d832ed | |
parent | 5a23965e937746923e15584898554871335777c4 (diff) | |
download | serenity-512d1df1c4b61f24131f2cca7be390d6c05476e5.zip |
LibWeb: Spec-comment `consume_a_simple_block()`
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 982e3f7aac..abafb82511 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -1724,29 +1724,49 @@ StyleComponentValueRule Parser::consume_a_component_value(TokenStream<T>& tokens return StyleComponentValueRule(token); } +// 5.4.8. Consume a simple block +// https://www.w3.org/TR/css-syntax-3/#consume-simple-block template<typename T> NonnullRefPtr<StyleBlockRule> Parser::consume_a_simple_block(TokenStream<T>& tokens) { + // Note: This algorithm assumes that the current input token has already been checked + // to be an <{-token>, <[-token>, or <(-token>. + + // To consume a simple block: + + // The ending token is the mirror variant of the current input token. + // (E.g. if it was called with <[-token>, the ending token is <]-token>.) auto ending_token = ((Token)tokens.current_token()).mirror_variant(); + // Create a simple block with its associated token set to the current input token + // and with its value initially set to an empty list. auto block = make_ref_counted<StyleBlockRule>(); block->m_token = tokens.current_token(); + // Repeatedly consume the next input token and process it as follows: for (;;) { auto& token = tokens.next_token(); + // ending token if (token.is(ending_token)) { + // Return the block. return block; } - + // <EOF-token> if (token.is(Token::Type::EndOfFile)) { + // This is a parse error. Return the block. log_parse_error(); return block; } - tokens.reconsume_current_input_token(); - auto value = consume_a_component_value(tokens); - block->m_values.append(value); + // anything else + { + // Reconsume the current input token. + tokens.reconsume_current_input_token(); + + // Consume a component value and append it to the value of the block. + block->m_values.append(consume_a_component_value(tokens)); + } } } |