Flow\Parser::parseFor PHP Method

parseFor() protected method

protected parseFor ( $token )
    protected function parseFor($token)
    {
        $this->inForLoop++;
        $line = $token->getLine();
        $key = null;
        $value = $this->parseName()->getValue();
        if ($this->stream->consume(Token::OPERATOR, ',')) {
            $key = $value;
            $value = $this->parseName()->getValue();
        }
        $this->stream->expect(Token::OPERATOR, 'in');
        $seq = $this->parseExpression();
        $this->stream->expect(Token::BLOCK_END);
        $body = $this->subparse(array('else', 'endfor'));
        $this->inForLoop--;
        if ($this->stream->getCurrentToken()->getValue() == 'else') {
            $this->stream->next();
            $this->stream->expect(Token::BLOCK_END);
            $else = $this->subparse('endfor');
            if ($this->stream->getCurrentToken()->getValue() != 'endfor') {
                throw new SyntaxError('malformed for statement', $token);
            }
        } elseif ($this->stream->getCurrentToken()->getValue() == 'endfor') {
            $else = null;
        } else {
            throw new SyntaxError('malformed for statement', $token);
        }
        $this->stream->next();
        $this->stream->expect(Token::BLOCK_END);
        return new Node\ForNode($seq, $key, $value, $body, $else, $line);
    }