import { LineResults } from "../LineResults" ; import { CommandNames } from "../Names/CommandNames" ; import { Command } from "./Command" ; import { CommandMetadata } from "./Metadata/CommandMetadata" ; import { SingleParameter } from "./Metadata/Parameters/SingleParameter" ; /**
 * An in-place dictionary initialization pair.
 */ export class DictionaryPairCommand extends Command { /**
     * Metadata on the command.
     */ private static metadata : CommandMetadata = new CommandMetadata ( CommandNames . DictionaryPair ) . withDescription ( "An in-place dictionary initialization pair" ) . withParameters ( [ new SingleParameter ( "key" , "The pair key." , true ) , new SingleParameter ( "value" , "The pair value" , true ) , new SingleParameter ( "comma" , "Whether a comma is needed" , false ) , ] ) ; returns public getMetadata ( ) { return DictionaryPairCommand . metadata ; } param parameters returns public render ( parameters ) { let output = "" ; output += this . language . syntax . dictionaries . initializePairLeft ; output += this . renderKey ( parameters [ 1 ] ) ; output += this . language . syntax . dictionaries . initializePairMiddle ; output += parameters [ 2 ] ; output += this . language . syntax . dictionaries . initializePairRight ; if ( parameters . length === 4 ) { output += this . language . syntax . dictionaries . initializePairComma ; } return LineResults . newSingleLine ( output ) ; } param keyRaw returns todo private renderKey ( keyRaw ) { const firstCharacter = keyRaw [ 0 ] ; const lastCharacter = keyRaw [ keyRaw . length - 1 ] ; if ( firstCharacter === '"' && lastCharacter === '"' ) { return keyRaw ; } if ( firstCharacter === '"' ) { throw new Error ( "Dictionary pair keys that start with quotes must end with quotes" ) ; } if ( lastCharacter === '"' ) { throw new Error ( "Dictionary pair keys that end with quotes must start with quotes" ) ; } return keyRaw ; } }