final class TokenStream
Restricted visibility: declared "@visibility root". Code outside that scope must not name this declaration.

Walks the tokens of a grammar file in order.

Methods§

public function __construct(private list<Token> $tokens)

Parameters

$tokenslist<Token>Tokens as the scanner produced them, ending with the end-of-file token
public function peek(int $ahead = 0): Token

Answers a token ahead of the current position without consuming it.

Parameters

$aheadintDistance from the current position

Returns

Token The token, the end-of-file token past the end
Test cases 4
Called from 25
Calls 1
public function next(): Token

Consumes and answers the current token.

Returns

Token The token, the end-of-file token past the end
Test cases 7
Called from 16
Calls 2
public function is(TokenKind $kind): bool

Reports whether the current token is of a given kind.

Parameters

$kindTokenKindKind to look for

Returns

bool True when the current token is of that kind
Test cases 13
Called from 9
Calls 1
public function isDirective(string $name): bool

Reports whether the current token is a given directive.

Parameters

$namestringCanonical directive name without the percent sign

Returns

bool True for that directive
Test cases 2
Calls 1
public function accept(TokenKind $kind): Token|null

Consumes the current token when it is of a given kind.

Parameters

$kindTokenKindKind to look for

Returns

Token|null The consumed token, or null when the current token is of another kind
Test cases 1
Called from 16
Calls 2
public function expect(TokenKind $kind, string $expected): Token

Consumes the current token, which must be of a given kind.

Parameters

$kindTokenKindKind the token must have
$expectedstringWhat to say was expected when it is not

Returns

Token The consumed token

Throws

SyntaxException When the current token is of another kind
Test cases 2
Called from 17
Calls 3

Private surface 2§

Implementation details, listed for orientation only.

private int $position = 0
private list<Token> $tokens

Test cases 66§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 7
Other tests reaching this symbol 59

Relations§

Instantiated in 1
Method calls 76
Type declarations 20