[WIP] Start implementing execution in the new TS version
This commit is contained in:
@@ -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)))))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user