Ejemplo n.º 1
0
 /**
  * This method parses a single foreach-statement node.
  *
  * @return PHP_Depend_Code_ASTForeachStatement
  * @since 0.9.8
  */
 private function _parseForeachStatement()
 {
     $this->_tokenStack->push();
     $token = $this->consumeToken(self::T_FOREACH);
     $foreach = $this->builder->buildASTForeachStatement($token->image);
     $this->consumeComments();
     $this->consumeToken(self::T_PARENTHESIS_OPEN);
     $foreach->addChild($this->_parseExpression());
     $this->consumeToken(self::T_AS);
     $this->consumeComments();
     if ($this->tokenizer->peek() === self::T_BITWISE_AND) {
         $foreach->addChild($this->_parseVariableOrMemberByReference());
     } else {
         $foreach->addChild($this->_parseVariableOrConstantOrPrimaryPrefix());
         if ($this->tokenizer->peek() === self::T_DOUBLE_ARROW) {
             $this->consumeToken(self::T_DOUBLE_ARROW);
             $foreach->addChild($this->_parseVariableOrMemberOptionalByReference());
         }
     }
     $this->consumeComments();
     $this->consumeToken(self::T_PARENTHESIS_CLOSE);
     return $this->_setNodePositionsAndReturn($this->_parseStatementBody($foreach));
 }
Ejemplo n.º 2
0
 /**
  * This method parses a single foreach-statement node.
  *
  * @return PHP_Depend_Code_ASTForeachStatement
  * @since 0.9.8
  */
 private function _parseForeachStatement()
 {
     $this->_tokenStack->push();
     $token = $this->_consumeToken(self::T_FOREACH);
     $foreach = $this->_builder->buildASTForeachStatement($token->image);
     $this->_consumeComments();
     $this->_consumeToken(self::T_PARENTHESIS_OPEN);
     // TODO: $foreach->addChild($this->_parseExpression());
     if (($expr = $this->_parseOptionalExpression()) != null) {
         $foreach->addChild($expr);
     }
     $this->_consumeToken(self::T_AS);
     $this->_consumeComments();
     if ($this->_tokenizer->peek() === self::T_BITWISE_AND) {
         $foreach->addChild($this->_parseVariableByReference());
     } else {
         $variable = $this->_parseCompoundVariableOrVariableVariableOrVariable();
         $foreach->addChild($variable);
         if ($this->_tokenizer->peek() === self::T_DOUBLE_ARROW) {
             $this->_consumeToken(self::T_DOUBLE_ARROW);
             $foreach->addChild($this->_parseVariableOptionalByReference());
         }
     }
     $this->_consumeComments();
     $this->_consumeToken(self::T_PARENTHESIS_CLOSE);
     return $this->_setNodePositionsAndReturn($this->_parseStatementBody($foreach));
 }