Copied!
Abstract
Constants
public PhpParser\ParserAbstract ::SYMBOL_NONE = -1
Methods
public __construct ( PhpParser\Lexer $lexer , array $options = [ ] )
 

Creates a parser instance.

Options: Currently none.

public parse ( string $code , ? PhpParser\ErrorHandler $errorHandler = NULL )
 

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.

  • return PhpParser\Node\Stmt []| null Array of statements (or null non-throwing error handler is used and the parser was unable to recover from an error).
Properties
protected $action
 
  • var int [] Table of actions. Indexed according to $actionBase comment.
protected $actionBase
 
  • var int [] 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 $actionCheck
 
  • var int [] 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 $actionDefault
 
  • var int [] Map of states to their default action
protected $actionTableSize
 
  • var int Size of $action table
protected $defaultAction
 
  • var int Action number signifying default action
protected $endAttributes
 
  • var array End attributes of last *shifted* token
protected $endAttributeStack
 
  • var array [] End attribute stack
protected $errorHandler
 
protected $errorState
 
  • var int Error state, used to avoid error floods
protected $errorSymbol
 
  • var int Symbol number of error recovery token
protected $goto
 
  • var int [] Table of states to goto after reduction. Indexed according to $gotoBase comment.
protected $gotoBase
 
  • var int [] 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 $gotoCheck
 
  • var int [] 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 $gotoDefault
 
  • var int [] Map of non-terminals to the default state to goto after their reduction
protected $gotoTableSize
 
  • var int Size of $goto table
protected $invalidSymbol
 
  • var int Symbol number signifying an invalid token
protected $lexer
 
protected $lookaheadStartAttributes
 
  • var array Start attributes of last *read* token
protected $numNonLeafStates
 
  • var int Number of non-leaf states
protected $productions
 
  • var array Names of the production rules (only necessary for debugging)
protected $reduceCallbacks
 
  • var callable [] Semantic action callbacks
protected $ruleToLength
 
  • var int [] 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 $ruleToNonTerminal
 
  • var int [] 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 $semStack
 
  • var array Semantic value stack (contains values of tokens and semantic action results)
protected $semValue
 
  • var mixed Temporary value containing the result of last semantic action (reduction)
protected $startAttributeStack
 
  • var array [] Start attribute stack
protected $symbolToName
 
  • var string [] Map of symbols to their names
protected $tokenToSymbol
 
  • var int [] Map of lexer tokens to internal symbols
protected $tokenToSymbolMapSize
 
  • var int Size of $tokenToSymbol map
protected $unexpectedTokenRule
 
  • var int Rule number signifying that an unexpected token was encountered
protected $YY2TBLSTATE
Methods
protected checkClass ( PhpParser\Node\Stmt\Class_ $node , $namePos )
protected checkClassConst ( PhpParser\Node\Stmt\ClassConst $node , $modifierPos )
protected checkClassMethod ( PhpParser\Node\Stmt\ClassMethod $node , $modifierPos )
protected checkInterface ( PhpParser\Node\Stmt\Interface_ $node , $namePos )
protected checkModifier ( $a , $b , $modifierPos )
protected checkNamespace ( PhpParser\Node\Stmt\Namespace_ $node )
protected checkParam ( PhpParser\Node\Param $node )
protected checkProperty ( PhpParser\Node\Stmt\Property $node , $modifierPos )
protected checkTryCatch ( PhpParser\Node\Stmt\TryCatch $node )
protected checkUseUse ( PhpParser\Node\Stmt\UseUse $node , $namePos )
protected createCommentNopAttributes ( array $comments )
 

Create attributes for a zero-length common-capturing nop.

  • return array
protected doParse ()
protected emitError ( PhpParser\Error $error )
protected fixupPhp5StaticPropCall ( $prop , array $args , array $attributes ) : PhpParser\Node\Expr\StaticCall
 

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

  • return Expr\StaticCall
protected fixupStartAttributes ( PhpParser\Node $to , PhpParser\Node $from )
protected getAttributesAt ( int $pos ) : array
 

Get combined start and end attributes at a stack location

  • return array Combined start and end attributes
protected getErrorMessage ( int $symbol , int $state ) : string
 

Format error message including expected tokens.

  • return string Formatted error message
protected getExpectedTokens ( int $state ) : array
 

Get limited number of expected tokens in given state.

  • return string [] Expected tokens. If too many, an empty array is returned.
protected getFloatCastKind ( string $cast ) : int
protected handleBuiltinTypes ( PhpParser\Node\Name $name )
protected handleNamespaces ( array $stmts ) : array
 

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

protected abstract initReduceCallbacks ()
 

Initialize $reduceCallbacks map.

protected parseDocString ( string $startToken , $contents , string $endToken , array $attributes , array $endTokenAttributes , bool $parseUnicodeEscape )
protected parseLNumber ( $str , $attributes , $allowInvalidOctal = false )
protected parseNumString ( string $str , array $attributes )
 

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

  • return LNumber | String_ Integer or string node.
protected stripIndentation ( string $string , int $indentLen , string $indentChar , bool $newlineAtStart , bool $newlineAtEnd , array $attributes )
Methods
private fixupNamespaceAttributes ( PhpParser\Node\Stmt\Namespace_ $stmt )
private getNamespacingStyle ( array $stmts )
 

Determine namespacing style (semicolon or brace)

  • return null | string One of "semicolon", "brace" or null (no namespaces)
© 2020 Bruce Wells
Search Namespaces \ Classes
Configuration Numbers (0-9.) only