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.
This commit is contained in:
Sam Atkins 2025-07-23 10:02:34 +01:00
commit 2a2a1986cc
Notes: github-actions[bot] 2025-08-04 09:52:44 +00:00
2 changed files with 15 additions and 0 deletions

View file

@ -187,3 +187,11 @@ private:
};
}
template<>
struct AK::Formatter<Web::CSS::Parser::Token> : Formatter<StringView> {
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::Parser::Token const& token)
{
return Formatter<StringView>::format(builder, token.to_string());
}
};

View file

@ -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<T const> m_tokens;