Documentation

ParserAbstract
in package
implements Parser

AbstractYes

Table of Contents

Interfaces

Parser

Constants

SYMBOL_NONE  = -1

Properties

$action  : array<string|int, int>
$actionBase  : array<string|int, int>
$actionCheck  : array<string|int, int>
$actionDefault  : array<string|int, int>
$actionTableSize  : int
$createdArrays  : SplObjectStorage<Array_, null>|null
$defaultAction  : int
$dropTokens  : array<int, bool>
$errorHandler  : ErrorHandler
$errorState  : int
$errorSymbol  : int
$goto  : array<string|int, int>
$gotoBase  : array<string|int, int>
$gotoCheck  : array<string|int, int>
$gotoDefault  : array<string|int, int>
$gotoTableSize  : int
$invalidSymbol  : int
$lexer  : Lexer
$numNonLeafStates  : int
$phpTokenToSymbol  : array<string|int, int>
$phpVersion  : PhpVersion
$productions  : array<int, string>
$reduceCallbacks  : array<string|int, callable>
$ruleToLength  : array<string|int, int>
$ruleToNonTerminal  : array<string|int, int>
$semStack  : array<string|int, mixed>
$semValue  : mixed
$symbolToName  : array<string|int, string>
$tokenEndStack  : array<string|int, int>
$tokenPos  : int
$tokens  : array<string|int, Token>
$tokenStartStack  : array<string|int, int>
$tokenToSymbol  : array<string|int, int>
$tokenToSymbolMapSize  : int
$unexpectedTokenRule  : int
$YY2TBLSTATE  : int

Methods

__construct()  : mixed
Creates a parser instance.
getTokens()  : array<string|int, Token>
Return tokens for the last parse.
parse()  : array<string|int, Stmt>|null
Parses PHP code into a node tree.
checkClass()  : void
checkClassConst()  : void
checkClassMethod()  : void
checkClassModifier()  : void
checkEnum()  : void
checkInterface()  : void
checkModifier()  : void
checkNamespace()  : void
checkParam()  : void
checkProperty()  : void
checkTryCatch()  : void
checkUseUse()  : void
createCommentFromToken()  : Comment
createEmptyElemAttributes()  : array<string, mixed>
createTokenMap()  : array<int, int>
Creates the token map.
doParse()  : array<string|int, Stmt>|null
emitError()  : void
fixupAlternativeElse()  : void
fixupArrayDestructuring()  : List_
getAttributes()  : array<string, mixed>
Get attributes for a node with the given start and end token positions.
getAttributesAt()  : array<string, mixed>
Get combined start and end attributes at a stack location
getAttributesForToken()  : array<string, mixed>
Get attributes for a single token at the given token position.
getCommentBeforeToken()  : Comment|null
Get last comment before the given token position, if any
getErrorMessage()  : string
Format error message including expected tokens.
getExpectedTokens()  : array<string|int, string>
Get limited number of expected tokens in given state.
getFloatCastKind()  : int
handleBuiltinTypes()  : Name|Identifier
handleHaltCompiler()  : string
handleNamespaces()  : array<string|int, Stmt>
Moves statements of semicolon-style namespaces into $ns->stmts and checks various error conditions.
initReduceCallbacks()  : void
Initialize $reduceCallbacks map.
inlineHtmlHasLeadingNewline()  : bool
maybeCreateNop()  : Nop|null
maybeCreateZeroLengthNop()  : Nop|null
Create a zero-length nop to capture preceding comments, if any.
parseDocString()  : Expr
parseLNumber()  : Int_
parseNumString()  : Int_|String_
Parse a T_NUM_STRING token into either an integer or string node.
postprocessList()  : void
stripIndentation()  : string
checkClassName()  : void
checkImplementedInterfaces()  : void
fixupNamespaceAttributes()  : void
getNamespaceErrorAttributes()  : array<string, mixed>
getNamespacingStyle()  : null|string
Determine namespacing style (semicolon or brace)

Constants

Properties

$action

protected array<string|int, int> $action

Table of actions. Indexed according to $actionBase comment.

$actionBase

protected array<string|int, int> $actionBase

Map of states to a displacement into the $action table. The corresponding action for this state/symbol pair is $action[$actionBase[$state] + $symbol]. If $actionBase[$state] is 0, the action is defaulted, i.e. $actionDefault[$state] should be used instead.

$actionCheck

protected array<string|int, int> $actionCheck

Table indexed analogously to $action. If $actionCheck[$actionBase[$state] + $symbol] != $symbol then the action is defaulted, i.e. $actionDefault[$state] should be used instead.

$actionDefault

protected array<string|int, int> $actionDefault

Map of states to their default action

$actionTableSize

protected int $actionTableSize

Size of $action table

$createdArrays

protected SplObjectStorage<Array_, null>|null $createdArrays

Array nodes created during parsing, for postprocessing of empty elements.

$defaultAction

protected int $defaultAction

Action number signifying default action

$dropTokens

protected array<int, bool> $dropTokens

Map of PHP token IDs to drop

$errorState

protected int $errorState

Error state, used to avoid error floods

$errorSymbol

protected int $errorSymbol

Symbol number of error recovery token

$goto

protected array<string|int, int> $goto

Table of states to goto after reduction. Indexed according to $gotoBase comment.

$gotoBase

protected array<string|int, int> $gotoBase

Map of non-terminals to a displacement into the $goto table. The corresponding goto state for this non-terminal/state pair is $goto[$gotoBase[$nonTerminal] + $state] (unless defaulted)

$gotoCheck

protected array<string|int, int> $gotoCheck

Table indexed analogously to $goto. If $gotoCheck[$gotoBase[$nonTerminal] + $state] != $nonTerminal then the goto state is defaulted, i.e. $gotoDefault[$nonTerminal] should be used.

$gotoDefault

protected array<string|int, int> $gotoDefault

Map of non-terminals to the default state to goto after their reduction

$invalidSymbol

protected int $invalidSymbol

Symbol number signifying an invalid token

$numNonLeafStates

protected int $numNonLeafStates

Number of non-leaf states

$phpTokenToSymbol

protected array<string|int, int> $phpTokenToSymbol

Map of PHP token IDs to internal symbols

$productions

protected array<int, string> $productions

Names of the production rules (only necessary for debugging)

$reduceCallbacks

protected array<string|int, callable> $reduceCallbacks

Semantic action callbacks

$ruleToLength

protected array<string|int, int> $ruleToLength

Map of rules to the length of their right-hand side, which is the number of elements that have to be popped from the stack(s) on reduction.

$ruleToNonTerminal

protected array<string|int, int> $ruleToNonTerminal

Map of rules to the non-terminal on their left-hand side, i.e. the non-terminal to use for determining the state to goto after reduction.

$semStack

protected array<string|int, mixed> $semStack

Semantic value stack (contains values of tokens and semantic action results)

$semValue

protected mixed $semValue

Temporary value containing the result of last semantic action (reduction)

$symbolToName

protected array<string|int, string> $symbolToName

Map of symbols to their names

$tokenEndStack

protected array<string|int, int> $tokenEndStack

Token end position stack

$tokenPos

protected int $tokenPos

Current position in token array

$tokenStartStack

protected array<string|int, int> $tokenStartStack

Token start position stack

$tokenToSymbol

protected array<string|int, int> $tokenToSymbol

Map of external symbols (static::T_*) to internal symbols

$tokenToSymbolMapSize

protected int $tokenToSymbolMapSize

Size of $tokenToSymbol map

$unexpectedTokenRule

protected int $unexpectedTokenRule

Rule number signifying that an unexpected token was encountered

Methods

__construct()

Creates a parser instance.

public __construct(Lexer $lexer[, PhpVersion $phpVersion = null ]) : mixed

Options:

  • phpVersion: ?PhpVersion,
Parameters
$lexer : Lexer

A lexer

$phpVersion : PhpVersion = null

PHP version to target, defaults to latest supported. This option is best-effort: Even if specified, parsing will generally assume the latest supported version and only adjust behavior in minor ways, for example by omitting errors in older versions and interpreting type hints as a name or identifier depending on version.

getTokens()

Return tokens for the last parse.

public getTokens() : array<string|int, Token>
Return values
array<string|int, Token>

parse()

Parses PHP code into a node tree.

public parse(string $code[, ErrorHandler|null $errorHandler = null ]) : array<string|int, Stmt>|null

If a non-throwing error handler is used, the parser will continue parsing after an error occurred and attempt to build a partial AST.

Parameters
$code : string

The source code to parse

$errorHandler : ErrorHandler|null = null

Error handler to use for lexer/parser errors, defaults to ErrorHandler\Throwing.

Return values
array<string|int, Stmt>|null

Array of statements (or null non-throwing error handler is used and the parser was unable to recover from an error).

checkClassModifier()

protected checkClassModifier(int $a, int $b, int $modifierPos) : void
Parameters
$a : int
$b : int
$modifierPos : int

checkModifier()

protected checkModifier(int $a, int $b, int $modifierPos) : void
Parameters
$a : int
$b : int
$modifierPos : int

createEmptyElemAttributes()

protected createEmptyElemAttributes(int $tokenPos) : array<string, mixed>
Parameters
$tokenPos : int
Return values
array<string, mixed>

createTokenMap()

Creates the token map.

protected createTokenMap() : array<int, int>

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<int, int>

The token map

doParse()

protected doParse() : array<string|int, Stmt>|null
Return values
array<string|int, Stmt>|null

getAttributes()

Get attributes for a node with the given start and end token positions.

protected getAttributes(int $tokenStartPos, int $tokenEndPos) : array<string, mixed>
Parameters
$tokenStartPos : int

Token position the node starts at

$tokenEndPos : int

Token position the node ends at

Return values
array<string, mixed>

Attributes

getAttributesAt()

Get combined start and end attributes at a stack location

protected getAttributesAt(int $stackPos) : array<string, mixed>
Parameters
$stackPos : int

Stack location

Return values
array<string, mixed>

Combined start and end attributes

getAttributesForToken()

Get attributes for a single token at the given token position.

protected getAttributesForToken(int $tokenPos) : array<string, mixed>
Parameters
$tokenPos : int
Return values
array<string, mixed>

Attributes

getCommentBeforeToken()

Get last comment before the given token position, if any

protected getCommentBeforeToken(int $tokenPos) : Comment|null
Parameters
$tokenPos : int
Return values
Comment|null

getErrorMessage()

Format error message including expected tokens.

protected getErrorMessage(int $symbol, int $state) : string
Parameters
$symbol : int

Unexpected symbol

$state : int

State at time of error

Return values
string

Formatted error message

getExpectedTokens()

Get limited number of expected tokens in given state.

protected getExpectedTokens(int $state) : array<string|int, string>
Parameters
$state : int

State

Return values
array<string|int, string>

Expected tokens. If too many, an empty array is returned.

getFloatCastKind()

protected getFloatCastKind(string $cast) : int
Parameters
$cast : string
Return values
int

handleHaltCompiler()

protected handleHaltCompiler() : string
Return values
string

handleNamespaces()

Moves statements of semicolon-style namespaces into $ns->stmts and checks various error conditions.

protected handleNamespaces(array<string|int, Stmt$stmts) : array<string|int, Stmt>
Parameters
$stmts : array<string|int, Stmt>
Return values
array<string|int, Stmt>

initReduceCallbacks()

Initialize $reduceCallbacks map.

protected abstract initReduceCallbacks() : void

inlineHtmlHasLeadingNewline()

protected inlineHtmlHasLeadingNewline(int $stackPos) : bool
Parameters
$stackPos : int
Return values
bool

maybeCreateNop()

protected maybeCreateNop(int $tokenStartPos, int $tokenEndPos) : Nop|null
Parameters
$tokenStartPos : int
$tokenEndPos : int
Return values
Nop|null

maybeCreateZeroLengthNop()

Create a zero-length nop to capture preceding comments, if any.

protected maybeCreateZeroLengthNop(int $tokenPos) : Nop|null
Parameters
$tokenPos : int
Return values
Nop|null

parseDocString()

protected parseDocString(string $startToken, string|array<string|int, Expr|InterpolatedStringPart$contents, string $endToken, array<string, mixed> $attributes, array<string, mixed> $endTokenAttributes, bool $parseUnicodeEscape) : Expr
Parameters
$startToken : string
$contents : string|array<string|int, Expr|InterpolatedStringPart>
$endToken : string
$attributes : array<string, mixed>
$endTokenAttributes : array<string, mixed>
$parseUnicodeEscape : bool
Return values
Expr

parseLNumber()

protected parseLNumber(string $str, array<string, mixed> $attributes[, bool $allowInvalidOctal = false ]) : Int_
Parameters
$str : string
$attributes : array<string, mixed>
$allowInvalidOctal : bool = false
Return values
Int_

parseNumString()

Parse a T_NUM_STRING token into either an integer or string node.

protected parseNumString(string $str, array<string, mixed> $attributes) : Int_|String_
Parameters
$str : string

Number string

$attributes : array<string, mixed>

Attributes

Return values
Int_|String_

Integer or string node.

stripIndentation()

protected stripIndentation(string $string, int $indentLen, string $indentChar, bool $newlineAtStart, bool $newlineAtEnd, array<string, mixed> $attributes) : string
Parameters
$string : string
$indentLen : int
$indentChar : string
$newlineAtStart : bool
$newlineAtEnd : bool
$attributes : array<string, mixed>
Return values
string

checkImplementedInterfaces()

private checkImplementedInterfaces(array<string|int, Name$interfaces) : void
Parameters
$interfaces : array<string|int, Name>

getNamespaceErrorAttributes()

private getNamespaceErrorAttributes(Namespace_ $node) : array<string, mixed>
Parameters
$node : Namespace_
Return values
array<string, mixed>

getNamespacingStyle()

Determine namespacing style (semicolon or brace)

private getNamespacingStyle(array<string|int, Node$stmts) : null|string
Parameters
$stmts : array<string|int, Node>

Top-level statements.

Return values
null|string

One of "semicolon", "brace" or null (no namespaces)


        
On this page

Search results