2026-04-01 20:29:28 -05:00
|
|
|
import {Command, ParseContext, wrapString} from "./command.js";
|
2026-02-09 22:15:33 -06:00
|
|
|
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> {
|
2026-02-09 23:49:30 -06:00
|
|
|
return vm.replaceContextMatchingTerm({
|
|
|
|
|
destructure: sub => {
|
|
|
|
|
const separators = [...sub.matchAll(/\s+/sg)]
|
|
|
|
|
const parts = sub.split(/\s+/sg)
|
2026-02-09 22:15:33 -06:00
|
|
|
|
2026-02-09 23:49:30 -06:00
|
|
|
return parts.map((part, idx) => ({
|
|
|
|
|
prefix: idx ? separators[idx - 1][0] : undefined,
|
2026-04-01 20:29:28 -05:00
|
|
|
value: wrapString(part),
|
2026-02-09 23:49:30 -06:00
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
})
|
2026-02-09 22:15:33 -06:00
|
|
|
}
|
|
|
|
|
}
|