Explorar o código

LibWeb: Parse quotes property using TokenStream

Sam Atkins hai 1 ano
pai
achega
647d52ff9a

+ 10 - 7
Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp

@@ -4579,23 +4579,25 @@ RefPtr<StyleValue> Parser::parse_place_self_value(Vector<ComponentValue> const&
         { *maybe_align_self_value, *maybe_justify_self_value });
         { *maybe_align_self_value, *maybe_justify_self_value });
 }
 }
 
 
-RefPtr<StyleValue> Parser::parse_quotes_value(Vector<ComponentValue> const& component_values)
+RefPtr<StyleValue> Parser::parse_quotes_value(TokenStream<ComponentValue>& tokens)
 {
 {
     // https://www.w3.org/TR/css-content-3/#quotes-property
     // https://www.w3.org/TR/css-content-3/#quotes-property
     // auto | none | [ <string> <string> ]+
     // auto | none | [ <string> <string> ]+
+    auto transaction = tokens.begin_transaction();
 
 
-    if (component_values.size() == 1) {
-        auto identifier = parse_identifier_value(component_values.first());
-        if (identifier && property_accepts_identifier(PropertyID::Quotes, identifier->to_identifier()))
+    if (tokens.remaining_token_count() == 1) {
+        auto identifier = parse_identifier_value(tokens.next_token());
+        if (identifier && property_accepts_identifier(PropertyID::Quotes, identifier->to_identifier())) {
+            transaction.commit();
             return identifier;
             return identifier;
+        }
         return nullptr;
         return nullptr;
     }
     }
 
 
     // Parse an even number of <string> values.
     // Parse an even number of <string> values.
-    if (component_values.size() % 2 != 0)
+    if (tokens.remaining_token_count() % 2 != 0)
         return nullptr;
         return nullptr;
 
 
-    auto tokens = TokenStream { component_values };
     StyleValueVector string_values;
     StyleValueVector string_values;
     while (tokens.has_next_token()) {
     while (tokens.has_next_token()) {
         auto maybe_string = parse_string_value(tokens.next_token());
         auto maybe_string = parse_string_value(tokens.next_token());
@@ -4605,6 +4607,7 @@ RefPtr<StyleValue> Parser::parse_quotes_value(Vector<ComponentValue> const& comp
         string_values.append(maybe_string.release_nonnull());
         string_values.append(maybe_string.release_nonnull());
     }
     }
 
 
+    transaction.commit();
     return StyleValueList::create(move(string_values), StyleValueList::Separator::Space);
     return StyleValueList::create(move(string_values), StyleValueList::Separator::Space);
 }
 }
 
 
@@ -5893,7 +5896,7 @@ Parser::ParseErrorOr<NonnullRefPtr<StyleValue>> Parser::parse_css_value(Property
             return parsed_value.release_nonnull();
             return parsed_value.release_nonnull();
         return ParseError::SyntaxError;
         return ParseError::SyntaxError;
     case PropertyID::Quotes:
     case PropertyID::Quotes:
-        if (auto parsed_value = parse_quotes_value(component_values))
+        if (auto parsed_value = parse_quotes_value(tokens); parsed_value && !tokens.has_next_token())
             return parsed_value.release_nonnull();
             return parsed_value.release_nonnull();
         return ParseError::SyntaxError;
         return ParseError::SyntaxError;
     case PropertyID::TextDecoration:
     case PropertyID::TextDecoration:

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

@@ -245,7 +245,7 @@ private:
     RefPtr<StyleValue> parse_place_content_value(Vector<ComponentValue> const&);
     RefPtr<StyleValue> parse_place_content_value(Vector<ComponentValue> const&);
     RefPtr<StyleValue> parse_place_items_value(Vector<ComponentValue> const&);
     RefPtr<StyleValue> parse_place_items_value(Vector<ComponentValue> const&);
     RefPtr<StyleValue> parse_place_self_value(Vector<ComponentValue> const&);
     RefPtr<StyleValue> parse_place_self_value(Vector<ComponentValue> const&);
-    RefPtr<StyleValue> parse_quotes_value(Vector<ComponentValue> const&);
+    RefPtr<StyleValue> parse_quotes_value(TokenStream<ComponentValue>&);
     enum class AllowInsetKeyword {
     enum class AllowInsetKeyword {
         No,
         No,
         Yes,
         Yes,