Parser is the base class for all custom parsers.

The intended usage is to extend it and utilize its method as an API where required.

Constructor

new (stream:S)

Creates a new Parser instance over TokenSource stream

Variables

read onlylast:Token

Returns the last matched token.

This is a convenience property for accessing cache[offset - 1].

Methods

inline curPos ():Position

Returns the current lexer position.

privateinline junk ():Void

Consumes the current token.

This method is automatically called after a successful match.

privateparseOptional<T> (f:Void ‑> T):T

Returns the result of calling f() if a match is made, or null otherwise.

privateparseRepeat<T> (f:Void ‑> T):Array<T>

Calls f until no match can be made.

The result is an Array containing the results of all calls to f.

privateparseSeparated<T> (separatorFunc:Token ‑> Bool, f:Void ‑> T):Array<T>

Invokes f and then separatorFunc with the current token until the result of that call is false.

The result is an Array containing the results of all calls to f.

A typical use case is parsing function arguments which are separated by a comma.

privatepeek (n:Int):Token

Returns the nth token without consuming it.