[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 {Command, ParseContext, processPath, StrTerm, wrapString} from "./command.js";
|
2025-11-10 23:54:20 -06:00
|
|
|
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";
|
|
|
|
|
import {Awaitable} from "../../util/types.js";
|
|
|
|
|
import fs from "node:fs/promises";
|
2025-11-10 23:54:20 -06:00
|
|
|
|
|
|
|
|
export class InFile extends Command<{ path: StrTerm }> {
|
|
|
|
|
isParseCandidate(token: LexInput): boolean {
|
|
|
|
|
return this.isKeyword(token, 'infile')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
attemptParse(context: ParseContext): { path: StrTerm } {
|
|
|
|
|
return { path: context.popTerm() }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getDisplayName(): string {
|
|
|
|
|
return 'infile'
|
|
|
|
|
}
|
[WIP] Implement save, load, over, infile, outfile, on, lipsum, help + start implementing undo, redo, exit, edit
2026-02-22 10:10:38 -06:00
|
|
|
|
|
|
|
|
execute(vm: StrVM, data: { path: StrTerm }): Awaitable<StrVM> {
|
|
|
|
|
return vm.replaceContextMatchingTerm(ctx => ({
|
|
|
|
|
override: async () => {
|
|
|
|
|
const path = processPath(ctx.resolveString(data.path))
|
|
|
|
|
const content = await fs.readFile(path, 'utf8')
|
|
|
|
|
return wrapString(content)
|
|
|
|
|
}
|
|
|
|
|
}))
|
|
|
|
|
}
|
2025-11-10 23:54:20 -06:00
|
|
|
}
|