Parses a token and returns a node.

@param Twig_Token $token A Twig_Token instance

@return AnnotateNode A Twig_NodeInterface instance
162883
public function parse(Twig_Token $token)
    {
        $stream = $this->parser->getStream();

        $info = array();
        $first = $this->parser->getExpressionParser()->parseExpression();

        if ($stream->test(Twig_Token::BLOCK_END_TYPE)) {
            $info['expr']= $first;
        } else {
            $info['name']= $first;
            $info['expr']= $this->parser->getExpressionParser()->parseExpression();
            if (!$stream->test(Twig_Token::BLOCK_END_TYPE)) {
                $info['prio']= $this->parser->getExpressionParser()->parseExpression();
            }
        }

        $node = new AnnotateNode($info);
        $stream->expect(\Twig_Token::BLOCK_END_TYPE);

        return $node;
    }
1155457
public function parse(Twig_Token $token)
    {
        $parser = $this->parser;
        $stream = $parser->getStream();
        $subunitExpression = $parser->getExpressionParser()->parseExpression();
        $stream->expect(Twig_Token::BLOCK_END_TYPE);

        return new RenderNode($subunitExpression, $token->getLine(), $this->getTag());
    }
78135
public function parse(\Twig_Token $token)
    {
        $lineno = $token->getLine();
        $stream = $this->parser->getStream();

        $table = $this->parser->getExpressionParser()->parseExpression();

        if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'with')) {
            $this->parser->getStream()->next();
            $resources = $this->parser->getExpressionParser()->parseExpression();
        } else {
            $resources = new \Twig_Node_Expression_Array(array(), $stream->getCurrent()->getLine());
            do {
                $resources->addElement($this->parser->getExpressionParser()->parseExpression());
            } while (!$stream->test(\Twig_Token::BLOCK_END_TYPE));
        }

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

        return new TableThemeNode($table, $resources, $lineno, $this->getTag());
    }
1100451
public function parse(\Twig_Token $token)
    {
        $lineno = $token->getLine();
        $stream = $this->parser->getStream();

        $vars = new \Twig_Node_Expression_Array(array(), $lineno);

        $count = $this->parser->getExpressionParser()->parseExpression();

        $domain = new \Twig_Node_Expression_Constant('messages', $lineno);
        $locale = null;

        if ($stream->test('with')) {
            // {% transchoice count with vars %}
            $stream->next();
            $vars = $this->parser->getExpressionParser()->parseExpression();
        }

        if ($stream->test('from')) {
            // {% transchoice count from "messages" %}
            $stream->next();
            $domain = $this->parser->getExpressionParser()->parseExpression();
        }

        if ($stream->test('into')) {
            // {% transchoice count into "fr" %}
            $stream->next();
            $locale =  $this->parser->getExpressionParser()->parseExpression();
        }

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

        $body = $this->parser->subparse(array($this, 'decideTransChoiceFork'), true);

        if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) {
            throw new \Twig_Error_Syntax('A message must be a simple text.');
        }

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

        return new TransNode($body, $domain, $count, $vars, $locale, $lineno, $this->getTag());
    }
488298
public function parse(Token $token)
    {
        $name = uniqid($this->getTag());
        $lineno = $token->getLine();
        $stream = $this->parser->getStream();
        $assets = [];

        while ($stream->test(Token::STRING_TYPE)) {
            $assets[] = $this->getRealAssetName($stream->next()->getValue());

            if ($stream->test(Token::PUNCTUATION_TYPE)) {
                $stream->next();
            }
        }

        $attributes = $this->getTagAttributes();
        $position = $this->getPosition($attributes);

        if (empty($assets)) {
            throw new SyntaxError(sprintf('The twig tag "%s" require a lest one asset', $this->getTag()), $stream->getCurrent()->getLine(), $stream->getSourceContext());
        }

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

        return new RequireTagReference($this->extension, $name, $this->getTagClass(), $assets, $attributes, $lineno, $position);
    }
758126
public function parse(Token $token)
    {
        $lineno = $token->getLine();
        $stream = $this->parser->getStream();

        $form = $this->parser->getExpressionParser()->parseExpression();
        $only = false;

        if ($this->parser->getStream()->test(Token::NAME_TYPE, 'with')) {
            $this->parser->getStream()->next();
            $resources = $this->parser->getExpressionParser()->parseExpression();

            if ($this->parser->getStream()->nextIf(Token::NAME_TYPE, 'only')) {
                $only = true;
            }
        } else {
            $resources = new ArrayExpression([], $stream->getCurrent()->getLine());
            do {
                $resources->addElement($this->parser->getExpressionParser()->parseExpression());
            } while (!$stream->test(Token::BLOCK_END_TYPE));
        }

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

        return new FormThemeNode($form, $resources, $lineno, $this->getTag(), $only);
    }
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);
    }
870907
public function parse(Twig_Token $token)
    {
        $lineno = $token->getLine();
        $stream = $this->parser->getStream();
        $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();

        $arguments = $this->parser->getExpressionParser()->parseArguments(true, true);

        $stream->expect(Twig_Token::BLOCK_END_TYPE);
        $this->parser->pushLocalScope();
        $body = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
        if ($token = $stream->nextIf(Twig_Token::NAME_TYPE)) {
            $value = $token->getValue();

            if ($value != $name) {
                throw new Twig_Error_Syntax(sprintf("Expected endmacro for macro '$name' (but %s given)", $value), $stream->getCurrent()->getLine(), $stream->getFilename());
            }
        }
        $this->parser->popLocalScope();
        $stream->expect(Twig_Token::BLOCK_END_TYPE);

        $this->parser->setMacro($name, new Twig_Node_Macro($name, new Twig_Node_Body(array($body)), $arguments, $lineno, $this->getTag()));
    }
859422
protected static function parseArgument( $token )
	{
		$description = null;

		if ( Str::contains( $token, ' : ' ) )
		{
			list( $token, $description ) = explode( ' : ', $token, 2 );

			$token = trim( $token );

			$description = trim( $description );
		}

		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::OPTIONAL, $description, $matches[2] );
			default:
				return new InputArgument( $token, InputArgument::REQUIRED, $description );
		}
	}
365459
public function parse(Twig_Token $token)
    {
        $name = $this->parser->getVarName();
        $ref = new Twig_Node_Expression_BlockReference(new Twig_Node_Expression_Constant($name, $token->getLine()), true, $token->getLine(), $this->getTag());

        $filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($ref, $this->getTag());
        $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);

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

        $block = new Twig_Node_Block($name, $body, $token->getLine());
        $this->parser->setBlock($name, $block);

        return new Twig_Node_Print($filter, $token->getLine(), $this->getTag());
    }
46490
public function parse(Token $token): PerLineNode
    {
        $stream = $this->parser->getStream();

        // perline is a very simple tag, not having anything more than its name
        // between the braces, so we expect the closing brace immediately.
        $stream->expect(Token::BLOCK_END_TYPE);

        // sub-parse everything until we reach the endperline tag.
        $body = $this->parser->subparse(function (Token $token) {
            return $token->test('endperline');
        }, true);

        // make sure our closing tag is also closed neatly and advance the
        // stream to allow continuation of parsing.
        $stream->expect(Token::BLOCK_END_TYPE);

        // turn out body in a nicely formatted PerLineNode
        return $this->parseBody($body);
    }
435971
private function parsePHPToken($token)
    {
        list($type, $expr) = $token;

        if ($type == T_INLINE_HTML) {
            $expr = $this->compileStatements($expr);
            $expr = $this->compileComments($expr);
            $expr = $this->compileRawEchos($expr);
            $expr = $this->compileRegularEchos($expr);
        }

        return $expr;
    }
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());
    }
1024594
public function parse(Twig_Token $token)
    {
        $lineno = $token->getLine();
        $stream = $this->parser->getStream();
        $reference = $stream->expect(Twig_Token::NAME_TYPE)->getValue();

        $name = $stream->nextIf(\Twig_Token::STRING_TYPE);
        $name = $name !== null ? $name->getValue() : false;

        $unique = $name !== false;

        $variableName = $stream->nextIf(\Twig_Token::NAME_TYPE);
        $variableName = $variableName !== null ? $variableName->getValue() : false;

        $offset = $stream->nextIf(\Twig_Token::NUMBER_TYPE);
        $offset = $offset !== null ? $offset->getValue() : false;

        if ($name) {
            $name = $this->blockPrefix . $reference . $name;
            if ($this->parser->hasBlock($name)) {
                $this->bodyParse($stream, $name);

                return null;
            }
        } else {
            $name = $this->createUniqueBlockName($token, $reference);
        }

        $this->parser->setBlock($name, $block = new Node\Defer($name, new Twig_Node(array()), $lineno));
        $this->parser->pushLocalScope();

        $body = $this->bodyParse($stream, $name);

        $block->setNode('body', $body);
        $this->parser->popLocalScope();

        return new Node\DeferReference($name, $variableName, $unique, $reference, $offset, $lineno, $this->getTag());
    }
1235677
public function parse(\Twig_Token $token) {

        $lineno = $token->getLine();

        $nodes['criteria'] = $this->parser->getExpressionParser()->parseExpression();
        $this->parser->getStream()->expect('as');
        $targets = $this->parser->getExpressionParser()->parseAssignmentExpression();
        $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);

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

        $elementsTarget = $targets->getNode(0);
        $nodes['elementsTarget'] = new \Twig_Node_Expression_AssignName($elementsTarget->getAttribute('name'), $elementsTarget->getLine());

        return new PageNode($nodes, array(), $lineno, $this->getTag());

    }
374569
public function parse(\Twig_Token $token)
    {
        $this->parseCodeBlock();

        return new CodeBlockNode(
            $this->highlighterName,
            $this->highlighterArgs,
            $this->getAttributes(),
            $this->getBody(),
            $token->getLine(),
            $this->getTag()
        );
    }
1345097
public function parse(Twig_Token $token)
    {
        $options = array();
        $stream = $this->parser->getStream();
        $start = $stream->getCurrent();
        $arguments = array();
        do {
            $value = $this->parser->getExpressionParser()->parseExpression();
            if ($stream->test('as')) {
                $stream->expect('as');
                $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
            } else {
                $name = null;
            }
            $arguments[] = array('name' => $name, 'value' => $value);

            $end = !$stream->test(Twig_Token::PUNCTUATION_TYPE, ',');
            if (!$end) {
                $stream->expect(Twig_Token::PUNCTUATION_TYPE, ',');
            }
        } while (!$end);

        while ($stream->test($this->options)) {
            $options[] = $stream->expect($this->options)->getValue();
        }

        $stream->expect(Twig_Token::BLOCK_END_TYPE);
        $body = $this->parser->subparse(array($this, 'decideWithEnd'), true);
        $stream->expect(Twig_Token::BLOCK_END_TYPE);
        return new WithNode($arguments, $body, $options, $start->getLine(), $start->getValue());
    }