Parses a list of tokens to separate out flags and options.
- Parser
- IterableIterator<ParserOutput>
- Iterator<ParserOutput, null, ParserOutput | undefined>
Parameters:
| Name | Type | Description |
|---|---|---|
| input? | Token[] | The input tokens. |
Returns: Parser
- get finished(): boolean
Whether the parser is finished.
Returns: boolean
- setInput(input: Token[]): this
Sets the input to use. This will reset the parser.
Parameters:
| Name | Type | Description |
|---|---|---|
| input | Token[] | Input to use. |
Returns: this
The parser.
- setUnorderedStrategy(s: UnorderedStrategy): this
Sets the strategy for parsing unordered arguments. This can be done in the middle of parsing.
const parser = new Parser(tokens)
.setUnorderedStrategy(longStrategy())
.parse();Parameters:
| Name | Type |
|---|---|
| s | UnorderedStrategy |
Returns: this
The parser.
- reset(): this
Resets the state of the parser.
Returns: this
The parser.
- next(output?: ParserOutput): IteratorResult<ParserOutput>
Gets the next parsed tokens. If a parser output is passed in, that output will be mutated, otherwise a new one is made.
Parameters:
| Name | Type | Description |
|---|---|---|
| output? | ParserOutput | Parser output to mutate. |
Returns: IteratorResult<ParserOutput>
An iterator result containing parser output.
- parse(): ParserOutput
Runs the parser.
const lexer = new Lexer(input);
const tokens = lexer.lex();
const parser = new Parser(tokens);
const output = parser.parse();Returns: ParserOutput
The parser output.