str/src/vm/commands/lines.ts

31 lines
816 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 class Lines extends Command<{}> {
attemptParse(context: ParseContext): {} {
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): Awaitable<StrVM> {
return vm.replaceContextMatchingTerm({
destructure: sub => {
return sub.split('\n')
.map((line, idx) => ({
prefix: idx ? '\n' : undefined,
value: line,
}))
},
})
}
2025-11-12 03:37:32 +00:00
}