Methods |
abstract
protected
|
initReduceCallbacks()
Initialize $reduceCallbacks map.
Initialize $reduceCallbacks map.
Implemented by
|
#
|
public
|
__construct(Lexer $lexer, array $options = [])
Creates a parser instance.
Creates a parser instance.
Options: Currently none.
Parameters
$lexer |
A lexer
|
$options |
Options array.
|
|
#
|
public
|
parse(string $code, ErrorHandler|null $errorHandler = null): Stmt[]|null
Parses PHP code into a node tree.
Parses PHP code into a node tree.
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 |
The source code to parse
|
$errorHandler |
Error handler to use for lexer/parser errors, defaults
to ErrorHandler\Throwing.
|
Returns
Array of statements (or null non-throwing error handler is used and
the parser was unable to recover from an error).
Implements
|
#
|
protected
|
doParse()
|
#
|
protected
|
emitError(Error $error)
|
#
|
protected
|
getErrorMessage(int $symbol, int $state): string
Format error message including expected tokens.
Format error message including expected tokens.
Parameters
$symbol |
Unexpected symbol
|
$state |
State at time of error
|
Returns
|
#
|
protected
|
getExpectedTokens(int $state): string[]
Get limited number of expected tokens in given state.
Get limited number of expected tokens in given state.
Parameters
Returns
Expected tokens. If too many, an empty array is returned.
|
#
|
protected
|
handleNamespaces(Stmt[] $stmts): Stmt[]
Moves statements of semicolon-style namespaces into $ns->stmts and checks various error conditions.
Moves statements of semicolon-style namespaces into $ns->stmts and checks various error conditions.
|
#
|
protected
|
fixupPhp5StaticPropCall(StaticPropertyFetch|ArrayDimFetch $prop, Arg[] $args, array $attributes): StaticCall
Fix up parsing of static property calls in PHP 5.
Fix up parsing of static property calls in PHP 5.
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 "()".
|
#
|
protected
|
fixupStartAttributes(Node $to, Node $from)
|
#
|
protected
|
handleBuiltinTypes(Name $name)
|
#
|
protected
|
getAttributesAt(int $pos): array
Get combined start and end attributes at a stack location
Get combined start and end attributes at a stack location
Parameters
Returns
Combined start and end attributes
|
#
|
protected
|
getFloatCastKind(string $cast): int
|
#
|
protected
|
parseLNumber($str, $attributes, $allowInvalidOctal = false)
|
#
|
protected
|
parseNumString(string $str, array $attributes): LNumber|String_
Parse a T_NUM_STRING token into either an integer or string node.
Parse a T_NUM_STRING token into either an integer or string node.
Parameters
$str |
Number string
|
$attributes |
Attributes
|
Returns
|
#
|
protected
|
stripIndentation(
string $string,
int $indentLen,
string $indentChar,
bool $newlineAtStart,
bool $newlineAtEnd,
array $attributes,
)
|
#
|
protected
|
parseDocString(
string $startToken,
$contents,
string $endToken,
array $attributes,
array $endTokenAttributes,
bool $parseUnicodeEscape,
)
|
#
|
protected
|
createCommentNopAttributes(Comment[] $comments): array
Create attributes for a zero-length common-capturing nop.
Create attributes for a zero-length common-capturing nop.
|
#
|
protected
|
fixupAlternativeElse(ElseIf_|Else_ $node)
|
#
|
protected
|
checkClassModifier($a, $b, $modifierPos)
|
#
|
protected
|
checkModifier($a, $b, $modifierPos)
|
#
|
protected
|
checkParam(Param $node)
|
#
|
protected
|
checkTryCatch(TryCatch $node)
|
#
|
protected
|
checkNamespace(Namespace_ $node)
|
#
|
protected
|
checkClass(Class_ $node, $namePos)
|
#
|
protected
|
checkInterface(Interface_ $node, $namePos)
|
#
|
protected
|
checkEnum(Enum_ $node, $namePos)
|
#
|
protected
|
checkClassMethod(ClassMethod $node, $modifierPos)
|
#
|
protected
|
checkClassConst(ClassConst $node, $modifierPos)
|
#
|
protected
|
checkProperty(Property $node, $modifierPos)
|
#
|
protected
|
checkUseUse(UseUse $node, $namePos)
|
#
|
Properties |
protected
|
int
|
$tokenToSymbolMapSize
Size of $tokenToSymbol map
Size of $tokenToSymbol map
|
#
|
protected
|
int
|
$actionTableSize
Size of $action table
|
#
|
protected
|
int
|
$gotoTableSize
Size of $goto table
|
#
|
protected
|
int
|
$invalidSymbol
Symbol number signifying an invalid token
Symbol number signifying an invalid token
|
#
|
protected
|
int
|
$errorSymbol
Symbol number of error recovery token
Symbol number of error recovery token
|
#
|
protected
|
int
|
$defaultAction
Action number signifying default action
Action number signifying default action
|
#
|
protected
|
int
|
$unexpectedTokenRule
Rule number signifying that an unexpected token was encountered
Rule number signifying that an unexpected token was encountered
|
#
|
protected
|
|
$YY2TBLSTATE
|
#
|
protected
|
int
|
$numNonLeafStates
Number of non-leaf states
Number of non-leaf states
|
#
|
protected
|
int[]
|
$tokenToSymbol
Map of lexer tokens to internal symbols
Map of lexer tokens to internal symbols
|
#
|
protected
|
string[]
|
$symbolToName
Map of symbols to their names
Map of symbols to their names
|
#
|
protected
|
array
|
$productions
Names of the production rules (only necessary for debugging)
Names of the production rules (only necessary for debugging)
|
#
|
protected
|
int[]
|
$actionBase
Map of states to a displacement into the $action table. The corresponding action for this
state/symbol pair…
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.
|
#
|
protected
|
int[]
|
$action
Table of actions. Indexed according to $actionBase comment.
Table of actions. Indexed according to $actionBase comment.
|
#
|
protected
|
int[]
|
$actionCheck
Table indexed analogously to $action. If $actionCheck[$actionBase[$state] + $symbol] != $symbol
then the…
Table indexed analogously to $action. If $actionCheck[$actionBase[$state] + $symbol] != $symbol
then the action is defaulted, i.e. $actionDefault[$state] should be used instead.
|
#
|
protected
|
int[]
|
$actionDefault
Map of states to their default action
Map of states to their default action
|
#
|
protected
|
callable[]
|
$reduceCallbacks
Semantic action callbacks
Semantic action callbacks
|
#
|
protected
|
int[]
|
$gotoBase
Map of non-terminals to a displacement into the $goto table. The corresponding goto state for this
non…
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)
|
#
|
protected
|
int[]
|
$goto
Table of states to goto after reduction. Indexed according to $gotoBase comment.
Table of states to goto after reduction. Indexed according to $gotoBase comment.
|
#
|
protected
|
int[]
|
$gotoCheck
Table indexed analogously to $goto. If $gotoCheck[$gotoBase[$nonTerminal] + $state] != $nonTerminal
then…
Table indexed analogously to $goto. If $gotoCheck[$gotoBase[$nonTerminal] + $state] != $nonTerminal
then the goto state is defaulted, i.e. $gotoDefault[$nonTerminal] should be used.
|
#
|
protected
|
int[]
|
$gotoDefault
Map of non-terminals to the default state to goto after their reduction
Map of non-terminals to the default state to goto after their reduction
|
#
|
protected
|
int[]
|
$ruleToNonTerminal
Map of rules to the non-terminal on their left-hand side, i.e. the non-terminal to use for
determining the…
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.
|
#
|
protected
|
int[]
|
$ruleToLength
Map of rules to the length of their right-hand side, which is the number of elements that have to
be popped…
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.
|
#
|
protected
|
Lexer
|
$lexer
Lexer that is used when parsing
Lexer that is used when parsing
|
#
|
protected
|
mixed
|
$semValue
Temporary value containing the result of last semantic action (reduction)
Temporary value containing the result of last semantic action (reduction)
|
#
|
protected
|
array
|
$semStack
Semantic value stack (contains values of tokens and semantic action results)
Semantic value stack (contains values of tokens and semantic action results)
|
#
|
protected
|
array[]
|
$startAttributeStack
Start attribute stack
|
#
|
protected
|
array[]
|
$endAttributeStack
End attribute stack
|
#
|
protected
|
array
|
$endAttributes
End attributes of last *shifted* token
End attributes of last shifted token
|
#
|
protected
|
array
|
$lookaheadStartAttributes
Start attributes of last *read* token
Start attributes of last read token
|
#
|
protected
|
ErrorHandler
|
$errorHandler
Error handler
|
#
|
protected
|
int
|
$errorState
Error state, used to avoid error floods
Error state, used to avoid error floods
|
#
|