1<?php
2
3/*
4 * This file is part of Twig.
5 *
6 * (c) Fabien Potencier
7 * (c) Armin Ronacher
8 *
9 * For the full copyright and license information, please view the LICENSE
10 * file that was distributed with this source code.
11 */
12
13namespace Twig\TokenParser;
14
15use Twig\Error\SyntaxError;
16use Twig\Token;
17
18/**
19 * Extends a template by another one.
20 *
21 *  {% extends "base.html" %}
22 *
23 * @final
24 */
25class ExtendsTokenParser extends AbstractTokenParser
26{
27    public function parse(Token $token)
28    {
29        $stream = $this->parser->getStream();
30
31        if (!$this->parser->isMainScope()) {
32            throw new SyntaxError('Cannot extend from a block.', $token->getLine(), $stream->getSourceContext());
33        }
34
35        if (null !== $this->parser->getParent()) {
36            throw new SyntaxError('Multiple extends tags are forbidden.', $token->getLine(), $stream->getSourceContext());
37        }
38        $this->parser->setParent($this->parser->getExpressionParser()->parseExpression());
39
40        $stream->expect(Token::BLOCK_END_TYPE);
41    }
42
43    public function getTag()
44    {
45        return 'extends';
46    }
47}
48
49class_alias('Twig\TokenParser\ExtendsTokenParser', 'Twig_TokenParser_Extends');
50