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

28 lines
718 B
TypeScript
Raw Normal View History

import {Command, CommandData, ParseContext, StrTerm} from "./command.js";
import {Executable} from "../parse.js";
import {LexInput} from "../lexer.js";
export type OnData = {
type: 'line'|'word',
specific: StrTerm,
exec: Executable<CommandData>,
}
export class On extends Command<OnData> {
async attemptParse(context: ParseContext): Promise<OnData> {
return {
type: context.popKeywordInSet(['line', 'word']).value,
specific: context.popTerm(),
exec: await context.popExecutable(),
}
}
getDisplayName(): string {
return 'on'
}
isParseCandidate(token: LexInput): boolean {
return this.isKeyword(token, 'on')
}
}