2026-02-09 22:15:33 -06:00
|
|
|
import {Command, CommandData, ParseContext} from "./command.js";
|
2025-11-11 22:09:26 -06:00
|
|
|
import {Executable} from "../parse.js";
|
|
|
|
|
import {LexInput} from "../lexer.js";
|
2026-02-09 22:15:33 -06:00
|
|
|
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";
|
2025-11-11 22:09:26 -06:00
|
|
|
|
|
|
|
|
export type LineData = {
|
|
|
|
|
exec: Executable<CommandData>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class Line extends Command<LineData> {
|
|
|
|
|
async attemptParse(context: ParseContext): Promise<LineData> {
|
|
|
|
|
return {
|
|
|
|
|
exec: await context.popExecutable(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getDisplayName(): string {
|
|
|
|
|
return 'line'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isParseCandidate(token: LexInput): boolean {
|
|
|
|
|
return this.isKeyword(token, 'line')
|
|
|
|
|
}
|
2026-02-09 22:15:33 -06:00
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
})))
|
|
|
|
|
}
|
2025-11-11 22:09:26 -06:00
|
|
|
}
|