Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. MacroTokenParser.php

function MacroTokenParser::parse

Overrides TokenParserInterface::parse

File

vendor/twig/twig/src/TokenParser/MacroTokenParser.php, line 37

Class

MacroTokenParser
Defines a macro.

Namespace

Twig\TokenParser

Code

public function parse(Token $token) : Node {
    $lineno = $token->getLine();
    $stream = $this->parser
        ->getStream();
    $name = $stream->expect(Token::NAME_TYPE)
        ->getValue();
    $arguments = $this->parseDefinition();
    $stream->expect(Token::BLOCK_END_TYPE);
    $this->parser
        ->pushLocalScope();
    $body = $this->parser
        ->subparse([
        $this,
        'decideBlockEnd',
    ], true);
    if ($token = $stream->nextIf(Token::NAME_TYPE)) {
        $value = $token->getValue();
        if ($value != $name) {
            throw new SyntaxError(\sprintf('Expected endmacro for macro "%s" (but "%s" given).', $name, $value), $stream->getCurrent()
                ->getLine(), $stream->getSourceContext());
        }
    }
    $this->parser
        ->popLocalScope();
    $stream->expect(Token::BLOCK_END_TYPE);
    $this->parser
        ->setMacro($name, new MacroNode($name, new BodyNode([
        $body,
    ]), $arguments, $lineno));
    return new EmptyNode($lineno);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal