Files
str/src/vm/commands/contains.ts

29 lines
837 B
TypeScript
Raw Normal View History

2025-11-11 21:37:32 -06:00
import { LexInput } from "../lexer.js";
import {Command, ParseContext, StrTerm, unwrapString, wrapString} from "./command.js";
import {StrVM} from "../vm.js";
import {Awaitable} from "../../util/types.js";
2025-11-11 21:37:32 -06:00
export class Contains extends Command<{ find: StrTerm }> {
attemptParse(context: ParseContext): { find: StrTerm } {
return {
find: context.popTerm(),
}
}
getDisplayName(): string {
return 'contains'
}
isParseCandidate(token: LexInput): boolean {
return this.isKeyword(token, 'contains')
}
execute(vm: StrVM, data: { find: StrTerm }): Awaitable<StrVM> {
return vm.tapInPlace(ctx =>
ctx.replaceSubjectAsString(sub =>
sub.includes(ctx.resolveString(data.find))
? sub
: ''))
}
2025-11-11 21:37:32 -06:00
}