Copied!
CloneableInstantiable
Methods
public __construct(array $options = [])
 

Creates a Lexer.

  • param array $options Options array. Currently only the 'usedAttributes' option is supported,
    which is an array of attributes to add to the AST nodes. Possible
    attributes are: 'comments', 'startLine', 'endLine', 'startTokenPos',
    'endTokenPos', 'startFilePos', 'endFilePos'. The option defaults to the
    first three. For more info see getNextToken() docs.
public getNextToken( $value = NULL, $startAttributes = NULL, $endAttributes = NULL) : int
 

Fetches the next token.

The available attributes are determined by the 'usedAttributes' option, which can
be specified in the constructor. The following attributes are supported:

  • 'comments' => Array of PhpParser\Comment or PhpParser\Comment\Doc instances,
                   representing all comments that occurred between the previous
                   non-discarded token and the current one.
    
  • 'startLine' => Line in which the node starts.
  • 'endLine' => Line in which the node ends.
  • 'startTokenPos' => Offset into the token array of the first token in the node.
  • 'endTokenPos' => Offset into the token array of the last token in the node.
  • 'startFilePos' => Offset into the code string of the first character that is part of the node.
  • 'endFilePos' => Offset into the code string of the last character that is part of the node.
  • param mixed $value Variable to store token content in
  • param mixed $startAttributes Variable to store start attributes in
  • param mixed $endAttributes Variable to store end attributes in
  • return int Token id
public getTokens() : array
 

Returns the token array for current code.

The token array is in the same format as provided by the
token_get_all() function and does not discard tokens (i.e.
whitespace and comments are included). The token position
attributes are against this token array.

  • return array Array of tokens in token_get_all() format
public handleHaltCompiler() : string
 

Handles __halt_compiler() by returning the text after it.

  • return string Remaining text
public startLexing(string $code, ?PhpParser\ErrorHandler $errorHandler = NULL)
 

Initializes the lexer for lexing the provided source code.

This function does not throw if lexing errors occur. Instead, errors may be retrieved using
the getErrors() method.

  • param string $code The source code to lex
  • param \ErrorHandler|null $errorHandler Error handler to use for lexing errors. Defaults to
    ErrorHandler\Throwing
Properties
protected $code = NULL
protected $dropTokens = NULL
protected $filePos = NULL
protected $identifierTokens = NULL
protected $line = NULL
protected $pos = NULL
protected $prevCloseTagHasNewline = NULL
protected $tokenMap = NULL
protected $tokens = NULL
Methods
protected createTokenMap() : array
 

Creates the token map.

The token map maps the PHP internal token identifiers
to the identifiers used by the Parser. Additionally it
maps T_OPEN_TAG_WITH_ECHO to T_ECHO and T_CLOSE_TAG to ';'.

  • return array The token map
protected postprocessTokens(PhpParser\ErrorHandler $errorHandler)
Properties
private $attributeCommentsUsed = NULL
private $attributeEndFilePosUsed = NULL
private $attributeEndLineUsed = NULL
private $attributeEndTokenPosUsed = NULL
private $attributeStartFilePosUsed = NULL
private $attributeStartLineUsed = NULL
private $attributeStartTokenPosUsed = NULL
Methods
private createIdentifierTokenMap() : array
private defineCompatibilityTokens()
private handleInvalidCharacterRange( $start, $end, $line, PhpParser\ErrorHandler $errorHandler)
private isUnterminatedComment( $token) : bool
 

Check whether comment token is unterminated.

  • return bool
© 2023 Bruce Wells
Search Namespaces \ Classes
Configuration