| Methods |
public
|
__construct(array $tokens)
Create token stream instance.
Create token stream instance.
Parameters
| $tokens |
Tokens in token_get_all() format
|
|
#
|
public
|
haveParens(int $startPos, int $endPos): bool
Whether the given position is immediately surrounded by parenthesis.
Whether the given position is immediately surrounded by parenthesis.
Parameters
| $startPos |
Start position
|
| $endPos |
End position
|
|
#
|
public
|
haveBraces(int $startPos, int $endPos): bool
Whether the given position is immediately surrounded by braces.
Whether the given position is immediately surrounded by braces.
Parameters
| $startPos |
Start position
|
| $endPos |
End position
|
|
#
|
public
|
haveTokenImmediatelyBefore(int $pos, int|string $expectedTokenType): bool
Check whether the position is directly preceded by a certain token type.
Check whether the position is directly preceded by a certain token type.
During this check whitespace and comments are skipped.
Parameters
| $pos |
Position before which the token should occur
|
| $expectedTokenType |
Token to check for
|
Returns
Whether the expected token was found
|
#
|
public
|
haveTokenImmediatelyAfter(int $pos, int|string $expectedTokenType): bool
Check whether the position is directly followed by a certain token type.
Check whether the position is directly followed by a certain token type.
During this check whitespace and comments are skipped.
Parameters
| $pos |
Position after which the token should occur
|
| $expectedTokenType |
Token to check for
|
Returns
Whether the expected token was found
|
#
|
public
|
skipLeft(int $pos, $skipTokenType)
|
#
|
public
|
skipRight(int $pos, $skipTokenType)
|
#
|
public
|
skipLeftWhitespace(int $pos): int
Return first non-whitespace token position smaller or equal to passed position.
Return first non-whitespace token position smaller or equal to passed position.
Parameters
Returns
Non-whitespace token position
|
#
|
public
|
skipRightWhitespace(int $pos): int
Return first non-whitespace position greater or equal to passed position.
Return first non-whitespace position greater or equal to passed position.
Parameters
Returns
Non-whitespace token position
|
#
|
public
|
findRight(int $pos, $findTokenType)
|
#
|
public
|
haveTokenInRange(int $startPos, int $endPos, int|string $tokenType): bool
Whether the given position range contains a certain token type.
Whether the given position range contains a certain token type.
Parameters
| $startPos |
Starting position (inclusive)
|
| $endPos |
Ending position (exclusive)
|
| $tokenType |
Token type to look for
|
Returns
Whether the token occurs in the given range
|
#
|
public
|
haveBracesInRange(int $startPos, int $endPos)
|
#
|
public
|
haveTagInRange(int $startPos, int $endPos): bool
|
#
|
public
|
getIndentationBefore(int $pos): int
Get indentation before token position.
Get indentation before token position.
Parameters
Returns
Indentation depth (in spaces)
|
#
|
public
|
getTokenCode(int $from, int $to, int $indent): string
Get the code corresponding to a token offset range, optionally adjusted for indentation.
Get the code corresponding to a token offset range, optionally adjusted for indentation.
Parameters
| $from |
Token start position (inclusive)
|
| $to |
Token end position (exclusive)
|
| $indent |
By how much the code should be indented (can be negative as well)
|
Returns
Code corresponding to token range, adjusted for indentation
|
#
|
private
|
calcIndentMap(): int[]
Precalculate the indentation at every token position.
Precalculate the indentation at every token position.
Returns
Token position to indentation map
|
#
|