Implement sub-command parsing + add on/word/line/over commands

This commit is contained in:
2025-11-11 22:09:26 -06:00
parent bfc9459b69
commit aaff8a5011
8 changed files with 153 additions and 9 deletions

27
src/vm/commands/on.ts Normal file
View File

@@ -0,0 +1,27 @@
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')
}
}