2025-11-11 22:09:26 -06:00
|
|
|
import {Command, CommandData, ParseContext, StrLVal} from "./command.js";
|
|
|
|
|
import {Executable} from "../parse.js";
|
|
|
|
|
import {LexInput} from "../lexer.js";
|
[WIP] Implement save, load, over, infile, outfile, on, lipsum, help + start implementing undo, redo, exit, edit
2026-02-22 10:10:38 -06:00
|
|
|
import {StrVM} from "../vm.js";
|
2025-11-11 22:09:26 -06:00
|
|
|
|
|
|
|
|
export type OverData = {
|
|
|
|
|
subject: StrLVal,
|
|
|
|
|
exec: Executable<CommandData>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class Over extends Command<OverData> {
|
|
|
|
|
async attemptParse(context: ParseContext): Promise<OverData> {
|
|
|
|
|
return {
|
|
|
|
|
subject: context.popLVal(),
|
|
|
|
|
exec: await context.popExecutable(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getDisplayName(): string {
|
|
|
|
|
return 'over'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isParseCandidate(token: LexInput): boolean {
|
|
|
|
|
return this.isKeyword(token, 'over')
|
|
|
|
|
}
|
[WIP] Implement save, load, over, infile, outfile, on, lipsum, help + start implementing undo, redo, exit, edit
2026-02-22 10:10:38 -06:00
|
|
|
|
|
|
|
|
async execute(vm: StrVM, data: OverData): Promise<StrVM> {
|
|
|
|
|
return vm.tapInPlace(async parentCtx => {
|
|
|
|
|
const oldValue = parentCtx.resolveRequired(data.subject)
|
|
|
|
|
const newValue = await vm.runInChild(async (child, childCtx) => {
|
|
|
|
|
await childCtx.replaceSubject(() => oldValue)
|
|
|
|
|
await data.exec.command.execute(child, data.exec.data)
|
|
|
|
|
return childCtx.getSubject()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
parentCtx.inScope(scope =>
|
|
|
|
|
scope.setOrShadowValue(data.subject, newValue))
|
|
|
|
|
})
|
|
|
|
|
}
|
2025-11-11 22:09:26 -06:00
|
|
|
}
|