Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.0

0.6.0 / src / web / svg / attribute_parser_2.lucb

#==============================================================================================
#
#   attribute_parser_2 - SVG::AttributeParser: numbers, keywords, transforms and viewBox
#
#   DESCRIPTION:
#       Port of LibWeb/SVG/AttributeParser.cpp (lines 304-833): lengths, coordinates,
#       integers and their sequences, elliptical arc arguments, whitespace, numbers, flags and
#       signs; preserveAspectRatio, the units and spreadMethod keywords, tableValues; the
#       transform list grammar (https://drafts.csswg.org/css-transforms/#svg-syntax); viewBox;
#       and the match_* lookahead predicates.
#
#       parse_transform's lambdas are functions over the parser: consume_whitespace,
#       consume_comma_whitespace, parse_optional_number and try_parse_number keep their names;
#       parse_function's six bodies are one function over the transform's name
#       (SvgAttributeParserTransformFunction).
#
#==============================================================================================

# mark: Numbers and sequences ===================================================================

## Ported from Libraries/LibWeb/SVG/AttributeParser.cpp:306 Web::SVG::AttributeParser::parse_length.
func svg_attribute_parser_parse_length(this: SvgAttributeParser*) -> f32!:
    # https://www.w3.org/TR/SVG11/types.html#DataTypeLength
    return try svg_attribute_parser_parse_number(this)

## Ported from Libraries/LibWeb/SVG/AttributeParser.cpp:312 Web::SVG::AttributeParser::parse_coordinate.
func svg_attribute_parser_parse_coordinate(this: SvgAttributeParser*) -> f32!:
    # https://www.w3.org/TR/SVG11/types.html#DataTypeCoordinate
    # coordinate ::= length
    return try svg_attribute_parser_parse_length(this)

## Ported from Libraries/LibWeb/SVG/AttributeParser.cpp:320 Web::SVG::AttributeParser::parse_integer.
# https://www.w3.org/TR/SVG11/types.html#DataTypeInteger
func svg_attribute_parser_parse_integer(this: SvgAttributeParser*) -> i32!:
    if not svg_attribute_parser_match_integer(this):
        error(ak.ak_error, "Expected integer")

    let parse_result = ak.parse_first_number_string_view_i32(ak.generic_lexer_remaining(&this.m_lexer), ak.TrimWhitespace.no) else error(ak.ak_error, "Integer out of range")

    ak.generic_lexer_ignore(&this.m_lexer, parse_result.characters_parsed)
    return parse_result.value

## Ported from Libraries/LibWeb/SVG/AttributeParser.cpp:333 Web::SVG::AttributeParser::parse_coordinate_pair.
func svg_attribute_parser_parse_coordinate_pair(this: SvgAttributeParser*) -> ak.Vector[f32]!:
    var coordinates = ak.Vector[f32]()
    ak.vector_append_t(&coordinates, try svg_attribute_parser_parse_coordinate(this))
    if svg_attribute_parser_match_comma_whitespace(this):
        svg_attribute_parser_parse_comma_whitespace(this)
    ak.vector_append_t(&coordinates, try svg_attribute_parser_parse_coordinate(this))
    return coordinates

## Ported from Libraries/LibWeb/SVG/AttributeParser.cpp:343 Web::SVG::AttributeParser::parse_coordinate_sequence.
func svg_attribute_parser_parse_coordinate_sequence(this: SvgAttributeParser*) -> ak.Vector[f32]!:
    var sequence = ak.Vector[f32]()
    var is_first = true
    while true:
        let coordinate = svg_attribute_parser_parse_coordinate(this) catch:
            if is_first:
                error(ak.ak_error, "Expected coordinate sequence")
            # donor quirk: C++ goes on to release_value() of the error, which VERIFY-fails.
            trap("VERIFY: release_value() of an error (AttributeParser::parse_coordinate_sequence)")
        is_first = false
        ak.vector_append_t(&sequence, coordinate)
        if svg_attribute_parser_match_comma_whitespace(this):
            svg_attribute_parser_parse_comma_whitespace(this)
        if not svg_attribute_parser_match_comma_whitespace(this) and not svg_attribute_parser_match_coordinate(this):
            break
    return sequence

## Ported from Libraries/LibWeb/SVG/AttributeParser.cpp:363 Web::SVG::AttributeParser::parse_coordinate_pair_sequence.
func svg_attribute_parser_parse_coordinate_pair_sequence(this: SvgAttributeParser*) -> ak.Vector[ak.Vector[f32]]!:
    var sequence = ak.Vector[ak.Vector[f32]]()
    var is_first = true
    while true:
        let coordinate_pair = svg_attribute_parser_parse_coordinate_pair(this) catch:
            if is_first:
                error(ak.ak_error, "Expected coordinate pair sequence")
            break
        is_first = false
        ak.vector_append_t(&sequence, coordinate_pair)
        if svg_attribute_parser_match_comma_whitespace(this):
            svg_attribute_parser_parse_comma_whitespace(this)
        if not svg_attribute_parser_match_comma_whitespace(this) and not svg_attribute_parser_match_coordinate(this):
            break
    return sequence

## Ported from Libraries/LibWeb/SVG/AttributeParser.cpp:384 Web::SVG::AttributeParser::parse_coordinate_pair_double.
func svg_attribute_parser_parse_coordinate_pair_double(this: SvgAttributeParser*) -> ak.Vector[f32]!:
    var coordinates = ak.Vector[f32]()
    var first = try svg_attribute_parser_parse_coordinate_pair(this)
    ak.vector_extend(&coordinates, &first)
    if svg_attribute_parser_match_comma_whitespace(this):
        svg_attribute_parser_parse_comma_whitespace(this)
    var second = try svg_attribute_parser_parse_coordinate_pair(this)
    ak.vector_extend(&coordinates, &second)
    return coordinates

## Ported from Libraries/LibWeb/SVG/AttributeParser.cpp:394 Web::SVG::AttributeParser::parse_coordinate_pair_triplet.
func svg_attribute_parser_parse_coordinate_pair_triplet(this: SvgAttributeParser*) -> ak.Vector[f32]!:
    var coordinates = ak.Vector[f32]()
    var first = try svg_attribute_parser_parse_coordinate_pair(this)
    ak.vector_extend(&coordinates, &first)
    if svg_attribute_parser_match_comma_whitespace(this):
        svg_attribute_parser_parse_comma_whitespace(this)
    var second = try svg_attribute_parser_parse_coordinate_pair(this)
    ak.vector_extend(&coordinates, &second)
    if svg_attribute_parser_match_comma_whitespace(this):
        svg_attribute_parser_parse_comma_whitespace(this)
    var third = try svg_attribute_parser_parse_coordinate_pair(this)
    ak.vector_extend(&coordinates, &third)
    return coordinates

## Ported from Libraries/LibWeb/SVG/AttributeParser.cpp:407 Web::SVG::AttributeParser::parse_elliptical_arc_argument.
func svg_attribute_parser_parse_elliptical_arc_argument(this: SvgAttributeParser*) -> ak.Vector[f32]!:
    var numbers = ak.Vector[f32]()
    ak.vector_append_t(&numbers, try svg_attribute_parser_parse_number(this))
    if svg_attribute_parser_match_comma_whitespace(this):
        svg_attribute_parser_parse_comma_whitespace(this)
    ak.vector_append_t(&numbers, try svg_attribute_parser_parse_number(this))
    if svg_attribute_parser_match_comma_whitespace(this):
        svg_attribute_parser_parse_comma_whitespace(this)
    ak.vector_append_t(&numbers, try svg_attribute_parser_parse_number(this))
    if svg_attribute_parser_match_comma_whitespace(this):
        svg_attribute_parser_parse_comma_whitespace(this)
    ak.vector_append_t(&numbers, try svg_attribute_parser_parse_flag(this))
    if svg_attribute_parser_match_comma_whitespace(this):
        svg_attribute_parser_parse_comma_whitespace(this)
    ak.vector_append_t(&numbers, try svg_attribute_parser_parse_flag(this))
    if svg_attribute_parser_match_comma_whitespace(this):
        svg_attribute_parser_parse_comma_whitespace(this)
    var pair = try svg_attribute_parser_parse_coordinate_pair(this)
    ak.vector_extend(&numbers, &pair)

    return numbers

## Ported from Libraries/LibWeb/SVG/AttributeParser.cpp:430 Web::SVG::AttributeParser::parse_whitespace.
func svg_attribute_parser_parse_whitespace(this: SvgAttributeParser*, must_match_once: bool = false):
    var matched = false
    while not svg_attribute_parser_done(this) and svg_attribute_parser_match_whitespace(this):
        _ = svg_attribute_parser_consume(this)
        matched = true

    assert(not must_match_once or matched)

## Ported from Libraries/LibWeb/SVG/AttributeParser.cpp:441 Web::SVG::AttributeParser::parse_comma_whitespace.
func svg_attribute_parser_parse_comma_whitespace(this: SvgAttributeParser*):
    if svg_attribute_parser_match(this, ','):
        _ = svg_attribute_parser_consume(this)
        svg_attribute_parser_parse_whitespace(this)
    else:
        svg_attribute_parser_parse_whitespace(this, true)
        if svg_attribute_parser_match(this, ','):
            _ = svg_attribute_parser_consume(this)
        svg_attribute_parser_parse_whitespace(this)

## Ported from Libraries/LibWeb/SVG/AttributeParser.cpp:455 Web::SVG::AttributeParser::parse_number.
# https://www.w3.org/TR/SVG11/types.html#DataTypeNumber
func svg_attribute_parser_parse_number(this: SvgAttributeParser*) -> f32!:
    let sign = svg_attribute_parser_parse_sign(this)
    return (f32)sign * try svg_attribute_parser_parse_nonnegative_number(this)

## Ported from Libraries/LibWeb/SVG/AttributeParser.cpp:462 Web::SVG::AttributeParser::parse_nonnegative_number.
# https://www.w3.org/TR/SVG11/paths.html#PathDataBNF
func svg_attribute_parser_parse_nonnegative_number(this: SvgAttributeParser*) -> f32!:
    # NOTE: The grammar is almost a floating point except we cannot have a sign
    #       at the start. That condition should have been checked by the caller.
    if svg_attribute_parser_match(this, '+') or svg_attribute_parser_match(this, '-') or not svg_attribute_parser_match_number(this):
        error(ak.ak_error, "Expected number")

    let parse_result = ak.parse_first_number_string_view_f32(ak.generic_lexer_remaining(&this.m_lexer), ak.TrimWhitespace.no) else trap("VERIFY: parse_result.has_value()")

    ak.generic_lexer_ignore(&this.m_lexer, parse_result.characters_parsed)
    return parse_result.value

## Ported from Libraries/LibWeb/SVG/AttributeParser.cpp:476 Web::SVG::AttributeParser::parse_flag.
func svg_attribute_parser_parse_flag(this: SvgAttributeParser*) -> f32!:
    if not svg_attribute_parser_match(this, '0') and not svg_attribute_parser_match(this, '1'):
        error(ak.ak_error, "Expected flag")
    return f32(svg_attribute_parser_consume(this) - '0')

## Ported from Libraries/LibWeb/SVG/AttributeParser.cpp:483 Web::SVG::AttributeParser::parse_sign.
# -1 if negative, +1 otherwise
func svg_attribute_parser_parse_sign(this: SvgAttributeParser*) -> i32:
    if svg_attribute_parser_match(this, '-'):
        _ = svg_attribute_parser_consume(this)
        return -1
    if svg_attribute_parser_match(this, '+'):
        _ = svg_attribute_parser_consume(this)
    return 1

## Ported from Libraries/LibWeb/SVG/AttributeParser.cpp:494 Web::SVG::whitespace (static).
func svg_whitespace(c_: u8) -> bool:
    # wsp:
    # Either a U+000A LINE FEED, U+000D CARRIAGE RETURN, U+0009 CHARACTER TABULATION, or U+0020 SPACE.
    return c_ == '\n' or c_ == '\r' or c_ == '\t' or c_ == 0x0c or c_ == ' '

## The `whitespace` function as a GenericLexer predicate (ignore_while, consume_until).
struct SvgWhitespacePredicate: ak.CharPredicate:
    var unused: u8

    func matches(ch: u8) -> bool:
        return svg_whitespace(ch)

# mark: Keywords ================================================================================

## Ported from Libraries/LibWeb/SVG/AttributeParser.cpp:502 Web::SVG::AttributeParser::parse_preserve_aspect_ratio.
# https://svgwg.org/svg2-draft/coords.html#PreserveAspectRatioAttribute
pub func svg_attribute_parser_parse_preserve_aspect_ratio(input: ak.StringView) -> SvgPreserveAspectRatio?:
    let whitespace = SvgWhitespacePredicate(unused = 0)
    # <align> <meetOrSlice>?
    var lexer = ak.generic_lexer_new(input)
    ak.generic_lexer_ignore_while(&lexer, &whitespace)
    let align_string = ak.generic_lexer_consume_until_tt_predicate(&lexer, &whitespace)
    if ak.string_view_is_empty(&align_string):
        return none
    ak.generic_lexer_ignore_while(&lexer, &whitespace)
    let meet_or_slice_string = ak.generic_lexer_consume_until_tt_predicate(&lexer, &whitespace)

    # <align> =
    #     none
    #     | xMinYMin | xMidYMin | xMaxYMin
    #     | xMinYMid | xMidYMid | xMaxYMid
    #     | xMinYMax | xMidYMax | xMaxYMax
    let align = svg_preserve_aspect_ratio_align_from_string(align_string) else return none

    # <meetOrSlice> = meet | slice
    var meet_or_slice: SvgPreserveAspectRatioMeetOrSlice? = none
    if ak.string_view_is_empty(&meet_or_slice_string) or ak.string_view_equals(&meet_or_slice_string, "meet"):
        meet_or_slice = SvgPreserveAspectRatioMeetOrSlice.meet
    elif ak.string_view_equals(&meet_or_slice_string, "slice"):
        meet_or_slice = SvgPreserveAspectRatioMeetOrSlice.slice

    let used_meet_or_slice = meet_or_slice else return none

    return SvgPreserveAspectRatio(align = align, meet_or_slice = used_meet_or_slice)

## parse_preserve_aspect_ratio's `align` lambda: the <align> keyword, case-sensitively.
func svg_preserve_aspect_ratio_align_from_string(align_string: ak.StringView) -> SvgPreserveAspectRatioAlign?:
    if ak.string_view_equals(&align_string, "none"):
        return SvgPreserveAspectRatioAlign.none_
    if ak.string_view_equals(&align_string, "xMinYMin"):
        return SvgPreserveAspectRatioAlign.x_min_y_min
    if ak.string_view_equals(&align_string, "xMidYMin"):
        return SvgPreserveAspectRatioAlign.x_mid_y_min
    if ak.string_view_equals(&align_string, "xMaxYMin"):
        return SvgPreserveAspectRatioAlign.x_max_y_min
    if ak.string_view_equals(&align_string, "xMinYMid"):
        return SvgPreserveAspectRatioAlign.x_min_y_mid
    if ak.string_view_equals(&align_string, "xMidYMid"):
        return SvgPreserveAspectRatioAlign.x_mid_y_mid
    if ak.string_view_equals(&align_string, "xMaxYMid"):
        return SvgPreserveAspectRatioAlign.x_max_y_mid
    if ak.string_view_equals(&align_string, "xMinYMax"):
        return SvgPreserveAspectRatioAlign.x_min_y_max
    if ak.string_view_equals(&align_string, "xMidYMax"):
        return SvgPreserveAspectRatioAlign.x_mid_y_max
    if ak.string_view_equals(&align_string, "xMaxYMax"):
        return SvgPreserveAspectRatioAlign.x_max_y_max
    return none

## Ported from Libraries/LibWeb/SVG/AttributeParser.cpp:563 Web::SVG::AttributeParser::parse_units.
# https://svgwg.org/svg2-draft/pservers.html#LinearGradientElementGradientUnitsAttribute
# https://drafts.fxtf.org/css-masking/#element-attrdef-mask-maskunits
# https://drafts.fxtf.org/css-masking/#element-attrdef-mask-maskcontentunits
pub func svg_attribute_parser_parse_units(input: ak.StringView) -> SvgUnits?:
    let whitespace = SvgWhitespacePredicate(unused = 0)
    var lexer = ak.generic_lexer_new(input)
    ak.generic_lexer_ignore_while(&lexer, &whitespace)
    let gradient_units_string = ak.generic_lexer_consume_until_tt_predicate(&lexer, &whitespace)
    if ak.string_view_equals(&gradient_units_string, "userSpaceOnUse"):
        return SvgUnits.user_space_on_use
    if ak.string_view_equals(&gradient_units_string, "objectBoundingBox"):
        return SvgUnits.object_bounding_box
    return none

## Ported from Libraries/LibWeb/SVG/AttributeParser.cpp:576 Web::SVG::AttributeParser::parse_spread_method.
# https://svgwg.org/svg2-draft/pservers.html#RadialGradientElementSpreadMethodAttribute
pub func svg_attribute_parser_parse_spread_method(input: ak.StringView) -> SvgSpreadMethod?:
    let whitespace = SvgWhitespacePredicate(unused = 0)
    var lexer = ak.generic_lexer_new(input)
    ak.generic_lexer_ignore_while(&lexer, &whitespace)
    let spread_method_string = ak.generic_lexer_consume_until_tt_predicate(&lexer, &whitespace)
    if ak.string_view_equals(&spread_method_string, "pad"):
        return SvgSpreadMethod.pad_
    if ak.string_view_equals(&spread_method_string, "repeat"):
        return SvgSpreadMethod.repeat
    if ak.string_view_equals(&spread_method_string, "reflect"):
        return SvgSpreadMethod.reflect
    return none

## Ported from Libraries/LibWeb/SVG/AttributeParser.cpp:591 Web::SVG::AttributeParser::parse_table_values.
# https://drafts.fxtf.org/filter-effects-1/#element-attrdef-fecomponenttransfer-tablevalues
pub func svg_attribute_parser_parse_table_values(input: ak.StringView) -> ak.Vector[f32]:
    var table_values = ak.Vector[f32]()

    var parser: SvgAttributeParser = ---
    svg_attribute_parser_construct(&parser, input)
    while not svg_attribute_parser_done(&parser):
        svg_attribute_parser_parse_whitespace(&parser)
        let table_value = svg_attribute_parser_parse_nonnegative_number(&parser) else return ak.Vector[f32]()

        ak.vector_append_t(&table_values, table_value)
        svg_attribute_parser_parse_whitespace(&parser)
        if svg_attribute_parser_match(&parser, ','):
            _ = svg_attribute_parser_consume(&parser)

    return table_values

# mark: Transforms ==============================================================================

## The functions of the transform grammar, one per `parse_function` body of parse_transform.
enum SvgAttributeParserTransformFunction:
    translate
    scale
    rotate
    skew_x
    skew_y
    matrix

## parse_transform's consume_whitespace lambda.
func svg_attribute_parser_consume_whitespace(this: SvgAttributeParser*):
    let whitespace = SvgWhitespacePredicate(unused = 0)
    ak.generic_lexer_ignore_while(&this.m_lexer, &whitespace)

## parse_transform's consume_comma_whitespace lambda.
func svg_attribute_parser_consume_comma_whitespace(this: SvgAttributeParser*):
    svg_attribute_parser_consume_whitespace(this)
    _ = ak.generic_lexer_consume_specific_t_char_type(&this.m_lexer, ',')
    svg_attribute_parser_consume_whitespace(this)

## parse_transform's parse_optional_number lambda.
# FIXME: This parsing is quite lenient, so will accept (with default values) some transforms that should be rejected.
func svg_attribute_parser_parse_optional_number(this: SvgAttributeParser*, default_value: f32 = 0.0) -> f32:
    svg_attribute_parser_consume_comma_whitespace(this)
    let number = svg_attribute_parser_parse_number(this) else return default_value
    return number

## parse_transform's try_parse_number lambda.
func svg_attribute_parser_try_parse_number(this: SvgAttributeParser*) -> f32?:
    let number = svg_attribute_parser_parse_number(this) else return none
    return number

## The bodies of parse_transform's parse_function calls: the arguments of one transform function.
func svg_attribute_parser_parse_transform_body(this: SvgAttributeParser*, function: SvgAttributeParserTransformFunction) -> SvgTransformOperation?:
    match function:
        .translate:
            let x = svg_attribute_parser_try_parse_number(this) else return none
            let y = svg_attribute_parser_parse_optional_number(this)
            return .svg_transform_translate(value = SvgTransformTranslate(x = x, y = y))
        .scale:
            let x = svg_attribute_parser_try_parse_number(this) else return none
            let y = svg_attribute_parser_parse_optional_number(this, x)
            return .svg_transform_scale(value = SvgTransformScale(x = x, y = y))
        .rotate:
            let a = svg_attribute_parser_try_parse_number(this) else return none
            let x = svg_attribute_parser_parse_optional_number(this)
            let y = svg_attribute_parser_parse_optional_number(this)
            return .svg_transform_rotate(value = SvgTransformRotate(a = a, x = x, y = y))
        .skew_x:
            let a = svg_attribute_parser_try_parse_number(this) else return none
            return .svg_transform_skew_x(value = SvgTransformSkewX(a = a))
        .skew_y:
            let a = svg_attribute_parser_try_parse_number(this) else return none
            return .svg_transform_skew_y(value = SvgTransformSkewY(a = a))
        .matrix:
            let a = svg_attribute_parser_try_parse_number(this) else return none
            svg_attribute_parser_consume_comma_whitespace(this)
            let b = svg_attribute_parser_try_parse_number(this) else return none
            svg_attribute_parser_consume_comma_whitespace(this)
            let c_ = svg_attribute_parser_try_parse_number(this) else return none
            svg_attribute_parser_consume_comma_whitespace(this)
            let d = svg_attribute_parser_try_parse_number(this) else return none
            svg_attribute_parser_consume_comma_whitespace(this)
            let e = svg_attribute_parser_try_parse_number(this) else return none
            svg_attribute_parser_consume_comma_whitespace(this)
            let f = svg_attribute_parser_try_parse_number(this) else return none
            return .svg_transform_matrix(value = SvgTransformMatrix(a = a, b = b, c = c_, d = d, e = e, f = f))

## parse_transform's parse_function lambda: `(`, the function's arguments, `)`.
func svg_attribute_parser_parse_function(this: SvgAttributeParser*, function: SvgAttributeParserTransformFunction) -> SvgTransform?:
    svg_attribute_parser_consume_whitespace(this)
    if not ak.generic_lexer_consume_specific_t_char_type(&this.m_lexer, '('):
        return none
    svg_attribute_parser_consume_whitespace(this)
    let operation = svg_attribute_parser_parse_transform_body(this, function) else return none
    let transform = SvgTransform(operation = operation)
    svg_attribute_parser_consume_whitespace(this)
    if ak.generic_lexer_consume_specific_t_char_type(&this.m_lexer, ')'):
        return transform
    return none

## Ported from Libraries/LibWeb/SVG/AttributeParser.cpp:612 Web::SVG::AttributeParser::parse_transform.
# https://drafts.csswg.org/css-transforms/#svg-syntax
func svg_attribute_parser_parse_transform(this: SvgAttributeParser*) -> ak.Vector[SvgTransform]?:
    # NOTE: This looks very similar to the CSS transform but the syntax is not compatible.
    var transform_list = ak.Vector[SvgTransform]()
    svg_attribute_parser_consume_whitespace(this)
    while not svg_attribute_parser_done(this):
        var maybe_transform: SvgTransform? = none
        if ak.generic_lexer_consume_specific_string_view(&this.m_lexer, ak.sv("translate")):
            maybe_transform = svg_attribute_parser_parse_function(this, SvgAttributeParserTransformFunction.translate)
        elif ak.generic_lexer_consume_specific_string_view(&this.m_lexer, ak.sv("scale")):
            maybe_transform = svg_attribute_parser_parse_function(this, SvgAttributeParserTransformFunction.scale)
        elif ak.generic_lexer_consume_specific_string_view(&this.m_lexer, ak.sv("rotate")):
            maybe_transform = svg_attribute_parser_parse_function(this, SvgAttributeParserTransformFunction.rotate)
        elif ak.generic_lexer_consume_specific_string_view(&this.m_lexer, ak.sv("skewX")):
            maybe_transform = svg_attribute_parser_parse_function(this, SvgAttributeParserTransformFunction.skew_x)
        elif ak.generic_lexer_consume_specific_string_view(&this.m_lexer, ak.sv("skewY")):
            maybe_transform = svg_attribute_parser_parse_function(this, SvgAttributeParserTransformFunction.skew_y)
        elif ak.generic_lexer_consume_specific_string_view(&this.m_lexer, ak.sv("matrix")):
            maybe_transform = svg_attribute_parser_parse_function(this, SvgAttributeParserTransformFunction.matrix)
        if let transform = maybe_transform:
            ak.vector_append_t(&transform_list, transform)
        else:
            return none
        svg_attribute_parser_consume_comma_whitespace(this)
    return transform_list

# mark: viewBox ==================================================================================

## Ported from Libraries/LibWeb/SVG/AttributeParser.cpp:753 Web::SVG::AttributeParser::parse_viewbox.
pub func svg_attribute_parser_parse_viewbox(input: ak.StringView) -> SvgViewBox?:
    var parser: SvgAttributeParser = ---
    svg_attribute_parser_construct(&parser, input)
    var viewbox = SvgViewBox()

    svg_attribute_parser_parse_whitespace(&parser)
    let min_x = svg_attribute_parser_parse_coordinate(&parser) else return none
    viewbox.min_x = f64(min_x)

    if not svg_attribute_parser_match_comma_whitespace(&parser):
        return none
    svg_attribute_parser_parse_comma_whitespace(&parser)
    let min_y = svg_attribute_parser_parse_coordinate(&parser) else return none
    viewbox.min_y = f64(min_y)

    if not svg_attribute_parser_match_comma_whitespace(&parser):
        return none
    svg_attribute_parser_parse_comma_whitespace(&parser)
    let width = svg_attribute_parser_parse_length(&parser) else return none
    viewbox.width = f64(width)

    if not svg_attribute_parser_match_comma_whitespace(&parser):
        return none
    svg_attribute_parser_parse_comma_whitespace(&parser)
    let height = svg_attribute_parser_parse_length(&parser) else return none
    viewbox.height = f64(height)

    svg_attribute_parser_parse_whitespace(&parser)
    if not svg_attribute_parser_done(&parser):
        return none

    return viewbox

# mark: Lookahead ===============================================================================

## Ported from Libraries/LibWeb/SVG/AttributeParser.cpp:795 Web::SVG::AttributeParser::match_whitespace.
func svg_attribute_parser_match_whitespace(this: const SvgAttributeParser*) -> bool:
    if svg_attribute_parser_done(this):
        return false
    let c_ = svg_attribute_parser_ch(this)
    return c_ == 0x9 or c_ == 0x20 or c_ == 0xa or c_ == 0xc or c_ == 0xd

## Ported from Libraries/LibWeb/SVG/AttributeParser.cpp:803 Web::SVG::AttributeParser::match_comma_whitespace.
func svg_attribute_parser_match_comma_whitespace(this: const SvgAttributeParser*) -> bool:
    return svg_attribute_parser_match_whitespace(this) or svg_attribute_parser_match(this, ',')

## Ported from Libraries/LibWeb/SVG/AttributeParser.cpp:808 Web::SVG::AttributeParser::match_coordinate.
func svg_attribute_parser_match_coordinate(this: const SvgAttributeParser*) -> bool:
    return svg_attribute_parser_match_length(this, SvgAttributeParserAllowDot.yes)

## Ported from Libraries/LibWeb/SVG/AttributeParser.cpp:813 Web::SVG::AttributeParser::match_number.
func svg_attribute_parser_match_number(this: const SvgAttributeParser*) -> bool:
    return svg_attribute_parser_match_length(this, SvgAttributeParserAllowDot.yes)

## Ported from Libraries/LibWeb/SVG/AttributeParser.cpp:818 Web::SVG::AttributeParser::match_integer.
func svg_attribute_parser_match_integer(this: const SvgAttributeParser*) -> bool:
    return svg_attribute_parser_match_length(this, SvgAttributeParserAllowDot.no)

## Ported from Libraries/LibWeb/SVG/AttributeParser.cpp:823 Web::SVG::AttributeParser::match_length.
func svg_attribute_parser_match_length(this: const SvgAttributeParser*, allow_dot: SvgAttributeParserAllowDot) -> bool:
    if svg_attribute_parser_done(this):
        return false

    var offset: usize = 0
    if svg_attribute_parser_ch(this) == '-' or svg_attribute_parser_ch(this) == '+':
        offset += 1

    if allow_dot == SvgAttributeParserAllowDot.yes and svg_attribute_parser_ch(this, offset) == '.':
        offset += 1

    return not svg_attribute_parser_done(this) and ak.is_ascii_digit(svg_attribute_parser_ch(this, offset))