public function parse(Parser $parser, Stream $stream) { if ($stream->nextTokenIf(Token::IDENTIFIER)) { $token = $stream->expectCurrent(Token::IDENTIFIER, ['off', 'on', 'auto', 'disabled', 'enabled']); } else { $token = $stream->expect(Token::STRING); } switch ($token->getValue()) { case 'disabled': case 'off': $strategy = 0; break; case 'on': case 'enabled': case 'auto': $strategy = 1; break; default: $strategy = $token->getValue(); break; } $node = new TagNode($this, ['strategy' => $strategy]); $stream->expect(Token::TAG_END); $node->addChild($parser->parseBlock($stream, 'endautofilter'), 'body'); $stream->expect(Token::TAG_END); 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)); }
private function parseConditional() { //Only instantiate ConditionalOperator when there is a possibility of it being used if (!isset($this->conditionalOperator)) { $this->conditionalOperator = new ConditionalOperator(); } $left = $this->operandStack->pop(); // Check whether the current expression is a simplified conditional // expression (expr1 ?: expr3) if (!$this->stream->nextTokenIf(Token::PUNCTUATION, ':')) { $middle = $this->parseExpression(true); $this->stream->expectCurrent(Token::PUNCTUATION, ':'); } else { $middle = null; } $right = $this->parseExpression(true); $this->operandStack->push($this->conditionalOperator->createNode($left, $right, $middle)); }