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

Breadcrumb

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

function Parser::parse

Same name in this branch
  1. 11.1.x vendor/sebastian/cli-parser/src/Parser.php \SebastianBergmann\CliParser\Parser::parse()
  2. 11.1.x vendor/sebastian/diff/src/Parser.php \SebastianBergmann\Diff\Parser::parse()
  3. 11.1.x vendor/egulias/email-validator/src/Parser.php \Egulias\EmailValidator\Parser::parse()
  4. 11.1.x vendor/nikic/php-parser/lib/PhpParser/Parser.php \PhpParser\Parser::parse()
  5. 11.1.x vendor/symfony/css-selector/Parser/Parser.php \Symfony\Component\CssSelector\Parser\Parser::parse()
  6. 11.1.x vendor/symfony/yaml/Parser.php \Symfony\Component\Yaml\Parser::parse()
  7. 11.1.x vendor/mck89/peast/lib/Peast/Selector/Parser.php \Peast\Selector\Parser::parse()
  8. 11.1.x vendor/mck89/peast/lib/Peast/Syntax/Parser.php \Peast\Syntax\Parser::parse()

File

vendor/twig/twig/src/Parser.php, line 70

Class

Parser
@author Fabien Potencier <fabien@symfony.com>

Namespace

Twig

Code

public function parse(TokenStream $stream, $test = null, bool $dropNeedle = false) : ModuleNode {
    $vars = get_object_vars($this);
    unset($vars['stack'], $vars['env'], $vars['handlers'], $vars['visitors'], $vars['expressionParser'], $vars['reservedMacroNames'], $vars['varNameSalt']);
    $this->stack[] = $vars;
    // node visitors
    if (null === $this->visitors) {
        $this->visitors = $this->env
            ->getNodeVisitors();
    }
    if (null === $this->expressionParser) {
        $this->expressionParser = new ExpressionParser($this, $this->env);
    }
    $this->stream = $stream;
    $this->parent = null;
    $this->blocks = [];
    $this->macros = [];
    $this->traits = [];
    $this->blockStack = [];
    $this->importedSymbols = [
        [],
    ];
    $this->embeddedTemplates = [];
    try {
        $body = $this->subparse($test, $dropNeedle);
        if (null !== $this->parent && null === ($body = $this->filterBodyNodes($body))) {
            $body = new EmptyNode();
        }
    } catch (SyntaxError $e) {
        if (!$e->getSourceContext()) {
            $e->setSourceContext($this->stream
                ->getSourceContext());
        }
        if (!$e->getTemplateLine()) {
            $e->setTemplateLine($this->getCurrentToken()
                ->getLine());
        }
        throw $e;
    }
    $node = new ModuleNode(new BodyNode([
        $body,
    ]), $this->parent, new Nodes($this->blocks), new Nodes($this->macros), new Nodes($this->traits), $this->embeddedTemplates, $stream->getSourceContext());
    $traverser = new NodeTraverser($this->env, $this->visitors);
    
    /**
     * @var ModuleNode $node
     */
    $node = $traverser->traverse($node);
    // restore previous stack so previous parse() call can resume working
    foreach (array_pop($this->stack) as $key => $val) {
        $this->{$key} = $val;
    }
    return $node;
}

API Navigation

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