36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
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 {
|
|
return this.isKeyword(token, 'unique')
|
|
}
|
|
|
|
attemptParse(context: ParseContext): {} {
|
|
return {}
|
|
}
|
|
|
|
getDisplayName(): string {
|
|
return 'unique'
|
|
}
|
|
|
|
execute(vm: StrVM): Awaitable<StrVM> {
|
|
return vm.replaceContextMatchingTerm({
|
|
destructuredOrLines: sub => {
|
|
const seen: Record<string, boolean> = {}
|
|
return sub.filter(part => {
|
|
const hash = hashStrRVal(part.value)
|
|
if ( seen[hash] ) {
|
|
return false
|
|
}
|
|
|
|
seen[hash] = true
|
|
return true
|
|
})
|
|
},
|
|
})
|
|
}
|
|
}
|