mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-29 15:58:47 +00:00
LibWeb/CSS: Bring TokenStream in line with spec
When the TokenStream code was originally written, there was no such concept in the CSS Syntax spec. But since then, it's been officially added, (https://drafts.csswg.org/css-syntax/#css-token-stream) and the parsing algorithms are described in terms of it. This patch brings our implementation in line with the spec. A few deprecated TokenStream methods are left around until their users are also updated to match the newer spec. There are a few differences: - They name things differently. The main confusing one is we had `next_token()` which consumed a token and returned it, but the spec has a `next_token()` which peeks the next token. The spec names are honestly better than what I'd come up with. (`discard_a_token()` is a nice addition too!) - We used to store the index of the token that was just consumed, and they instead store the index of the token that will be consumed next. This is a perfect breeding ground for off-by-one errors, so I've finally added a test suite for TokenStream itself. - We use a transaction system for rewinding, and the spec uses a stack of "marks", which can be manually rewound to. These should be able to coexist as long as we stick with marks in the parser spec algorithms, and stick with transactions elsewhere.
This commit is contained in:
parent
5df6c6eecf
commit
b645e26e9b
Notes:
github-actions[bot]
2024-10-09 16:30:23 +00:00
Author: https://github.com/AtkinsSJ
Commit: b645e26e9b
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1694
8 changed files with 763 additions and 603 deletions
|
@ -97,15 +97,15 @@ namespace Web::CSS::Parser {
|
|||
static Optional<RoundingStrategy> parse_rounding_strategy(Vector<ComponentValue> const& tokens)
|
||||
{
|
||||
auto stream = TokenStream { tokens };
|
||||
stream.skip_whitespace();
|
||||
stream.discard_whitespace();
|
||||
if (!stream.has_next_token())
|
||||
return {};
|
||||
|
||||
auto& ident = stream.next_token();
|
||||
auto& ident = stream.consume_a_token();
|
||||
if (!ident.is(Token::Type::Ident))
|
||||
return {};
|
||||
|
||||
stream.skip_whitespace();
|
||||
stream.discard_whitespace();
|
||||
if (stream.has_next_token())
|
||||
return {};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue