[WIP] Start implementing execution in the new TS version

This commit is contained in:
2026-02-09 18:09:47 -06:00
parent aaff8a5011
commit 82eda43dad
19 changed files with 378 additions and 10 deletions

View File

@@ -1,5 +1,7 @@
import { LexInput } from "../lexer.js";
import {Command, ParseContext, StrTerm} from "./command.js";
import {Command, ParseContext, StrTerm, unwrapString} from "./command.js";
import {StrVM} from "../vm.js";
import {Awaitable} from "../../util/types.js";
export class Contains extends Command<{ find: StrTerm }> {
attemptParse(context: ParseContext): { find: StrTerm } {
@@ -15,4 +17,11 @@ export class Contains extends Command<{ find: StrTerm }> {
isParseCandidate(token: LexInput): boolean {
return this.isKeyword(token, 'contains')
}
execute(vm: StrVM, data: { find: StrTerm }): Awaitable<StrVM> {
return vm.inPlace(ctx =>
ctx.replaceSubject(sub =>
sub.emptyUnlessCondition(s =>
s.includes(ctx.resolveString(data.find)))))
}
}