LibWeb/CSS: Rewrite CSS Parser core methods according to new spec

CSS Syntax 3 (https://drafts.csswg.org/css-syntax) has changed
significantly since we implemented it a couple of years ago. Just about
every parsing algorithm has been rewritten in terms of the new token
stream concept, and to support nested styles. As all of those
algorithms call into each other, this is an unfortunately chonky diff.

As part of this, the transitory types (Declaration, Function, AtRule...)
have been rewritten. That's both because we have new requirements of
what they should be and contain, and also because the spec asks us to
create and then gradually modify them in place, which is easier if they
are plain structs.
This commit is contained in:
Sam Atkins 2024-10-11 11:17:10 +01:00 committed by Andreas Kling
commit e0be17e4fb
Notes: github-actions[bot] 2024-10-14 06:09:33 +00:00
24 changed files with 1126 additions and 1278 deletions

View file

@ -5,9 +5,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/CSS/Parser/Block.h>
#include <LibWeb/CSS/Parser/ComponentValue.h>
#include <LibWeb/CSS/Parser/Function.h>
namespace Web::CSS::Parser {
@ -15,11 +13,11 @@ ComponentValue::ComponentValue(Token token)
: m_value(token)
{
}
ComponentValue::ComponentValue(NonnullRefPtr<Function> function)
ComponentValue::ComponentValue(Function&& function)
: m_value(function)
{
}
ComponentValue::ComponentValue(NonnullRefPtr<Block> block)
ComponentValue::ComponentValue(SimpleBlock&& block)
: m_value(block)
{
}
@ -28,7 +26,7 @@ ComponentValue::~ComponentValue() = default;
bool ComponentValue::is_function(StringView name) const
{
return is_function() && function().name().equals_ignoring_ascii_case(name);
return is_function() && function().name.equals_ignoring_ascii_case(name);
}
bool ComponentValue::is_ident(StringView ident) const
@ -40,8 +38,8 @@ String ComponentValue::to_string() const
{
return m_value.visit(
[](Token const& token) { return token.to_string(); },
[](NonnullRefPtr<Block> const& block) { return block->to_string(); },
[](NonnullRefPtr<Function> const& function) { return function->to_string(); });
[](SimpleBlock const& block) { return block.to_string(); },
[](Function const& function) { return function.to_string(); });
}
String ComponentValue::to_debug_string() const
@ -50,11 +48,11 @@ String ComponentValue::to_debug_string() const
[](Token const& token) {
return MUST(String::formatted("Token: {}", token.to_debug_string()));
},
[](NonnullRefPtr<Block> const& block) {
return MUST(String::formatted("Block: {}", block->to_string()));
[](SimpleBlock const& block) {
return MUST(String::formatted("Block: {}", block.to_string()));
},
[](NonnullRefPtr<Function> const& function) {
return MUST(String::formatted("Function: {}", function->to_string()));
[](Function const& function) {
return MUST(String::formatted("Function: {}", function.to_string()));
});
}