import { Equatable } from "@siteimprove/alfa-equatable" ; import { Serializable } from "@siteimprove/alfa-json" ; import { Parser } from "@siteimprove/alfa-parser" ; import { Err , Result } from "@siteimprove/alfa-result" ; import { Slice } from "@siteimprove/alfa-slice" ; import { Block } from "./block" ; import { Function } from "./function" ; import { Token } from "./token" ; /**
 *  https public export class Component implements Iterable < Token > , Equatable , Serializable { public static of ( value ) { return new Component ( Array . from ( value ) ) ; } private readonly _value : Array < Token > ; private constructor ( value ) { this . _value = value ; } public get value ( ) : Array < Token > { return this . _value ; } public * [ Symbol . iterator ] ( ) { yield * this . _value ; } public equals ( value ) { return ( value instanceof Component && value . _value . length === this . _value . length && value . _value . every ( ( token , i ) => token . equals ( this . _value [ i ] ) ) ) ; } public toJSON ( ) { return this . _value . map ( ( token ) => token . toJSON ( ) ) ; } public toString ( ) { return this . _value . join ( "" ) ; } } public export namespace Component { export type JSON = Array < Token . JSON > ; /**
     *  https export const consume = ( input ) => { if ( input . length === 0 ) { return Err . of ( "Unexpected end of file" ) ; } const next = input . array [ input . offset ] ; if ( Token . isOpenParenthesis ( next ) || Token . isOpenSquareBracket ( next ) || Token . isOpenCurlyBracket ( next ) ) { return Block . consume ( input ) . map ( ( [ input , value ] ) => [ input , Component . of ( value ) , ] ) ; } if ( Token . isFunction ( next ) ) { return Function . consume ( input ) . map ( ( [ input , value ] ) => [ input , Component . of ( value ) , ] ) ; } return Result . of ( [ input . slice ( 1 ) , Component . of ( [ next ] ) ] ) ; } ; /**
     *  https export const parse = ( input ) => { while ( Token . isWhitespace ( input . array [ input . offset ] ) ) { input = input . slice ( 1 ) ; } if ( input . length === 0 ) { return Err . of ( "Unexpected end of input" ) ; } const component = consume ( input ) ; while ( Token . isWhitespace ( input . array [ input . offset ] ) ) { input = input . slice ( 1 ) ; } if ( input . length !== 0 ) { return Err . of ( "Expected end of input" ) ; } return component ; } ; }