2026-02-09 22:15:33 -06:00
|
|
|
import {Command, hashStrRVal, ParseContext, unwrapDestructured, wrapDestructured, wrapString} from "./command.js";
|
2025-11-11 21:37:32 -06:00
|
|
|
import {LexInput} from "../lexer.js";
|
2026-02-09 22:15:33 -06:00
|
|
|
import {StrVM} from "../vm.js";
|
|
|
|
|
import {Awaitable} from "../../util/types.js";
|
2025-11-11 21:37:32 -06:00
|
|
|
|
|
|
|
|
export class Unique extends Command<{}> {
|
|
|
|
|
isParseCandidate(token: LexInput): boolean {
|
|
|
|
|
return this.isKeyword(token, 'unique')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
attemptParse(context: ParseContext): {} {
|
|
|
|
|
return {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getDisplayName(): string {
|
|
|
|
|
return 'unique'
|
|
|
|
|
}
|
2026-02-09 22:15:33 -06:00
|
|
|
|
|
|
|
|
execute(vm: StrVM): Awaitable<StrVM> {
|
2026-02-09 23:49:30 -06:00
|
|
|
return vm.replaceContextMatchingTerm({
|
2026-03-02 22:20:18 -06:00
|
|
|
destructuredOrLines: sub => {
|
2026-02-09 22:15:33 -06:00
|
|
|
const seen: Record<string, boolean> = {}
|
2026-02-09 23:49:30 -06:00
|
|
|
return sub.filter(part => {
|
2026-04-01 20:29:28 -05:00
|
|
|
const hash = hashStrRVal(part.value)
|
2026-02-09 23:49:30 -06:00
|
|
|
if ( seen[hash] ) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
2026-02-09 22:15:33 -06:00
|
|
|
|
2026-02-09 23:49:30 -06:00
|
|
|
seen[hash] = true
|
|
|
|
|
return true
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
})
|
2026-02-09 22:15:33 -06:00
|
|
|
}
|
2025-11-11 21:37:32 -06:00
|
|
|
}
|