1<?php 2 3/* 4 * This file is part of Twig. 5 * 6 * (c) Fabien Potencier 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12namespace Twig\TokenParser; 13 14use Twig\Node\Expression\AssignNameExpression; 15use Twig\Node\ImportNode; 16use Twig\Token; 17 18/** 19 * Imports macros. 20 * 21 * {% import 'forms.html' as forms %} 22 */ 23final class ImportTokenParser extends AbstractTokenParser 24{ 25 public function parse(Token $token) 26 { 27 $macro = $this->parser->getExpressionParser()->parseExpression(); 28 $this->parser->getStream()->expect(/* Token::NAME_TYPE */ 5, 'as'); 29 $var = new AssignNameExpression($this->parser->getStream()->expect(/* Token::NAME_TYPE */ 5)->getValue(), $token->getLine()); 30 $this->parser->getStream()->expect(/* Token::BLOCK_END_TYPE */ 3); 31 32 $this->parser->addImportedSymbol('template', $var->getAttribute('name')); 33 34 return new ImportNode($macro, $var, $token->getLine(), $this->getTag(), $this->parser->isMainScope()); 35 } 36 37 public function getTag() 38 { 39 return 'import'; 40 } 41} 42 43class_alias('Twig\TokenParser\ImportTokenParser', 'Twig_TokenParser_Import'); 44