2025-11-11 21:37:32 -06:00
|
|
|
import { LexInput } from "../lexer.js";
|
2026-02-09 18:09:47 -06:00
|
|
|
import {Command, ParseContext, StrTerm, unwrapString} 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')
|
|
|
|
|
}
|
2026-02-09 18:09:47 -06:00
|
|
|
|
|
|
|
|
execute(vm: StrVM, data: { find: StrTerm }): Awaitable<StrVM> {
|
|
|
|
|
return vm.inPlace(ctx =>
|
|
|
|
|
ctx.replaceSubject(sub =>
|
|
|
|
|
sub.emptyUnlessCondition(s =>
|
|
|
|
|
s.includes(ctx.resolveString(data.find)))))
|
|
|
|
|
}
|
2025-11-11 21:37:32 -06:00
|
|
|
}
|