str/src/vm/commands/trim.ts

25 lines
653 B
TypeScript
Raw Normal View History

2025-11-12 03:37:32 +00:00
import {Command, ParseContext, StrTerm} from "./command.js";
import {LexInput} from "../lexer.js";
export type TrimData = {
type?: 'start'|'end'|'both'|'left'|'right'|'lines',
char?: StrTerm,
}
export class Trim extends Command<TrimData> {
attemptParse(context: ParseContext): TrimData {
return {
type: context.popOptionalKeywordInSet(['start', 'end', 'both', 'left', 'right', 'lines'])?.value,
char: context.popOptionalTerm(),
}
}
getDisplayName(): string {
return 'trim'
}
isParseCandidate(token: LexInput): boolean {
return this.isKeyword(token, 'trim')
}
}