str/src/vm/commands/lines.ts

31 lines
867 B
TypeScript
Raw Normal View History

import {Command, ParseContext, unwrapString} from "./command.js";
2025-11-12 03:37:32 +00:00
import {LexInput} from "../lexer.js";
import {StrVM} from "../vm.js";
import {Awaitable} from "../../util/types.js";
2025-11-12 03:37:32 +00:00
export type LinesData = {}
2025-11-12 03:37:32 +00:00
export class Lines extends Command<LinesData> {
attemptParse(context: ParseContext): LinesData {
return {}
2025-11-12 03:37:32 +00:00
}
getDisplayName(): string {
return 'lines'
}
isParseCandidate(token: LexInput): boolean {
return this.isKeyword(token, 'lines')
}
execute(vm: StrVM, data: LinesData): Awaitable<StrVM> {
return vm.tapInPlace(ctx =>
ctx.replaceSubject(sub => ({
term: 'destructured',
value: unwrapString(sub)
.split('\n')
.map((line, idx) => ({ prefix: idx ? '\n' : undefined, value: line })),
})))
}
2025-11-12 03:37:32 +00:00
}