Parses a token and returns a node.

@param \Twig_Token $token A Twig_Token instance

@return \Twig_NodeInterface A Twig_NodeInterface instance

@throws \Twig_Error_Syntax When error syntax
343872
public function parse(\Twig_Token $token)
    {
        list($type, $options, $variables, $skip, $loop) = $this->parseArguments();

        $stream = $this->parser->getStream();
        $lineno = $stream->getCurrent()->getLine();

        $superblock = new Superblock($type, $options, $loop, $lineno, $this->getTag());
        $name = $superblock->getAttribute('name');
        $reference = new SuperblockReference($name, $variables, $loop, $lineno, $this->getTag());
        $reference->setAttribute('parent_name', $name);

        $this->parser->setBlock($name, $superblock);
        $this->parser->pushLocalScope();
        $this->parser->pushBlockStack($name);

        if ($skip) {
            $this->parser->popBlockStack();
            $this->parser->popLocalScope();

            return $reference;
        }

        // body content
        $sBlocks = new \Twig_Node([], [], $lineno);
        $body = $this->parser->subparse([$this, 'decideBlockEnd'], true);
        $previousTwigNode = null;

        if (0 === \count($body) || null !== $body->getNodeTag()) {
            $body = new \Twig_Node([$body], [], $lineno);
        }

        if (null === $body->getNodeTag()) {
            /* @var \Twig_Node $node */
            foreach ($body->getIterator() as $node) {
                if (!$node instanceof \Twig_Node) {
                    continue;
                }

                if ($node instanceof SuperblockReference) {
                    $this->pushClosureNode($sBlocks, $variables, $name, $previousTwigNode);
                    $previousTwigNode = null;

                    $node->setAttribute('is_root', false);
                    $node->setAttribute('parent_name', $name);
                    $sBlocks->setNode(\count($sBlocks), $node);
                } elseif ($node instanceof \Twig_Node_Set) {
                    $this->pushClosureNode($sBlocks, $variables, $name, $previousTwigNode);
                    $previousTwigNode = null;

                    $sBlocks->setNode(\count($sBlocks), $node);
                } elseif (!$node instanceof \Twig_Node_Text || ($node instanceof \Twig_Node_Text && '' !== trim($node->getAttribute('data')))) {
                    if (null === $previousTwigNode) {
                        $previousTwigNode = new SuperblockClosure(new \Twig_Node([], [], $lineno), $node->getTemplateLine());
                    }

                    $previousTwigNode->getNode('body')->setNode(\count($previousTwigNode->getNode('body')), $node);
                }
            }
        }

        $this->pushClosureNode($sBlocks, $variables, $name, $previousTwigNode);

        $superblock->setNode('sblocks', $sBlocks);

        $stream->expect(\Twig_Token::BLOCK_END_TYPE);

        $this->parser->popBlockStack();
        $this->parser->popLocalScope();

        return $reference;
    }
540886
public function parse(Token $token)
    {
        $lineno = $token->getLine();

        $this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
        $body = $this->parser->subparse(array($this, 'decideImresizeEnd'), true);
        $this->parser->getStream()->expect(Token::BLOCK_END_TYPE);

        return new ImresizeNode($body, $lineno, $this->getTag());
    }
536379
public function parse(Token $token)
    {
        $range = $this->buildRange($token);
        $references = [];
        $from = $range->getFrom();
        $to = $range->getTo();
        $step = $range->getStep();
        for ($currentIndex = $from; $currentIndex <= $to; $currentIndex += $step) {
            $fixtureId = str_replace($this->token, $currentIndex, $range->getName());
            $references[] = new FixtureReferenceValue($fixtureId);
        }

        return new ArrayValue($references);
    }
1033477
protected static function parseArgument($token)
    {
        list($token, $description) = static::extractDescription($token);

        switch (true) {
            case Str::endsWith($token, '?*'):
                return new InputArgument(trim($token, '?*'), InputArgument::IS_ARRAY, $description);
            case Str::endsWith($token, '*'):
                return new InputArgument(trim($token, '*'), InputArgument::IS_ARRAY | InputArgument::REQUIRED, $description);
            case Str::endsWith($token, '?'):
                return new InputArgument(trim($token, '?'), InputArgument::OPTIONAL, $description);
            case preg_match('/(.+)\=\*(.+)/', $token, $matches):
                return new InputArgument($matches[1], InputArgument::IS_ARRAY, $description, preg_split('/,\s?/', $matches[2]));
            case preg_match('/(.+)\=(.+)/', $token, $matches):
                return new InputArgument($matches[1], InputArgument::OPTIONAL, $description, $matches[2]);
            default:
                return new InputArgument($token, InputArgument::REQUIRED, $description);
        }
    }
1356030
protected function processToken($token)
    {
        switch ($token) {
            case ')':
                $this->processTokenClosingParenthesis();
                break;
            case '(':
                $this->processTokenOpeningParenthesis();
                break;
            case self::LOGICAL_OR:
            case self::LOGICAL_AND:
                $this->processTokenLogicalOperator($token);
                break;
            default:
                $this->processTokenCondition($token);
                break;
        }

        return $this;
    }
638726
public function parse(Token $token): FixtureMethodCallValue
    {
        parent::parse($token);

        $explodedValue = explode('->', $token->getValue());
        if (count($explodedValue) !== 2) {
            throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token);
        }

        $reference = $this->parser->parse($explodedValue[0]);
        $method = $this->parser->parse(
            sprintf(
                '<%s>',
                $explodedValue[1]
            )
        );

        if ($reference instanceof FixtureReferenceValue && $method instanceof FunctionCallValue) {
            return new FixtureMethodCallValue($reference, $method);
        }

        throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token);
    }
835396
public function parse(array $tokens)
    {
        $symbolNodes = $this->detectSymbols($tokens);

        $nodes = $this->createTreeByBrackets($symbolNodes);

        $nodes = $this->transformTreeByFunctions($nodes);

        $this->checkGrammar($nodes);

        // Wrap the nodes in an array node.
        $rootNode = new ContainerNode($nodes);

        return $rootNode;
    }
969693
public function parse(Twig_Token $token)
    {
        $stream = $this->parser->getStream();

        $stream->expect(Twig_Token::BLOCK_END_TYPE);
        $body = $this->parser->subparse(array($this, 'decideEndAnnotations'));
        $stream->expect('endannotations');
        $stream->expect(Twig_Token::BLOCK_END_TYPE);

        return new AnnotationsNode(array('body' => $body));
    }
625525
public function parse(\Twig_Token $token)
    {
        $stream = $this->parser->getStream();
        $value = $this->parser->getExpressionParser()->parseExpression();
        $stream->expect(\Twig_Token::BLOCK_END_TYPE);

        return new JSNode($value, $token->getLine(), $this->getTag());
    }
44435
public function parse(Twig_Token $token)
    {
        $lineno = $token->getLine();
        $stream = $this->parser->getStream();

        $name = $this->parser->getExpressionParser()->parseExpression();
        $paramNames = [];
        $nodes = [$name];

        $end = false;
        while (!$end) {
            $current = $stream->next();

            switch ($current->getType()) {
                case Twig_Token::NAME_TYPE:
                    $paramNames[] = $current->getValue();
                    $stream->expect(Twig_Token::OPERATOR_TYPE, '=');
                    $nodes[] = $this->parser->getExpressionParser()->parseExpression();
                    break;

                case Twig_Token::BLOCK_END_TYPE:
                    $end = true;
                    break;

                default:
                    throw new Twig_Error_Syntax(
                        sprintf('Invalid syntax in the content tag. Line %s', $lineno),
                        $stream->getCurrent()->getLine(),
                        $stream->getSourceContext()
                    );
                    break;
            }
        }

        return new ContentNode(new Twig_Node($nodes), $paramNames, $token->getLine(), $this->getTag());
    }
1283080
public function parse(\Twig_Token $token)
    {
        $lineNo = $token->getLine();
        $stream = $this->parser->getStream();

        $attributes = [
            'html' => false,
            'css' => false,
            'js' => false,
        ];

        if ($stream->test(\Twig_Token::NAME_TYPE, 'html')) {
            $attributes['html'] = true;
            $stream->next();
        }

        if ($stream->test(\Twig_Token::NAME_TYPE, 'css')) {
            $attributes['css'] = true;
            $stream->next();
        }

        if ($stream->test(\Twig_Token::NAME_TYPE, 'js')) {
            $attributes['js'] = true;
            $stream->next();
        }

        $stream->expect(\Twig_Token::BLOCK_END_TYPE);
        $nodes['body'] = $this->parser->subparse([$this, 'decideMinifyEnd'], true);
        $stream->expect(\Twig_Token::BLOCK_END_TYPE);

        return new MinifyNode($nodes, $attributes, $lineNo, $this->getTag());
    }
791283
public function fetchToken(string $token) : ?Token
    {
        return $this->getModel()
                    ->newQuery()
                    ->where('token', $token)
                    ->first();
    }
152505
public function parse(Twig_Token $token)
    {
        $stream = $this->parser->getStream();
        $stream->expect(Twig_Token::BLOCK_END_TYPE);
        return new DefaultNode($token->getLine(), $this->getTag());
    }
187722
public function parse(Token $token): ElementNode
    {
        $stream = $this->parser->getStream();
        $name = $this->parser->getExpressionParser()->parseExpression();

        $data = null;
        if (!$stream->test(Token::BLOCK_END_TYPE)) {
            $data = $this->parser->getExpressionParser()->parseExpression();
        }

        $options = null;
        if (!$stream->test(Token::BLOCK_END_TYPE)) {
            $options = $this->parser->getExpressionParser()->parseExpression();
        }

        $stream->expect(Token::BLOCK_END_TYPE);

        return new ElementNode($name, $data, $options, $token->getLine(), $this->getTag());
    }
525232
public function parse(Twig_Token $token)
    {
        $parser = $this->parser;
        $stream = $parser->getStream();

        $default = array();
        $cases = array();
        $end = false;

        $name = $parser->getExpressionParser()->parseExpression();
        $stream->expect(Twig_Token::BLOCK_END_TYPE);
        $stream->expect(Twig_Token::TEXT_TYPE);
        $stream->expect(Twig_Token::BLOCK_START_TYPE);
        while (!$end)
        {
            $v = $stream->next();
            switch ($v->getValue()) {
                case 'default':
                    $stream->expect(Twig_Token::BLOCK_END_TYPE);
                    $default[] = $parser->subparse(array($this, 'decideIfEnd'));
                    break;

                case 'case':
                    $expr = $parser->getExpressionParser()->parseExpression();
                    $stream->expect(Twig_Token::BLOCK_END_TYPE);
                    $body = $parser->subparse(array($this, 'decideIfFork'));
                    $cases[] = $expr;
                    $cases[] = $body;
                    break;

                case 'endswitch':
                    $end = true;
                    break;

                default:
                    throw new Twig_Error_Syntax(sprintf('Unexpected end of template. Twig was looking for the following tags "case", "default", or "endswitch" to close the "switch" block started at line %d)', $token->getLine()), -1);
            }
        }

        $stream->expect(Twig_Token::BLOCK_END_TYPE);

        return new NodeSwitch($name, new Twig_Node($cases), new Twig_Node($default), $token->getLine(), $this->getTag());
    }
204803
public function parse(\Twig_Token $token)
    {
        $expr = $this->parser->getExpressionParser()->parseExpression();

        $variables = $this->parseArguments();

        return new \Cetera\Twig\Node\Widget($expr, $variables, $token->getLine(), $this->getTag());
    }
429547
public function parse(Token $token)
    {
        $lineno = $token->getLine();
        $stream = $this->parser->getStream();

        $stream->expect(Token::BLOCK_END_TYPE);
        $try = $this->parser->subparse([$this, 'decideCatch']);
        $stream->next();
        $stream->expect(Token::BLOCK_END_TYPE);
        $catch = $this->parser->subparse([$this, 'decideEnd']);
        $stream->next();
        $stream->expect(Token::BLOCK_END_TYPE);

        return new TwigNodeTryCatch($try, $catch, $lineno, $this->getTag());
    }