From 2a2a1986ccbcffbb6589e4e7291811d774ee7e79 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 23 Jul 2025 10:02:34 +0100 Subject: [PATCH] LibWeb/CSS: Add `dump_string()` method to TokenStream This is to support error reporting. It's not the most elegant way of getting the source CSS, but it works. --- Libraries/LibWeb/CSS/Parser/Token.h | 8 ++++++++ Libraries/LibWeb/CSS/Parser/TokenStream.h | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/Libraries/LibWeb/CSS/Parser/Token.h b/Libraries/LibWeb/CSS/Parser/Token.h index a01b5ae7034..de4c59ae39a 100644 --- a/Libraries/LibWeb/CSS/Parser/Token.h +++ b/Libraries/LibWeb/CSS/Parser/Token.h @@ -187,3 +187,11 @@ private: }; } + +template<> +struct AK::Formatter : Formatter { + ErrorOr format(FormatBuilder& builder, Web::CSS::Parser::Token const& token) + { + return Formatter::format(builder, token.to_string()); + } +}; diff --git a/Libraries/LibWeb/CSS/Parser/TokenStream.h b/Libraries/LibWeb/CSS/Parser/TokenStream.h index 6c99421f5b4..f76bc8c5889 100644 --- a/Libraries/LibWeb/CSS/Parser/TokenStream.h +++ b/Libraries/LibWeb/CSS/Parser/TokenStream.h @@ -189,6 +189,13 @@ public: } } + String dump_string() + { + // FIXME: The whitespace is only needed because we strip it when parsing property values. Remove it here once + // we stop doing that. + return MUST(String::join(" "sv, m_tokens)); + } + private: // https://drafts.csswg.org/css-syntax/#token-stream-tokens Span m_tokens;