1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:17:46 +00:00

LibWeb: Add CSS::Tokenizer::start_of_input_stream_[twin|triplet]()

These correspond to "If the input stream starts with..." in the spec,
which up until now we were not handling correctly, which led to some fun
bugs.

As noted, reconsuming the input code point in order to read its value is
hacky, but works. Keeping track of the current code point in Tokenizer
would be nicer, when I'm feeling brave enough to mess with it!
This commit is contained in:
Sam Atkins 2021-12-24 16:08:35 +00:00 committed by Andreas Kling
parent 8600d89407
commit 981badb45f
2 changed files with 27 additions and 0 deletions

View file

@ -309,6 +309,30 @@ U32Triplet Tokenizer::peek_triplet() const
return values;
}
U32Twin Tokenizer::start_of_input_stream_twin()
{
U32Twin twin;
// FIXME: Reconsuming just to read the current code point again is weird.
reconsume_current_input_code_point();
twin.first = next_code_point();
twin.second = peek_code_point();
return twin;
}
U32Triplet Tokenizer::start_of_input_stream_triplet()
{
U32Triplet triplet;
// FIXME: Reconsuming just to read the current code point again is weird.
reconsume_current_input_code_point();
triplet.first = next_code_point();
auto next_two = peek_twin();
triplet.second = next_two.first;
triplet.third = next_two.second;
return triplet;
}
Token Tokenizer::create_new_token(Token::Type type)
{
Token token = {};

View file

@ -79,6 +79,9 @@ private:
[[nodiscard]] U32Twin peek_twin() const;
[[nodiscard]] U32Triplet peek_triplet() const;
[[nodiscard]] U32Twin start_of_input_stream_twin();
[[nodiscard]] U32Triplet start_of_input_stream_triplet();
[[nodiscard]] static Token create_new_token(Token::Type);
[[nodiscard]] static Token create_value_token(Token::Type, String value);
[[nodiscard]] static Token create_value_token(Token::Type, u32 value);