Replace StringRange w/ an actual StrRVal + more command implementations
This commit is contained in:
@@ -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()
|
||||
})))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user