25 lines
653 B
TypeScript
25 lines
653 B
TypeScript
|
|
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')
|
||
|
|
}
|
||
|
|
}
|