Replace StringRange w/ an actual StrRVal + more command implementations

This commit is contained in:
2026-02-09 22:15:33 -06:00
parent 82eda43dad
commit feba84051a
29 changed files with 502 additions and 192 deletions

View File

@@ -1,6 +1,11 @@
import {Command, CommandData, ParseContext, StrLVal} from "./command.js";
import {Command, CommandData, ParseContext} from "./command.js";
import {Executable} from "../parse.js";
import {LexInput} from "../lexer.js";
import {StrVM} from "../vm.js";
import {Awaitable} from "../../util/types.js";
import {Lines} from "./lines.js";
import {Each} from "./each.js";
import {Join} from "./join.js";
export type LineData = {
exec: Executable<CommandData>,
@@ -20,4 +25,16 @@ export class Line extends Command<LineData> {
isParseCandidate(token: LexInput): boolean {
return this.isKeyword(token, 'line')
}
execute(vm: StrVM, data: LineData): Awaitable<StrVM> {
// `line <cmd>` is equivalent to `lines` -> `each <cmd>` -> `join`, so just do that
return vm.tapInPlace(ctx =>
ctx.replaceSubject(async sub =>
vm.runInChild(async (child, ctx) => {
await (new Lines).execute(child, {})
await (new Each).execute(child, { exec: data.exec })
await (new Join).execute(child, {})
return ctx.getSubject()
})))
}
}