mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:07:34 +00:00
LibWeb: Move function parsing to separate method
This commit is contained in:
parent
47fc91ed43
commit
570e43a66a
2 changed files with 22 additions and 13 deletions
|
@ -3439,18 +3439,31 @@ ErrorOr<RefPtr<StyleValue>> Parser::parse_dynamic_value(ComponentValue const& co
|
||||||
if (component_value.is_function()) {
|
if (component_value.is_function()) {
|
||||||
auto const& function = component_value.function();
|
auto const& function = component_value.function();
|
||||||
|
|
||||||
if (function.name().equals_ignoring_ascii_case("calc"sv))
|
|
||||||
return parse_calculated_value(function.values());
|
|
||||||
|
|
||||||
if (function.name().equals_ignoring_ascii_case("var"sv)) {
|
if (function.name().equals_ignoring_ascii_case("var"sv)) {
|
||||||
// Declarations using `var()` should already be parsed as an UnresolvedStyleValue before this point.
|
// Declarations using `var()` should already be parsed as an UnresolvedStyleValue before this point.
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto function_node = TRY(parse_a_calc_function_node(function));
|
||||||
|
if (!function_node)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
auto function_type = function_node->resolved_type().value();
|
||||||
|
return CalculatedStyleValue::create(function_node.release_nonnull(), function_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ErrorOr<OwnPtr<CalculationNode>> Parser::parse_a_calc_function_node(Function const& function)
|
||||||
|
{
|
||||||
|
if (function.name().equals_ignoring_ascii_case("calc"sv))
|
||||||
|
return TRY(parse_a_calculation(function.values()));
|
||||||
|
|
||||||
|
dbgln_if(CSS_PARSER_DEBUG, "We didn't implement `{}` function yet", function.name());
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
Optional<Parser::Dimension> Parser::parse_dimension(ComponentValue const& component_value)
|
Optional<Parser::Dimension> Parser::parse_dimension(ComponentValue const& component_value)
|
||||||
{
|
{
|
||||||
if (component_value.is(Token::Type::Dimension)) {
|
if (component_value.is(Token::Type::Dimension)) {
|
||||||
|
@ -8068,19 +8081,14 @@ ErrorOr<OwnPtr<CalculationNode>> Parser::parse_a_calculation(Vector<ComponentVal
|
||||||
// NOTE: All function tokens at this point should be math functions.
|
// NOTE: All function tokens at this point should be math functions.
|
||||||
else if (component_value.is_function()) {
|
else if (component_value.is_function()) {
|
||||||
auto& function = component_value.function();
|
auto& function = component_value.function();
|
||||||
if (function.name().equals_ignoring_ascii_case("calc"sv)) {
|
auto leaf_calculation = TRY(parse_a_calc_function_node(function));
|
||||||
auto leaf_calculation = TRY(parse_a_calculation(function.values()));
|
if (!leaf_calculation) {
|
||||||
if (!leaf_calculation) {
|
|
||||||
parsing_failed_for_child_node = true;
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
node = leaf_calculation.release_nonnull();
|
|
||||||
return {};
|
|
||||||
} else {
|
|
||||||
// FIXME: Parse more math functions once we have them.
|
|
||||||
parsing_failed_for_child_node = true;
|
parsing_failed_for_child_node = true;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
node = leaf_calculation.release_nonnull();
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: If we get here, then we have an UnparsedCalculationNode that didn't get replaced with something else.
|
// NOTE: If we get here, then we have an UnparsedCalculationNode that didn't get replaced with something else.
|
||||||
|
|
|
@ -289,6 +289,7 @@ private:
|
||||||
ErrorOr<RefPtr<StyleValue>> parse_builtin_value(ComponentValue const&);
|
ErrorOr<RefPtr<StyleValue>> parse_builtin_value(ComponentValue const&);
|
||||||
ErrorOr<RefPtr<StyleValue>> parse_dynamic_value(ComponentValue const&);
|
ErrorOr<RefPtr<StyleValue>> parse_dynamic_value(ComponentValue const&);
|
||||||
ErrorOr<RefPtr<CalculatedStyleValue>> parse_calculated_value(Vector<ComponentValue> const&);
|
ErrorOr<RefPtr<CalculatedStyleValue>> parse_calculated_value(Vector<ComponentValue> const&);
|
||||||
|
ErrorOr<OwnPtr<CalculationNode>> parse_a_calc_function_node(Function const&);
|
||||||
ErrorOr<RefPtr<StyleValue>> parse_dimension_value(ComponentValue const&);
|
ErrorOr<RefPtr<StyleValue>> parse_dimension_value(ComponentValue const&);
|
||||||
ErrorOr<RefPtr<StyleValue>> parse_integer_value(TokenStream<ComponentValue>&);
|
ErrorOr<RefPtr<StyleValue>> parse_integer_value(TokenStream<ComponentValue>&);
|
||||||
ErrorOr<RefPtr<StyleValue>> parse_number_value(TokenStream<ComponentValue>&);
|
ErrorOr<RefPtr<StyleValue>> parse_number_value(TokenStream<ComponentValue>&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue