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

@ -11,24 +11,26 @@
#include <AK/NonnullRefPtr.h>
#include <AK/RefPtr.h>
#include <LibWeb/CSS/Parser/Token.h>
#include <LibWeb/Forward.h>
#include <LibWeb/CSS/Parser/Types.h>
namespace Web::CSS::Parser {
// https://www.w3.org/TR/css-syntax-3/#component-value
// https://drafts.csswg.org/css-syntax/#component-value
class ComponentValue {
public:
ComponentValue(Token);
explicit ComponentValue(NonnullRefPtr<Function>);
explicit ComponentValue(NonnullRefPtr<Block>);
explicit ComponentValue(Function&&);
explicit ComponentValue(SimpleBlock&&);
~ComponentValue();
bool is_block() const { return m_value.has<NonnullRefPtr<Block>>(); }
Block& block() const { return m_value.get<NonnullRefPtr<Block>>(); }
bool is_block() const { return m_value.has<SimpleBlock>(); }
SimpleBlock& block() { return m_value.get<SimpleBlock>(); }
SimpleBlock const& block() const { return m_value.get<SimpleBlock>(); }
bool is_function() const { return m_value.has<NonnullRefPtr<Function>>(); }
bool is_function() const { return m_value.has<Function>(); }
bool is_function(StringView name) const;
Function& function() const { return m_value.get<NonnullRefPtr<Function>>(); }
Function& function() { return m_value.get<Function>(); }
Function const& function() const { return m_value.get<Function>(); }
bool is_token() const { return m_value.has<Token>(); }
bool is(Token::Type type) const { return is_token() && token().is(type); }
@ -41,7 +43,7 @@ public:
String to_debug_string() const;
private:
Variant<Token, NonnullRefPtr<Function>, NonnullRefPtr<Block>> m_value;
Variant<Token, Function, SimpleBlock> m_value;
};
}