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, } export class Line extends Command { async attemptParse(context: ParseContext): Promise { return { exec: await context.popExecutable(), } } getDisplayName(): string { return 'line' } isParseCandidate(token: LexInput): boolean { return this.isKeyword(token, 'line') } execute(vm: StrVM, data: LineData): Awaitable { // `line ` is equivalent to `lines` -> `each ` -> `join`, so just do that return vm.replaceContextFromChild(async child => { await (new Lines).execute(child) await (new Each).execute(child, { exec: data.exec }) await (new Join).execute(child, {}) }) } }