import { Equatable } from "@siteimprove/alfa-equatable" ; import { Serializable } from "@siteimprove/alfa-json" ; import { Parser } from "@siteimprove/alfa-parser" ; import { Slice } from "@siteimprove/alfa-slice" ; import { Result } from "@siteimprove/alfa-result" ; import * as json from "@siteimprove/alfa-json" ; import { Component } from "./component" ; import { Token } from "./token" ; /**
 *  https public export class Block implements Iterable < Token > , Equatable , Serializable { public static of ( token , value ) { return new Block ( token , Array . from ( value ) ) ; } private readonly _token : Block . Open ; private readonly _value : Array < Token > ; private constructor ( token , value ) { this . _token = token ; this . _value = value ; } public get token ( ) : Block . Open { return this . _token ; } public get value ( ) : Array < Token > { return this . _value ; } public * [ Symbol . iterator ] ( ) { yield this . _token ; yield * this . _value ; yield this . _token . mirror ; } public equals ( value ) { return ( value instanceof Block && value . _token . equals ( this . _token ) && value . _value . length === this . _value . length && value . _value . every ( ( token , i ) => token . equals ( this . _value [ i ] ) ) ) ; } public toJSON ( ) { return { token : this . _token . toJSON ( ) , value : this . _value . map ( ( token ) => token . toJSON ( ) ) , } ; } public toString ( ) { return ( this . _token . toString ( ) + this . _value . join ( "" ) + this . _token . mirror . toString ( ) ) ; } } public export namespace Block { export interface JSON { [ key ] : json . JSON ; token : Token . JSON ; value : Array < Token . JSON > ; } /**
     * The tokens that are allowed to open a block.
     */ export type Open = Token . OpenParenthesis | Token . OpenSquareBracket | Token . OpenCurlyBracket ; /**
     * The tokens that are allowed to close a block.
     */ export type Close = Token . CloseParenthesis | Token . CloseSquareBracket | Token . CloseCurlyBracket ; /**
     *  https export const consume = ( input ) => { const token = input . array [ input . offset ] as Open ; const value = [ ] ; input = input . slice ( 1 ) ; while ( input . length > 0 ) { const next = input . array [ input . offset ] ; if ( next . type === token . mirror . type ) { input = input . slice ( 1 ) ; break ; } const [ remainder , component ] = Component . consume ( input ) . get ( ) ; input = remainder ; value . push ( ... component ) ; } return Result . of ( [ input , Block . of ( token , value ) ] ) ; } ; }