/** * 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)); }