Menu

## Lexer
in package

Lexer.php : 7

### Table of Contents

$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
__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
handleInvalidCharacterRange() : mixed
isUnterminatedComment() : bool
  Check whether comment token is unterminated.

### Properties

#### $code

Lexer.php : 9
`protected mixed $code`

#### $dropTokens

Lexer.php : 17
`protected mixed $dropTokens`

#### $filePos

Lexer.php : 13
`protected mixed $filePos`

#### $identifierTokens

Lexer.php : 18
`protected mixed $identifierTokens`

#### $line

Lexer.php : 12
`protected mixed $line`

#### $pos

Lexer.php : 11
`protected mixed $pos`

#### $prevCloseTagHasNewline

Lexer.php : 14
`protected mixed $prevCloseTagHasNewline`

#### $tokenMap

Lexer.php : 16
`protected mixed $tokenMap`

#### $tokens

Lexer.php : 10
`protected mixed $tokens`

#### $attributeCommentsUsed

Lexer.php : 26
`private mixed $attributeCommentsUsed`

#### $attributeEndFilePosUsed

Lexer.php : 25
`private mixed $attributeEndFilePosUsed`

#### $attributeEndLineUsed

Lexer.php : 21
`private mixed $attributeEndLineUsed`

#### $attributeEndTokenPosUsed

Lexer.php : 23
`private mixed $attributeEndTokenPosUsed`

#### $attributeStartFilePosUsed

Lexer.php : 24
`private mixed $attributeStartFilePosUsed`

#### $attributeStartLineUsed

Lexer.php : 20
`private mixed $attributeStartLineUsed`

#### $attributeStartTokenPosUsed

Lexer.php : 22
`private mixed $attributeStartTokenPosUsed`

### Methods

#### __construct()

Lexer.php : 37

Creates a Lexer.

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

##### Parameters

$options : array<string|int, mixed> = []

  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.

##### Return values

mixed —

#### getNextToken()

Lexer.php : 306

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()

Lexer.php : 397

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()

Lexer.php : 406

Handles __halt_compiler() by returning the text after it.

`public handleHaltCompiler() : string`

##### Return values

string —

Remaining text

#### startLexing()

Lexer.php : 72

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()

Lexer.php : 493

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()

Lexer.php : 131
`protected postprocessTokens(ErrorHandler $errorHandler) : mixed`

##### Parameters

$errorHandler : ErrorHandler

##### Return values

mixed —

#### createIdentifierTokenMap()

Lexer.php : 545
`private createIdentifierTokenMap() : array<string|int, mixed>`

##### Return values

array<string|int, mixed> —

#### defineCompatibilityTokens()

Lexer.php : 424
`private defineCompatibilityTokens() : mixed`

##### Return values

mixed —

#### handleInvalidCharacterRange()

Lexer.php : 96
`private handleInvalidCharacterRange(mixed $start, mixed $end, mixed $line, ErrorHandler $errorHandler) : mixed`

##### Parameters

$start : mixed
$end : mixed
$line : mixed
$errorHandler : ErrorHandler

##### Return values

mixed —

#### isUnterminatedComment()

Lexer.php : 125

Check whether comment token is unterminated.

`private isUnterminatedComment(mixed $token) : bool`

##### Parameters

$token : mixed

##### Return values

bool —

## Search results