Flow\Parser::parseBlock PHP Method

parseBlock() protected method

protected parseBlock ( $token )
    protected function parseBlock($token)
    {
        if ($this->inMacro) {
            throw new SyntaxError('cannot declare blocks inside macros', $token);
        }
        $name = $this->parseName()->getValue();
        if (isset($this->blocks[$name])) {
            throw new SyntaxError(sprintf('block "%s" already defined', $name), $token);
        }
        array_push($this->currentBlock, $name);
        if ($this->stream->consume(Token::BLOCK_END)) {
            $body = $this->subparse('endblock');
            if ($this->stream->next()->getValue() != 'endblock') {
                throw new SyntaxError('malformed block statement', $token);
            }
            $this->parseName(false, $name);
        } else {
            $expr = $this->parseExpression();
            $autoEscape = $this->autoEscape[count($this->autoEscape) - 1];
            if ($autoEscape) {
                $filters = array();
                if ($expr instanceof FilterExpression) {
                    if (!$expr->isRaw()) {
                        $expr->setAutoEscape(true);
                    }
                } else {
                    $expr = new Expression\FilterExpression($expr, $filters, true, $token->getLine());
                }
            }
            $body = new Node\OutputNode($expr, $token->getLine());
        }
        $this->stream->expect(Token::BLOCK_END);
        array_pop($this->currentBlock);
        $this->blocks[$name] = new Node\BlockNode($name, $body, $token->getLine());
        return new Node\BlockDisplayNode($name, $token->getLine());
    }