26 lines
733 B
TypeScript
26 lines
733 B
TypeScript
import {Command, ParseContext, StrTerm} from "./command.js";
|
|
import {LexInput} from "../lexer.js";
|
|
import {StrVM} from "../vm.js";
|
|
import {Awaitable} from "../../util/types.js";
|
|
|
|
export class Suffix extends Command<{ with: StrTerm }> {
|
|
attemptParse(context: ParseContext): { with: StrTerm } {
|
|
return {
|
|
with: context.popTerm(),
|
|
}
|
|
}
|
|
|
|
getDisplayName(): string {
|
|
return 'suffix'
|
|
}
|
|
|
|
isParseCandidate(token: LexInput): boolean {
|
|
return this.isKeyword(token, 'suffix')
|
|
}
|
|
|
|
execute(vm: StrVM, data: { with: StrTerm }): Awaitable<StrVM> {
|
|
return vm.tapInPlace(ctx =>
|
|
ctx.replaceSubjectAsString(sub => `${sub}${ctx.resolveString(data.with)}`))
|
|
}
|
|
}
|