4 * This file is part of Twig.
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
16 * {% from 'forms.html' import forms %}
21 class Twig_TokenParser_From extends Twig_TokenParser
23 public function parse(Twig_Token $token)
25 $macro = $this->parser->getExpressionParser()->parseExpression();
26 $stream = $this->parser->getStream();
27 $stream->expect('import');
31 $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
34 if ($stream->nextIf('as')) {
35 $alias = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
38 $targets[$name] = $alias;
40 if (!$stream->nextIf(Twig_Token::PUNCTUATION_TYPE, ',')) {
45 $stream->expect(Twig_Token::BLOCK_END_TYPE);
47 $node = new Twig_Node_Import($macro, new Twig_Node_Expression_AssignName($this->parser->getVarName(), $token->getLine()), $token->getLine(), $this->getTag());
49 foreach ($targets as $name => $alias) {
50 if ($this->parser->isReservedMacroName($name)) {
51 throw new Twig_Error_Syntax(sprintf('"%s" cannot be an imported macro as it is a reserved keyword.', $name), $token->getLine(), $stream->getSourceContext());
54 $this->parser->addImportedSymbol('function', $alias, 'get'.$name, $node->getNode('var'));
60 public function getTag()
66 class_alias('Twig_TokenParser_From', 'Twig\TokenParser\FromTokenParser', false);