import {Command, ParseContext, StrTerm} from "./command.js"; import {LexInput} from "../lexer.js"; import {StrVM} from "../vm.js"; export type TimesData = { val: StrTerm, } export class Times extends Command { async attemptParse(context: ParseContext): Promise { return { val: await context.popTerm(), } } getDisplayName(): string { return 'times' } isParseCandidate(token: LexInput): boolean { return this.isKeyword(token, 'times') } async execute(vm: StrVM, data: TimesData): Promise { return vm.replaceContextMatchingTerm(ctx => ({ int: sub => sub * ctx.resolveInt(data.val), })) } }