ParserAbstract
in package
implements
Parser
Interfaces, Classes and Traits
Table of Contents
- SYMBOL_NONE = -1
- $action : array<string|int, int>
- $actionBase : array<string|int, int>
- $actionCheck : array<string|int, int>
- $actionDefault : array<string|int, int>
- $actionTableSize : int
- $defaultAction : int
- $endAttributes : array<string|int, mixed>
- $endAttributeStack : array<string|int, array<string|int, mixed>>
- $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
- $lookaheadStartAttributes : array<string|int, mixed>
- $numNonLeafStates : int
- $productions : array<string|int, mixed>
- $reduceCallbacks : array<string|int, callable>
- $ruleToLength : array<string|int, int>
- $ruleToNonTerminal : array<string|int, int>
- $semStack : array<string|int, mixed>
- $semValue : mixed
- $startAttributeStack : array<string|int, array<string|int, mixed>>
- $symbolToName : array<string|int, string>
- $tokenToSymbol : array<string|int, int>
- $tokenToSymbolMapSize : int
- $unexpectedTokenRule : int
- $YY2TBLSTATE : mixed
- __construct() : mixed
- Creates a parser instance.
- parse() : array<string|int, Stmt>|null
- Parses PHP code into a node tree.
- checkClass() : mixed
- checkClassConst() : mixed
- checkClassMethod() : mixed
- checkClassModifier() : mixed
- checkEnum() : mixed
- checkInterface() : mixed
- checkModifier() : mixed
- checkNamespace() : mixed
- checkParam() : mixed
- checkProperty() : mixed
- checkTryCatch() : mixed
- checkUseUse() : mixed
- createCommentNopAttributes() : array<string|int, mixed>
- Create attributes for a zero-length common-capturing nop.
- doParse() : mixed
- emitError() : mixed
- fixupAlternativeElse() : mixed
- fixupPhp5StaticPropCall() : StaticCall
- Fix up parsing of static property calls in PHP 5.
- fixupStartAttributes() : mixed
- getAttributesAt() : array<string|int, mixed>
- Get combined start and end attributes at a stack location
- 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() : mixed
- handleNamespaces() : array<string|int, Stmt>
- Moves statements of semicolon-style namespaces into $ns->stmts and checks various error conditions.
- initReduceCallbacks() : mixed
- Initialize $reduceCallbacks map.
- parseDocString() : mixed
- parseLNumber() : mixed
- parseNumString() : LNumber|String_
- Parse a T_NUM_STRING token into either an integer or string node.
- stripIndentation() : mixed
- checkClassName() : mixed
- checkImplementedInterfaces() : mixed
- fixupNamespaceAttributes() : mixed
- getNamespacingStyle() : null|string
- Determine namespacing style (semicolon or brace)
Constants
SYMBOL_NONE
public
mixed
SYMBOL_NONE
= -1
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
$defaultAction
protected
int
$defaultAction
Action number signifying default action
$endAttributes
protected
array<string|int, mixed>
$endAttributes
End attributes of last shifted token
$endAttributeStack
protected
array<string|int, array<string|int, mixed>>
$endAttributeStack
End attribute stack
$errorHandler
protected
ErrorHandler
$errorHandler
Error handler
$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
$gotoTableSize
protected
int
$gotoTableSize
Size of $goto table
$invalidSymbol
protected
int
$invalidSymbol
Symbol number signifying an invalid token
$lexer
protected
Lexer
$lexer
Lexer that is used when parsing
$lookaheadStartAttributes
protected
array<string|int, mixed>
$lookaheadStartAttributes
Start attributes of last read token
$numNonLeafStates
protected
int
$numNonLeafStates
Number of non-leaf states
$productions
protected
array<string|int, mixed>
$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)
$startAttributeStack
protected
array<string|int, array<string|int, mixed>>
$startAttributeStack
Start attribute stack
$symbolToName
protected
array<string|int, string>
$symbolToName
Map of symbols to their names
$tokenToSymbol
protected
array<string|int, int>
$tokenToSymbol
Map of lexer tokens to internal symbols
$tokenToSymbolMapSize
protected
int
$tokenToSymbolMapSize
Size of $tokenToSymbol map
$unexpectedTokenRule
protected
int
$unexpectedTokenRule
Rule number signifying that an unexpected token was encountered
$YY2TBLSTATE
protected
mixed
$YY2TBLSTATE
Methods
__construct()
Creates a parser instance.
public
__construct(Lexer $lexer[, array<string|int, mixed> $options = [] ]) : mixed
Options: Currently none.
Parameters
- $lexer : Lexer
-
A lexer
- $options : array<string|int, mixed> = []
-
Options array.
Return values
mixed —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).
checkClass()
protected
checkClass(Class_ $node, mixed $namePos) : mixed
Parameters
- $node : Class_
- $namePos : mixed
Return values
mixed —checkClassConst()
protected
checkClassConst(ClassConst $node, mixed $modifierPos) : mixed
Parameters
- $node : ClassConst
- $modifierPos : mixed
Return values
mixed —checkClassMethod()
protected
checkClassMethod(ClassMethod $node, mixed $modifierPos) : mixed
Parameters
- $node : ClassMethod
- $modifierPos : mixed
Return values
mixed —checkClassModifier()
protected
checkClassModifier(mixed $a, mixed $b, mixed $modifierPos) : mixed
Parameters
- $a : mixed
- $b : mixed
- $modifierPos : mixed
Return values
mixed —checkEnum()
protected
checkEnum(Enum_ $node, mixed $namePos) : mixed
Parameters
- $node : Enum_
- $namePos : mixed
Return values
mixed —checkInterface()
protected
checkInterface(Interface_ $node, mixed $namePos) : mixed
Parameters
- $node : Interface_
- $namePos : mixed
Return values
mixed —checkModifier()
protected
checkModifier(mixed $a, mixed $b, mixed $modifierPos) : mixed
Parameters
- $a : mixed
- $b : mixed
- $modifierPos : mixed
Return values
mixed —checkNamespace()
protected
checkNamespace(Namespace_ $node) : mixed
Parameters
- $node : Namespace_
Return values
mixed —checkParam()
protected
checkParam(Param $node) : mixed
Parameters
- $node : Param
Return values
mixed —checkProperty()
protected
checkProperty(Property $node, mixed $modifierPos) : mixed
Parameters
- $node : Property
- $modifierPos : mixed
Return values
mixed —checkTryCatch()
protected
checkTryCatch(TryCatch $node) : mixed
Parameters
- $node : TryCatch
Return values
mixed —checkUseUse()
protected
checkUseUse(UseUse $node, mixed $namePos) : mixed
Parameters
- $node : UseUse
- $namePos : mixed
Return values
mixed —createCommentNopAttributes()
Create attributes for a zero-length common-capturing nop.
protected
createCommentNopAttributes(array<string|int, Comment> $comments) : array<string|int, mixed>
Parameters
- $comments : array<string|int, Comment>
Return values
array<string|int, mixed> —doParse()
protected
doParse() : mixed
Return values
mixed —emitError()
protected
emitError(Error $error) : mixed
Parameters
- $error : Error
Return values
mixed —fixupAlternativeElse()
protected
fixupAlternativeElse(ElseIf_|Else_ $node) : mixed
Parameters
Return values
mixed —fixupPhp5StaticPropCall()
Fix up parsing of static property calls in PHP 5.
protected
fixupPhp5StaticPropCall(StaticPropertyFetch|ArrayDimFetch $prop, array<string|int, Arg> $args, array<string|int, mixed> $attributes) : StaticCall
In PHP 5 A::$b[c][d] and A::$b[c]d have very different interpretation. The former is interpreted as (A::$b)[c][d], while the latter is the same as A::{$b[c][d]}(). We parse the latter as the former initially and this method fixes the AST into the correct form when we encounter the "()".
Parameters
- $prop : StaticPropertyFetch|ArrayDimFetch
- $args : array<string|int, Arg>
- $attributes : array<string|int, mixed>
Return values
StaticCall —fixupStartAttributes()
protected
fixupStartAttributes(Node $to, Node $from) : mixed
Parameters
Return values
mixed —getAttributesAt()
Get combined start and end attributes at a stack location
protected
getAttributesAt(int $pos) : array<string|int, mixed>
Parameters
- $pos : int
-
Stack location
Return values
array<string|int, mixed> —Combined start and end attributes
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 —handleBuiltinTypes()
protected
handleBuiltinTypes(Name $name) : mixed
Parameters
- $name : Name
Return values
mixed —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() : mixed
Return values
mixed —parseDocString()
protected
parseDocString(string $startToken, mixed $contents, string $endToken, array<string|int, mixed> $attributes, array<string|int, mixed> $endTokenAttributes, bool $parseUnicodeEscape) : mixed
Parameters
- $startToken : string
- $contents : mixed
- $endToken : string
- $attributes : array<string|int, mixed>
- $endTokenAttributes : array<string|int, mixed>
- $parseUnicodeEscape : bool
Return values
mixed —parseLNumber()
protected
parseLNumber(mixed $str, mixed $attributes[, mixed $allowInvalidOctal = false ]) : mixed
Parameters
- $str : mixed
- $attributes : mixed
- $allowInvalidOctal : mixed = false
Return values
mixed —parseNumString()
Parse a T_NUM_STRING token into either an integer or string node.
protected
parseNumString(string $str, array<string|int, mixed> $attributes) : LNumber|String_
Parameters
- $str : string
-
Number string
- $attributes : array<string|int, mixed>
-
Attributes
Return values
LNumber|String_ —Integer or string node.
stripIndentation()
protected
stripIndentation(string $string, int $indentLen, string $indentChar, bool $newlineAtStart, bool $newlineAtEnd, array<string|int, mixed> $attributes) : mixed
Parameters
- $string : string
- $indentLen : int
- $indentChar : string
- $newlineAtStart : bool
- $newlineAtEnd : bool
- $attributes : array<string|int, mixed>
Return values
mixed —checkClassName()
private
checkClassName(mixed $name, mixed $namePos) : mixed
Parameters
- $name : mixed
- $namePos : mixed
Return values
mixed —checkImplementedInterfaces()
private
checkImplementedInterfaces(array<string|int, mixed> $interfaces) : mixed
Parameters
- $interfaces : array<string|int, mixed>
Return values
mixed —fixupNamespaceAttributes()
private
fixupNamespaceAttributes(Namespace_ $stmt) : mixed
Parameters
- $stmt : Namespace_
Return values
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)