2025-11-12 03:37:32 +00:00
|
|
|
import {Command, ParseContext, StrTerm} from "./command.js";
|
|
|
|
|
import {LexInput} from "../lexer.js";
|
2026-02-10 00:09:47 +00:00
|
|
|
import {StrVM} from "../vm.js";
|
|
|
|
|
import {Awaitable} from "../../util/types.js";
|
2025-11-12 03:37:32 +00:00
|
|
|
|
|
|
|
|
export class Prefix extends Command<{ with: StrTerm }> {
|
|
|
|
|
attemptParse(context: ParseContext): { with: StrTerm } {
|
|
|
|
|
return {
|
|
|
|
|
with: context.popTerm(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getDisplayName(): string {
|
|
|
|
|
return 'prefix'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isParseCandidate(token: LexInput): boolean {
|
|
|
|
|
return this.isKeyword(token, 'prefix')
|
|
|
|
|
}
|
2026-02-10 00:09:47 +00:00
|
|
|
|
|
|
|
|
execute(vm: StrVM, data: { with: StrTerm }): Awaitable<StrVM> {
|
|
|
|
|
return vm.inPlace(ctx =>
|
|
|
|
|
ctx.replaceSubject(sub =>
|
|
|
|
|
sub.modify(s => `${ctx.resolveString(data.with)}${s}`)))
|
|
|
|
|
}
|
2025-11-12 03:37:32 +00:00
|
|
|
}
|