Copied!

Provides operations on token streams, for use by pretty printer.

  • internal
CloneableInstantiable
Methods
public __construct(array $tokens)
 

Create token stream instance.

  • param array $tokens Tokens in token_get_all() format
public findRight(int $pos, $findTokenType)
public getIndentationBefore(int $pos) : int
 

Get indentation before token position.

  • param int $pos Token position
  • return int 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.

  • param int $from Token start position (inclusive)
  • param int $to Token end position (exclusive)
  • param int $indent By how much the code should be indented (can be negative as well)
  • return string Code corresponding to token range, adjusted for indentation
public haveBraces(int $startPos, int $endPos) : bool
 

Whether the given position is immediately surrounded by braces.

  • param int $startPos Start position
  • param int $endPos End position
  • return bool
public haveBracesInRange(int $startPos, int $endPos)
public haveParens(int $startPos, int $endPos) : bool
 

Whether the given position is immediately surrounded by parenthesis.

  • param int $startPos Start position
  • param int $endPos End position
  • return bool
public haveTagInRange(int $startPos, int $endPos) : bool
public haveTokenImmediatelyAfter(int $pos, $expectedTokenType) : bool
 

Check whether the position is directly followed by a certain token type.

During this check whitespace and comments are skipped.

  • param int $pos Position after which the token should occur
  • param int|string $expectedTokenType Token to check for
  • return bool Whether the expected token was found
public haveTokenImmediatelyBefore(int $pos, $expectedTokenType) : bool
 

Check whether the position is directly preceded by a certain token type.

During this check whitespace and comments are skipped.

  • param int $pos Position before which the token should occur
  • param int|string $expectedTokenType Token to check for
  • return bool Whether the expected token was found
public haveTokenInRange(int $startPos, int $endPos, $tokenType)
 

Whether the given position range contains a certain token type.

  • param int $startPos Starting position (inclusive)
  • param int $endPos Ending position (exclusive)
  • param int|string $tokenType Token type to look for
  • return bool Whether the token occurs in the given range
public skipLeft(int $pos, $skipTokenType)
public skipLeftWhitespace(int $pos)
 

Return first non-whitespace token position smaller or equal to passed position.

  • param int $pos Token position
  • return int Non-whitespace token position
public skipRight(int $pos, $skipTokenType)
public skipRightWhitespace(int $pos)
 

Return first non-whitespace position greater or equal to passed position.

  • param int $pos Token position
  • return int Non-whitespace token position
Properties
private $indentMap
 
  • var int[] Map from position to indentation
private $tokens
 
  • var array Tokens (in token_get_all format)
Methods
private calcIndentMap()
 

Precalculate the indentation at every token position.

  • return int[] Token position to indentation map
© 2022 Bruce Wells
Search Namespaces \ Classes
Configuration