mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 02:37:42 +00:00
LibWeb: Don't assume grid-line parts are Tokens
This stops `grid-row-start: {}` from crashing. Also tidy up the parsing code a little.
This commit is contained in:
parent
1f6e13d8fe
commit
314a30b12e
3 changed files with 27 additions and 24 deletions
|
@ -0,0 +1,12 @@
|
||||||
|
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
|
||||||
|
BlockContainer <html> at (0,0) content-size 800x600 [BFC] children: not-inline
|
||||||
|
BlockContainer <body> at (8,8) content-size 784x0 children: not-inline
|
||||||
|
BlockContainer <div> at (8,8) content-size 784x0 children: not-inline
|
||||||
|
BlockContainer <(anonymous)> at (8,16) content-size 784x0 children: inline
|
||||||
|
TextNode <#text>
|
||||||
|
|
||||||
|
ViewportPaintable (Viewport<#document>) [0,0 800x600]
|
||||||
|
PaintableWithLines (BlockContainer<HTML>) [0,0 800x600]
|
||||||
|
PaintableWithLines (BlockContainer<BODY>) [8,8 784x0] overflow: [8,16 784x0]
|
||||||
|
PaintableWithLines (BlockContainer<DIV>) [8,8 784x0]
|
||||||
|
PaintableWithLines (BlockContainer(anonymous)) [8,16 784x0]
|
|
@ -0,0 +1 @@
|
||||||
|
<div style="grid-row-start: {}"></div>
|
|
@ -5345,42 +5345,32 @@ RefPtr<StyleValue> Parser::parse_grid_track_placement(Vector<ComponentValue> con
|
||||||
// <custom-ident> |
|
// <custom-ident> |
|
||||||
// [ <integer> && <custom-ident>? ] |
|
// [ <integer> && <custom-ident>? ] |
|
||||||
// [ span && [ <integer> || <custom-ident> ] ]
|
// [ span && [ <integer> || <custom-ident> ] ]
|
||||||
auto is_auto = [](Token token) -> bool {
|
auto is_valid_integer = [](auto& token) -> bool {
|
||||||
if (token.is(Token::Type::Ident) && token.ident().equals_ignoring_ascii_case("auto"sv))
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
auto is_span = [](Token token) -> bool {
|
|
||||||
if (token.is(Token::Type::Ident) && token.ident().equals_ignoring_ascii_case("span"sv))
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
auto is_valid_integer = [](Token token) -> bool {
|
|
||||||
// An <integer> value of zero makes the declaration invalid.
|
// An <integer> value of zero makes the declaration invalid.
|
||||||
if (token.is(Token::Type::Number) && token.number().is_integer() && token.number_value() != 0)
|
if (token.is(Token::Type::Number) && token.token().number().is_integer() && token.token().number_value() != 0)
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
auto is_identifier = [](Token token) -> bool {
|
auto is_identifier = [](auto& token) -> bool {
|
||||||
// The <custom-ident> additionally excludes the keywords span and auto.
|
// The <custom-ident> additionally excludes the keywords span and auto.
|
||||||
if (token.is(Token::Type::Ident) && !token.ident().equals_ignoring_ascii_case("span"sv) && !token.ident().equals_ignoring_ascii_case("auto"sv))
|
if (token.is(Token::Type::Ident) && !token.token().ident().equals_ignoring_ascii_case("span"sv) && !token.token().ident().equals_ignoring_ascii_case("auto"sv))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto tokens = TokenStream { component_values };
|
auto tokens = TokenStream { component_values };
|
||||||
tokens.skip_whitespace();
|
tokens.skip_whitespace();
|
||||||
auto current_token = tokens.next_token().token();
|
auto current_token = tokens.next_token();
|
||||||
|
|
||||||
if (!tokens.has_next_token()) {
|
if (!tokens.has_next_token()) {
|
||||||
if (is_auto(current_token))
|
if (current_token.is_ident("auto"sv))
|
||||||
return GridTrackPlacementStyleValue::create(GridTrackPlacement::make_auto());
|
return GridTrackPlacementStyleValue::create(GridTrackPlacement::make_auto());
|
||||||
if (is_span(current_token))
|
if (current_token.is_ident("span"sv))
|
||||||
return GridTrackPlacementStyleValue::create(GridTrackPlacement::make_span(1));
|
return GridTrackPlacementStyleValue::create(GridTrackPlacement::make_span(1));
|
||||||
if (is_valid_integer(current_token))
|
if (is_valid_integer(current_token))
|
||||||
return GridTrackPlacementStyleValue::create(GridTrackPlacement::make_line(static_cast<int>(current_token.number_value()), {}));
|
return GridTrackPlacementStyleValue::create(GridTrackPlacement::make_line(static_cast<int>(current_token.token().number_value()), {}));
|
||||||
if (is_identifier(current_token)) {
|
if (is_identifier(current_token)) {
|
||||||
auto maybe_string = String::from_utf8(current_token.ident());
|
auto maybe_string = String::from_utf8(current_token.token().ident());
|
||||||
if (!maybe_string.is_error())
|
if (!maybe_string.is_error())
|
||||||
return GridTrackPlacementStyleValue::create(GridTrackPlacement::make_line({}, maybe_string.value()));
|
return GridTrackPlacementStyleValue::create(GridTrackPlacement::make_line({}, maybe_string.value()));
|
||||||
}
|
}
|
||||||
|
@ -5391,9 +5381,9 @@ RefPtr<StyleValue> Parser::parse_grid_track_placement(Vector<ComponentValue> con
|
||||||
auto span_or_position_value = 0;
|
auto span_or_position_value = 0;
|
||||||
String identifier_value;
|
String identifier_value;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (is_auto(current_token))
|
if (current_token.is_ident("auto"sv))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
if (is_span(current_token)) {
|
if (current_token.is_ident("span"sv)) {
|
||||||
if (span_value == false)
|
if (span_value == false)
|
||||||
span_value = true;
|
span_value = true;
|
||||||
else
|
else
|
||||||
|
@ -5401,13 +5391,13 @@ RefPtr<StyleValue> Parser::parse_grid_track_placement(Vector<ComponentValue> con
|
||||||
}
|
}
|
||||||
if (is_valid_integer(current_token)) {
|
if (is_valid_integer(current_token)) {
|
||||||
if (span_or_position_value == 0)
|
if (span_or_position_value == 0)
|
||||||
span_or_position_value = static_cast<int>(current_token.number_value());
|
span_or_position_value = static_cast<int>(current_token.token().number_value());
|
||||||
else
|
else
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (is_identifier(current_token)) {
|
if (is_identifier(current_token)) {
|
||||||
if (identifier_value.is_empty()) {
|
if (identifier_value.is_empty()) {
|
||||||
auto maybe_string = String::from_utf8(current_token.ident());
|
auto maybe_string = String::from_utf8(current_token.token().ident());
|
||||||
if (maybe_string.is_error())
|
if (maybe_string.is_error())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
identifier_value = maybe_string.release_value();
|
identifier_value = maybe_string.release_value();
|
||||||
|
@ -5417,7 +5407,7 @@ RefPtr<StyleValue> Parser::parse_grid_track_placement(Vector<ComponentValue> con
|
||||||
}
|
}
|
||||||
tokens.skip_whitespace();
|
tokens.skip_whitespace();
|
||||||
if (tokens.has_next_token())
|
if (tokens.has_next_token())
|
||||||
current_token = tokens.next_token().token();
|
current_token = tokens.next_token();
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue