浏览代码

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
Sam Atkins 1 年之前
父节点
当前提交
0578bec655
共有 2 个文件被更改,包括 13 次插入9 次删除
  1. 12 8
      Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
  2. 1 1
      Userland/Libraries/LibWeb/CSS/Parser/Parser.h

+ 12 - 8
Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp

@@ -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:

+ 1 - 1
Userland/Libraries/LibWeb/CSS/Parser/Parser.h

@@ -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&);