mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 10:22:05 -05:00
LibWeb: Parse quotes property using TokenStream
This commit is contained in:
parent
ebad94658a
commit
647d52ff9a
2 changed files with 11 additions and 8 deletions
|
@ -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) {
|
if (tokens.remaining_token_count() == 1) {
|
||||||
auto identifier = parse_identifier_value(component_values.first());
|
auto identifier = parse_identifier_value(tokens.next_token());
|
||||||
if (identifier && property_accepts_identifier(PropertyID::Quotes, identifier->to_identifier()))
|
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:
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Add table
Reference in a new issue