public function parse(Parser $parser, Stream $stream) { $node = $this->helper->createRenderBlockNode($parser->getCurrentBlock(), $this->helper->createContext($stream->next()->test(Token::IDENTIFIER, 'using'), $stream, $parser)); $expression = $node->getChild('expression'); if (!$expression instanceof FunctionNode) { throw new \UnexpectedValueException("An instance of FunctionNode was expected"); } $expression->addArgument(new DataNode(true)); return $node; }
public function parse(Parser $parser, Stream $stream) { //force the optimizer to compile $environment by always using a temp variable $environmentNode = new TempVariableNode('environment'); $parentTemplate = $parser->parseExpression($stream); $contextNode = $this->helper->createContext($stream->current()->test(Token::IDENTIFIER, 'using'), $stream, $parser); $node = new TagNode($this, ['template' => $this->parseClass($parser, $stream, $parentTemplate)]); $node->addChild($environmentNode, 'environment'); $node->addChild($contextNode, 'context'); return $node; }
public function parse(Parser $parser, Stream $stream) { if ($stream->nextTokenIf(Token::IDENTIFIER, 'all')) { $stream->expect(Token::IDENTIFIER, 'from'); } else { $blocks = $parser->parseExpression($stream); $stream->expectCurrent(Token::IDENTIFIER, 'from'); } $arguments = [$parser->parseExpression($stream)]; if (isset($blocks)) { $arguments[] = $blocks; } return new ExpressionNode($this->helper->createMethodCallNode(new VariableNode('_self'), 'importBlocks', $arguments)); }
public function parse(Parser $parser, Stream $stream) { $templateNameToken = $stream->expect(Token::IDENTIFIER); $templateName = $templateNameToken->getValue(); $stream->expect(Token::TAG_END); $classNode = $parser->getCurrentClassNode(); if ($classNode->hasChild($templateName)) { throw new ParseException("Block {$templateName} is already defined", $templateNameToken->getLine()); } $parser->enterBlock($templateName); $classNode->addChild($parser->parseBlock($stream, 'endblock'), $templateName); $stream->expect(Token::TAG_END); $parser->leaveBlock(); return $this->helper->createRenderBlockNode($templateName, new TempVariableNode('context')); }
public function parse(Parser $parser, Stream $stream) { $environment = $parser->getEnvironment(); $node = new TagNode($environment->getTag('for'), ['save_temp_var' => true, 'create_stack' => true, 'variables' => 1]); $node->addChild($parser->parseExpression($stream), 'source'); $temp = $node->addChild(new TempVariableNode('element'), 'loop_variable_0'); $loopBody = $node->addChild(new RootNode(), 'loop_body'); if ($stream->current()->test(Token::IDENTIFIER, 'as')) { $arrayNode = new ArrayNode(); $arrayNode->add($temp, new DataNode($stream->expect(Token::VARIABLE)->getValue())); $setOperator = $parser->getEnvironment()->getBinaryOperators()->getOperator(':'); $varNode = $setOperator->createNode($temp, $arrayNode); $loopBody->addChild(new ExpressionNode($varNode)); $stream->next(); } $stream->expectCurrent(Token::IDENTIFIER, 'using'); $loopBody->addChild($this->helper->createRenderFunctionNode($parser->parseExpression($stream), $temp)); return $node; }
public function parse(Parser $parser, Stream $stream) { return $this->helper->createRenderBlockNode($stream->expect(Token::IDENTIFIER)->getValue(), $this->helper->createContext($stream->next()->test(Token::IDENTIFIER, 'using'), $stream, $parser)); }
public function parse(Parser $parser, Stream $stream) { return $this->helper->createRenderFunctionNode($parser->parseExpression($stream), $this->helper->createContext($stream->current()->test(Token::IDENTIFIER, 'using'), $stream, $parser)); }