import { CommandNode } from "../../../../Tokenization/Nodes/CommandNode" ; import { IBudgieNode } from "../../../../Tokenization/Nodes/IBudgieNode" ; import { TextNode } from "../../../../Tokenization/Nodes/TextNode" ; import { IParameter } from "./Parameter" ; /**
 * A parameter that's only satisfied by particular string literal(s).
 */ export class KeywordParameter implements IParameter { /**
     * A plain-text description of this parameter.
     */ public description : string ; /**
     * Allowed matching string literals.
     */ public literals : Set < string > ; /**
     * Whether this must be provided.
     */ public required : boolean ; param literal param description param required public constructor ( literals , description , required ) { this . description = description ; this . literals = new Set ( literals ) ; this . required = required ; } returns public isRequired ( ) { return this . required ; } param node param inputPosition param requirements param requirementPosition returns public validate ( node , inputPosition , requirements , requirementPosition ) { const inputArg = node . args [ inputPosition ] ; if ( ! ( inputArg instanceof TextNode ) ) { if ( this . required ) { throw new Error ( `${ node . command }: Parameter must be a text keyword.` ) ; } return inputPosition ; } if ( this . literals . has ( inputArg . text ) ) { return inputPosition + 1 ; } if ( this . required ) { throw new Error ( `${ node . command }: Missing required parameter: must be one of: '${ Array . from ( this . literals ) . join ( "', '" ) }'` ) ; } return inputPosition ; } }