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

View File

@@ -1,5 +1,7 @@
import {Command, ParseContext} from "./command.js";
import {Command, hashStrRVal, ParseContext, unwrapDestructured, wrapDestructured, wrapString} from "./command.js";
import {LexInput} from "../lexer.js";
import {StrVM} from "../vm.js";
import {Awaitable} from "../../util/types.js";
export class Unique extends Command<{}> {
isParseCandidate(token: LexInput): boolean {
@@ -13,4 +15,22 @@ export class Unique extends Command<{}> {
getDisplayName(): string {
return 'unique'
}
execute(vm: StrVM): Awaitable<StrVM> {
return vm.tapInPlace(ctx =>
ctx.replaceSubject(sub => {
const seen: Record<string, boolean> = {}
return wrapDestructured(
unwrapDestructured(sub)
.filter(part => {
const hash = hashStrRVal(wrapString(part.value))
if ( seen[hash] ) {
return false
}
seen[hash] = true
return true
}))
}))
}
}