function WithTokenParser::parse
Overrides TokenParserInterface::parse
File
-
vendor/
twig/ twig/ src/ TokenParser/ WithTokenParser.php, line 27
Class
- WithTokenParser
- Creates a nested scope.
Namespace
Twig\TokenParserCode
public function parse(Token $token) : Node {
$stream = $this->parser
->getStream();
$variables = null;
$only = false;
if (!$stream->test(Token::BLOCK_END_TYPE)) {
$variables = $this->parser
->getExpressionParser()
->parseExpression();
$only = (bool) $stream->nextIf(Token::NAME_TYPE, 'only');
}
$stream->expect(Token::BLOCK_END_TYPE);
$body = $this->parser
->subparse([
$this,
'decideWithEnd',
], true);
$stream->expect(Token::BLOCK_END_TYPE);
return new WithNode($body, $variables, $only, $token->getLine());
}