LibWeb: Parse math-depth property using TokenStream

We don't need to skip whitespace at the top level because that's already
done before we're called. But we do still have to skip it inside the
`add()` function
This commit is contained in:
Sam Atkins 2023-12-08 17:06:04 +00:00 committed by Sam Atkins
parent 6e0a550a03
commit 0578bec655
Notes: sideshowbarker 2024-07-18 05:37:06 +09:00
2 changed files with 13 additions and 9 deletions

View file

@ -4443,21 +4443,21 @@ RefPtr<StyleValue> Parser::parse_list_style_value(TokenStream<ComponentValue>& t
{ list_position.release_nonnull(), list_image.release_nonnull(), list_type.release_nonnull() });
}
RefPtr<StyleValue> Parser::parse_math_depth_value(Vector<ComponentValue> const& component_values)
RefPtr<StyleValue> Parser::parse_math_depth_value(TokenStream<ComponentValue>& tokens)
{
// https://w3c.github.io/mathml-core/#propdef-math-depth
// auto-add | add(<integer>) | <integer>
auto tokens = TokenStream { component_values };
auto transaction = tokens.begin_transaction();
tokens.skip_whitespace();
auto token = tokens.next_token();
tokens.skip_whitespace();
if (tokens.has_next_token())
return nullptr;
// auto-add
if (token.is_ident("auto-add"sv))
if (token.is_ident("auto-add"sv)) {
transaction.commit();
return MathDepthStyleValue::create_auto_add();
}
// FIXME: Make it easier to parse "thing that might be <bar> or literally anything that resolves to it" and get rid of this
auto parse_something_that_resolves_to_integer = [this](ComponentValue& token) -> RefPtr<StyleValue> {
@ -4476,14 +4476,18 @@ RefPtr<StyleValue> Parser::parse_math_depth_value(Vector<ComponentValue> const&
add_tokens.skip_whitespace();
if (add_tokens.has_next_token())
return nullptr;
if (auto integer_value = parse_something_that_resolves_to_integer(integer_token))
if (auto integer_value = parse_something_that_resolves_to_integer(integer_token)) {
transaction.commit();
return MathDepthStyleValue::create_add(integer_value.release_nonnull());
}
return nullptr;
}
// <integer>
if (auto integer_value = parse_something_that_resolves_to_integer(token))
if (auto integer_value = parse_something_that_resolves_to_integer(token)) {
transaction.commit();
return MathDepthStyleValue::create_integer(integer_value.release_nonnull());
}
return nullptr;
}
@ -5907,7 +5911,7 @@ Parser::ParseErrorOr<NonnullRefPtr<StyleValue>> Parser::parse_css_value(Property
return parsed_value.release_nonnull();
return ParseError::SyntaxError;
case PropertyID::MathDepth:
if (auto parsed_value = parse_math_depth_value(component_values))
if (auto parsed_value = parse_math_depth_value(tokens); parsed_value && !tokens.has_next_token())
return parsed_value.release_nonnull();
return ParseError::SyntaxError;
case PropertyID::Overflow:

View file

@ -241,7 +241,7 @@ private:
RefPtr<StyleValue> parse_font_value(TokenStream<ComponentValue>&);
RefPtr<StyleValue> parse_font_family_value(TokenStream<ComponentValue>&);
RefPtr<StyleValue> parse_list_style_value(TokenStream<ComponentValue>&);
RefPtr<StyleValue> parse_math_depth_value(Vector<ComponentValue> const&);
RefPtr<StyleValue> parse_math_depth_value(TokenStream<ComponentValue>&);
RefPtr<StyleValue> parse_overflow_value(Vector<ComponentValue> const&);
RefPtr<StyleValue> parse_place_content_value(Vector<ComponentValue> const&);
RefPtr<StyleValue> parse_place_items_value(Vector<ComponentValue> const&);