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

LibWeb: Parse flex property using TokenStream

This commit is contained in:
Sam Atkins 2023-12-07 17:28:55 +00:00 committed by Sam Atkins
parent 4f3136c230
commit bf3576667a
2 changed files with 6 additions and 5 deletions

View file

@ -3815,17 +3815,18 @@ RefPtr<StyleValue> Parser::parse_filter_value_list_value(TokenStream<ComponentVa
return FilterValueListStyleValue::create(move(filter_value_list)); return FilterValueListStyleValue::create(move(filter_value_list));
} }
RefPtr<StyleValue> Parser::parse_flex_value(Vector<ComponentValue> const& component_values) RefPtr<StyleValue> Parser::parse_flex_value(TokenStream<ComponentValue>& tokens)
{ {
auto tokens = TokenStream { component_values }; auto transaction = tokens.begin_transaction();
auto make_flex_shorthand = [&](NonnullRefPtr<StyleValue> flex_grow, NonnullRefPtr<StyleValue> flex_shrink, NonnullRefPtr<StyleValue> flex_basis) { auto make_flex_shorthand = [&](NonnullRefPtr<StyleValue> flex_grow, NonnullRefPtr<StyleValue> flex_shrink, NonnullRefPtr<StyleValue> flex_basis) {
transaction.commit();
return ShorthandStyleValue::create(PropertyID::Flex, return ShorthandStyleValue::create(PropertyID::Flex,
{ PropertyID::FlexGrow, PropertyID::FlexShrink, PropertyID::FlexBasis }, { PropertyID::FlexGrow, PropertyID::FlexShrink, PropertyID::FlexBasis },
{ move(flex_grow), move(flex_shrink), move(flex_basis) }); { move(flex_grow), move(flex_shrink), move(flex_basis) });
}; };
if (component_values.size() == 1) { if (tokens.remaining_token_count() == 1) {
// One-value syntax: <flex-grow> | <flex-basis> | none // One-value syntax: <flex-grow> | <flex-basis> | none
auto properties = Array { PropertyID::FlexGrow, PropertyID::FlexBasis, PropertyID::Flex }; auto properties = Array { PropertyID::FlexGrow, PropertyID::FlexBasis, PropertyID::Flex };
auto property_and_value = parse_css_value_for_properties(properties, tokens); auto property_and_value = parse_css_value_for_properties(properties, tokens);
@ -5802,7 +5803,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::Flex: case PropertyID::Flex:
if (auto parsed_value = parse_flex_value(component_values)) if (auto parsed_value = parse_flex_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::FlexFlow: case PropertyID::FlexFlow:

View file

@ -236,7 +236,7 @@ private:
RefPtr<StyleValue> parse_border_radius_shorthand_value(TokenStream<ComponentValue>&); RefPtr<StyleValue> parse_border_radius_shorthand_value(TokenStream<ComponentValue>&);
RefPtr<StyleValue> parse_content_value(TokenStream<ComponentValue>&); RefPtr<StyleValue> parse_content_value(TokenStream<ComponentValue>&);
RefPtr<StyleValue> parse_display_value(TokenStream<ComponentValue>&); RefPtr<StyleValue> parse_display_value(TokenStream<ComponentValue>&);
RefPtr<StyleValue> parse_flex_value(Vector<ComponentValue> const&); RefPtr<StyleValue> parse_flex_value(TokenStream<ComponentValue>&);
RefPtr<StyleValue> parse_flex_flow_value(Vector<ComponentValue> const&); RefPtr<StyleValue> parse_flex_flow_value(Vector<ComponentValue> const&);
RefPtr<StyleValue> parse_font_value(Vector<ComponentValue> const&); RefPtr<StyleValue> parse_font_value(Vector<ComponentValue> const&);
RefPtr<StyleValue> parse_font_family_value(TokenStream<ComponentValue>&); RefPtr<StyleValue> parse_font_family_value(TokenStream<ComponentValue>&);