final class TokenStream

Lazy token buffer over an iterator with random-access peek and consume operations.

Methods

__construct(Iterator $source)

No description

bool
is(int|string ...$kind)

Tells whether the token at current position is of given kind.

peek(int $offset = 0)

Gets the token at $offset from the current position or throws.

Token|null
tryPeek(int $offset = 0)

Gets the token at $offset from the current position.

consume(int|string ...$kind)

Consumes the current token (if is of given kind) or throws exception on end.

Token|null
tryConsume(int|string ...$kind)

Consumes the current token of given kind or returns null.

void
seek(int $index)

Sets the input cursor to the position.

int
getIndex()

Returns the cursor position.

never
throwUnexpectedException(array $expected = [], string $addendum = '', string $excerpt = '')

No description

Details

at line 24
__construct(Iterator $source)

No description

Parameters

Iterator $source

at line 33
bool is(int|string ...$kind)

Tells whether the token at current position is of given kind.

Parameters

int|string ...$kind

Return Value

bool

at line 42
Token peek(int $offset = 0)

Gets the token at $offset from the current position or throws.

Parameters

int $offset

Return Value

Token

at line 51
Token|null tryPeek(int $offset = 0)

Gets the token at $offset from the current position.

Parameters

int $offset

Return Value

Token|null

at line 72
Token consume(int|string ...$kind)

Consumes the current token (if is of given kind) or throws exception on end.

Parameters

int|string ...$kind

Return Value

Token

Exceptions

CompileException

at line 88
Token|null tryConsume(int|string ...$kind)

Consumes the current token of given kind or returns null.

Parameters

int|string ...$kind

Return Value

Token|null

at line 103
void seek(int $index)

Sets the input cursor to the position.

Parameters

int $index

Return Value

void

at line 115
int getIndex()

Returns the cursor position.

Return Value

int

at line 125
never throwUnexpectedException(array $expected = [], string $addendum = '', string $excerpt = '')

No description

Parameters

array $expected
string $addendum
string $excerpt

Return Value

never

Exceptions

CompileException