示例#1
0
文件: Parser.php 项目: rouffj/pdepend
 /**
  * Parses an optional statement or returns <b>null</b>.
  *
  * @return PHP_Depend_Code_ASTNode
  * @since 0.9.8
  */
 private function _parseOptionalStatement()
 {
     $tokenType = $this->tokenizer->peek();
     switch ($tokenType) {
         case self::T_ECHO:
             return $this->_parseEchoStatement();
         case self::T_SWITCH:
             return $this->_parseSwitchStatement();
         case self::T_TRY:
             return $this->_parseTryStatement();
         case self::T_THROW:
             return $this->_parseThrowStatement();
         case self::T_IF:
             return $this->_parseIfStatement();
         case self::T_FOR:
             return $this->_parseForStatement();
         case self::T_FOREACH:
             return $this->_parseForeachStatement();
         case self::T_DO:
             return $this->_parseDoWhileStatement();
         case self::T_WHILE:
             return $this->_parseWhileStatement();
         case self::T_RETURN:
             return $this->_parseReturnStatement();
         case self::T_BREAK:
             return $this->_parseBreakStatement();
         case self::T_CONTINUE:
             return $this->_parseContinueStatement();
         case self::T_GOTO:
             return $this->_parseGotoStatement();
         case self::T_GLOBAL:
             return $this->_parseGlobalStatement();
         case self::T_UNSET:
             return $this->_parseUnsetStatement();
         case self::T_STRING:
             if ($this->tokenizer->peekNext() === self::T_COLON) {
                 return $this->_parseLabelStatement();
             }
             break;
         case self::T_CONST:
             return $this->_parseConstantDefinition();
         case self::T_FUNCTION:
             return $this->_parseFunctionOrClosureDeclaration();
         case self::T_COMMENT:
             return $this->_parseCommentWithOptionalInlineClassOrInterfaceReference();
         case self::T_DOC_COMMENT:
             return $this->builder->buildASTComment($this->consumeToken(self::T_DOC_COMMENT)->image);
         case self::T_CURLY_BRACE_OPEN:
             return $this->_parseRegularScope();
         case self::T_DECLARE:
             return $this->_parseDeclareStatement();
         case self::T_ELSE:
         case self::T_ENDIF:
         case self::T_ELSEIF:
         case self::T_ENDFOR:
         case self::T_ENDWHILE:
         case self::T_ENDSWITCH:
         case self::T_ENDDECLARE:
         case self::T_ENDFOREACH:
         case self::T_CURLY_BRACE_CLOSE:
             return null;
         case self::T_DECLARE:
             return $this->_parseDeclareStatement();
         case self::T_CLOSE_TAG:
             if (($tokenType = $this->_parseNonePhpCode()) === self::T_EOF) {
                 return null;
             }
             return $this->_parseOptionalStatement();
         case self::T_TRAIT:
             $package = $this->_getNamespaceOrPackage();
             $package->addType($trait = $this->_parseTraitDeclaration());
             $this->builder->restoreTrait($trait);
             $this->_sourceFile->addChild($trait);
             return $trait;
         case self::T_INTERFACE:
             $package = $this->_getNamespaceOrPackage();
             $package->addType($interface = $this->_parseInterfaceDeclaration());
             $this->builder->restoreInterface($interface);
             $this->_sourceFile->addChild($interface);
             return $interface;
         case self::T_CLASS:
         case self::T_FINAL:
         case self::T_ABSTRACT:
             $package = $this->_getNamespaceOrPackage();
             $package->addType($class = $this->_parseClassDeclaration());
             $this->builder->restoreClass($class);
             $this->_sourceFile->addChild($class);
             return $class;
     }
     $this->_tokenStack->push();
     $stmt = $this->builder->buildASTStatement();
     if (($expr = $this->_parseOptionalExpression()) != null) {
         $stmt->addChild($expr);
     }
     $this->_parseStatementTermination();
     return $this->_setNodePositionsAndReturn($stmt);
 }
示例#2
0
 /**
  * This method can be used to register an existing trait in the current
  * class context.
  *
  * @param PHP_Depend_Code_Trait $trait The trait instance.
  *
  * @return void
  * @since 1.0.0
  */
 public function registerTrait(PHP_Depend_Code_Trait $trait)
 {
     self::$builder->restoreTrait($trait);
 }