Methods |
abstract
protected
|
initReduceCallbacks(): void
Initialize $reduceCallbacks map.
Initialize $reduceCallbacks map.
Implemented by
|
#
|
public
|
__construct(Lexer $lexer, PhpVersion $phpVersion = null)
Creates a parser instance.
Creates a parser instance.
Options:
Parameters
$lexer |
A lexer
|
$phpVersion |
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.
|
|
#
|
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
|
#
|
public
|
getTokens(): array
Return tokens for the last parse.
Return tokens for the last parse.
Implements
|
#
|
protected
|
doParse(): Stmt[]|null
|
#
|
protected
|
emitError(Error $error): void
|
#
|
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
|
getAttributes(int $tokenStartPos, int $tokenEndPos): array<string, mixed>
Get attributes for a node with the given start and end token positions.
Get attributes for a node with the given start and end token positions.
Parameters
$tokenStartPos |
Token position the node starts at
|
$tokenEndPos |
Token position the node ends at
|
Returns
|
#
|
protected
|
getAttributesForToken(int $tokenPos): array<string, mixed>
Get attributes for a single token at the given token position.
Get attributes for a single token at the given token position.
Returns
|
#
|
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
|
handleBuiltinTypes(Name $name): Name|Identifier
|
#
|
protected
|
getAttributesAt(int $stackPos): array<string, mixed>
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(string $str, array<string, mixed> $attributes, bool $allowInvalidOctal = false): Int_
|
#
|
protected
|
parseNumString(string $str, array<string, mixed> $attributes): Int_|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<string, mixed> $attributes,
): string
|
#
|
protected
|
parseDocString(
string $startToken,
string|(Expr|InterpolatedStringPart)[] $contents,
string $endToken,
array<string, mixed> $attributes,
array<string, mixed> $endTokenAttributes,
bool $parseUnicodeEscape,
): Expr
|
#
|
protected
|
createCommentFromToken(Token $token, int $tokenPos): Comment
|
#
|
protected
|
getCommentBeforeToken(int $tokenPos): ?Comment
Get last comment before the given token position, if any
Get last comment before the given token position, if any
|
#
|
protected
|
maybeCreateZeroLengthNop(int $tokenPos): ?Nop
Create a zero-length nop to capture preceding comments, if any.
Create a zero-length nop to capture preceding comments, if any.
|
#
|
protected
|
maybeCreateNop(int $tokenStartPos, int $tokenEndPos): ?Nop
|
#
|
protected
|
handleHaltCompiler(): string
|
#
|
protected
|
inlineHtmlHasLeadingNewline(int $stackPos): bool
|
#
|
protected
|
createEmptyElemAttributes(int $tokenPos): array<string, mixed>
|
#
|
protected
|
fixupArrayDestructuring(Array_ $node): List_
|
#
|
protected
|
postprocessList(List_ $node): void
|
#
|
protected
|
fixupAlternativeElse(ElseIf_|Else_ $node): void
|
#
|
protected
|
checkClassModifier(int $a, int $b, int $modifierPos): void
|
#
|
protected
|
checkModifier(int $a, int $b, int $modifierPos): void
|
#
|
protected
|
checkParam(Param $node): void
|
#
|
protected
|
checkTryCatch(TryCatch $node): void
|
#
|
protected
|
checkNamespace(Namespace_ $node): void
|
#
|
protected
|
checkClass(Class_ $node, int $namePos): void
|
#
|
protected
|
checkInterface(Interface_ $node, int $namePos): void
|
#
|
protected
|
checkEnum(Enum_ $node, int $namePos): void
|
#
|
protected
|
checkClassMethod(ClassMethod $node, int $modifierPos): void
|
#
|
protected
|
checkClassConst(ClassConst $node, int $modifierPos): void
|
#
|
protected
|
checkUseUse(UseItem $node, int $namePos): void
|
#
|
protected
|
checkPropertyHooksForMultiProperty(Property $property, int $hookPos): void
|
#
|
protected
|
checkEmptyPropertyHookList(PropertyHook[] $hooks, int $hookPos): void
|
#
|
protected
|
checkPropertyHook(PropertyHook $hook, ?int $paramListPos): void
|
#
|
protected
|
checkPropertyHookModifiers(int $a, int $b, int $modifierPos): void
|
#
|
protected
|
addPropertyNameToHooks(Property|Param $node): void
|
#
|
protected
|
createExitExpr(string $name, int $namePos, array<Arg|VariadicPlaceholder> $args, array<string, mixed> $attrs): Expr
|
#
|
protected
|
createTokenMap(): array<int, int>
Creates the token map.
Creates the token map.
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 ';'.
Returns
|
#
|