Implement sub-command parsing + add on/word/line/over commands
This commit is contained in:
27
src/vm/commands/on.ts
Normal file
27
src/vm/commands/on.ts
Normal 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')
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user