Documentation

Emulative extends Lexer
in package

Table of Contents

PHP_7_3  = '7.3dev'
PHP_7_4  = '7.4dev'
PHP_8_0  = '8.0dev'
PHP_8_1  = '8.1dev'
PHP_8_2  = '8.2dev'
$code  : mixed
$dropTokens  : mixed
$filePos  : mixed
$identifierTokens  : mixed
$line  : mixed
$pos  : mixed
$prevCloseTagHasNewline  : mixed
$tokenMap  : mixed
$tokens  : mixed
$attributeCommentsUsed  : mixed
$attributeEndFilePosUsed  : mixed
$attributeEndLineUsed  : mixed
$attributeEndTokenPosUsed  : mixed
$attributeStartFilePosUsed  : mixed
$attributeStartLineUsed  : mixed
$attributeStartTokenPosUsed  : mixed
$emulators  : array<string|int, TokenEmulator>
$patches  : array<string|int, mixed>
$targetPhpVersion  : string
__construct()  : mixed
Creates a Lexer.
getNextToken()  : int
Fetches the next token.
getTokens()  : array<string|int, mixed>
Returns the token array for current code.
handleHaltCompiler()  : string
Handles __halt_compiler() by returning the text after it.
startLexing()  : mixed
Initializes the lexer for lexing the provided source code.
createTokenMap()  : array<string|int, mixed>
Creates the token map.
postprocessTokens()  : mixed
createIdentifierTokenMap()  : array<string|int, mixed>
defineCompatibilityTokens()  : mixed
fixupErrors()  : mixed
Fixup line and position information in errors.
fixupTokens()  : mixed
handleInvalidCharacterRange()  : mixed
isForwardEmulationNeeded()  : bool
isReverseEmulationNeeded()  : bool
isUnterminatedComment()  : bool
Check whether comment token is unterminated.
sortPatches()  : mixed

Constants

Properties

$dropTokens

protected mixed $dropTokens

$filePos

protected mixed $filePos

$identifierTokens

protected mixed $identifierTokens

$prevCloseTagHasNewline

protected mixed $prevCloseTagHasNewline

$tokenMap

protected mixed $tokenMap

$tokens

protected mixed $tokens

$attributeCommentsUsed

private mixed $attributeCommentsUsed

$attributeEndFilePosUsed

private mixed $attributeEndFilePosUsed

$attributeEndLineUsed

private mixed $attributeEndLineUsed

$attributeEndTokenPosUsed

private mixed $attributeEndTokenPosUsed

$attributeStartFilePosUsed

private mixed $attributeStartFilePosUsed

$attributeStartLineUsed

private mixed $attributeStartLineUsed

$attributeStartTokenPosUsed

private mixed $attributeStartTokenPosUsed

$emulators

private array<string|int, TokenEmulator> $emulators = []

$patches

private array<string|int, mixed> $patches = []

Patches used to reverse changes introduced in the code

$targetPhpVersion

private string $targetPhpVersion

Methods

__construct()

Creates a Lexer.

public __construct([array<string|int, mixed> $options = [] ]) : mixed
Parameters
$options : array<string|int, mixed> = []

Lexer options. In addition to the usual options, accepts a 'phpVersion' string that specifies the version to emulate. Defaults to newest supported.

Return values
mixed

getNextToken()

Fetches the next token.

public getNextToken([mixed &$value = null ][, mixed &$startAttributes = null ][, mixed &$endAttributes = null ]) : int

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.
Parameters
$value : mixed = null

Variable to store token content in

$startAttributes : mixed = null

Variable to store start attributes in

$endAttributes : mixed = null

Variable to store end attributes in

Return values
int

Token id

getTokens()

Returns the token array for current code.

public getTokens() : array<string|int, mixed>

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 values
array<string|int, mixed>

Array of tokens in token_get_all() format

handleHaltCompiler()

Handles __halt_compiler() by returning the text after it.

public handleHaltCompiler() : string
Return values
string

Remaining text

startLexing()

Initializes the lexer for lexing the provided source code.

public startLexing(string $code[, ErrorHandler|null $errorHandler = null ]) : mixed

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

Parameters
$code : string

The source code to lex

$errorHandler : ErrorHandler|null = null

Error handler to use for lexing errors. Defaults to ErrorHandler\Throwing

Return values
mixed

createTokenMap()

Creates the token map.

protected createTokenMap() : array<string|int, mixed>

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 values
array<string|int, mixed>

The token map

postprocessTokens()

protected postprocessTokens(ErrorHandler $errorHandler) : mixed
Parameters
$errorHandler : ErrorHandler
Return values
mixed

createIdentifierTokenMap()

private createIdentifierTokenMap() : array<string|int, mixed>
Return values
array<string|int, mixed>

defineCompatibilityTokens()

private defineCompatibilityTokens() : mixed
Return values
mixed

fixupErrors()

Fixup line and position information in errors.

private fixupErrors(array<string|int, Error$errors) : mixed
Parameters
$errors : array<string|int, Error>
Return values
mixed

fixupTokens()

private fixupTokens() : mixed
Return values
mixed

handleInvalidCharacterRange()

private handleInvalidCharacterRange(mixed $start, mixed $end, mixed $line, ErrorHandler $errorHandler) : mixed
Parameters
$start : mixed
$end : mixed
$line : mixed
$errorHandler : ErrorHandler
Return values
mixed

isForwardEmulationNeeded()

private isForwardEmulationNeeded(string $emulatorPhpVersion) : bool
Parameters
$emulatorPhpVersion : string
Return values
bool

isReverseEmulationNeeded()

private isReverseEmulationNeeded(string $emulatorPhpVersion) : bool
Parameters
$emulatorPhpVersion : string
Return values
bool

isUnterminatedComment()

Check whether comment token is unterminated.

private isUnterminatedComment(mixed $token) : bool
Parameters
$token : mixed
Return values
bool

sortPatches()

private sortPatches() : mixed
Return values
mixed

Search results