import { Hash } from "@siteimprove/alfa-hash" ; import { Parser } from "@siteimprove/alfa-parser" ; import { Predicate } from "@siteimprove/alfa-predicate" ; import { Slice } from "@siteimprove/alfa-slice" ; import { Token } from "../syntax/token" ; import { Value } from "../value" ; const { map } = Parser ; const { equals } = Predicate ; /**
 *  https public export class Keyword < T extends string = string > extends Value < "keyword" > { public static of < T extends string > ( value ) { return new Keyword ( value ) ; } private readonly _value : T ; private constructor ( value ) { super ( ) ; this . _value = value ; } public get type ( ) : "keyword" { return "keyword" ; } public get value ( ) : T { return this . _value ; } public equals ( value ) { return value instanceof Keyword && value . _value === this . _value ; } public hash ( hash ) { hash . writeString ( this . _value ) ; } public toJSON ( ) { return { type : "keyword" , value : this . _value , } ; } public toString ( ) { return this . _value ; } } public export namespace Keyword { export interface JSON < T extends string = string > extends Value . JSON < "keyword" > { value : T ; } export function isKeyword ( value ) { return value instanceof Keyword ; } export function parse < T extends string > ( ... keywords ) { return map ( Token . parseIdent ( ( ident ) => keywords . some ( equals ( ident . value . toLowerCase ( ) ) ) ) , ( ident ) => Keyword . of ( ident . value . toLowerCase ( ) ) as { [ K in T ] : Keyword < K > ; } [ T ] ) ; } }