Replace StringRange w/ an actual StrRVal + more command implementations

This commit is contained in:
2026-02-09 22:15:33 -06:00
parent 82eda43dad
commit feba84051a
29 changed files with 502 additions and 192 deletions

33
src/vm/commands/words.ts Normal file
View File

@@ -0,0 +1,33 @@
import {Command, ParseContext, unwrapString, wrapDestructured} from "./command.js";
import {LexInput} from "../lexer.js";
import {StrVM} from "../vm.js";
import {Awaitable} from "../../util/types.js";
export class Words extends Command<{}> {
attemptParse(context: ParseContext): {} {
return {}
}
getDisplayName(): string {
return 'words'
}
isParseCandidate(token: LexInput): boolean {
return this.isKeyword(token, 'words')
}
execute(vm: StrVM): Awaitable<StrVM> {
return vm.tapInPlace(ctx =>
ctx.replaceSubject(sub => {
const val = unwrapString(sub)
const separators = [...val.matchAll(/\s+/sg)]
const parts = val.split(/\s+/sg)
return wrapDestructured(
parts.map((part, idx) => ({
prefix: idx ? separators[idx - 1][0] : undefined,
value: part,
})))
}))
}
}