str/src/vm/commands/lower.ts

25 lines
618 B
TypeScript

import {Command, ParseContext} from "./command.js";
import {LexInput} from "../lexer.js";
import {Awaitable} from "../../util/types.js";
import {StrVM} from "../vm.js";
export class Lower extends Command<{}> {
isParseCandidate(token: LexInput): boolean {
return this.isKeyword(token, 'lower')
}
attemptParse(context: ParseContext): {} {
return {}
}
getDisplayName(): string {
return 'lower'
}
execute(vm: StrVM): Awaitable<StrVM> {
return vm.inPlace(ctx =>
ctx.replaceSubject(sub =>
sub.modify(s => s.toLowerCase())))
}
}