public static function parse(ParserInterface $parser) { if ($parser->accept(Token::T_IDENT, 'else')) { $parser->insert(new static()); $parser->advance(); $parser->expect(Token::T_CLOSING_TAG); $parser->advance(); return true; } return false; }
public static function parse(ParserInterface $parser) { if ($parser->accept(Token::T_IDENT, 'for')) { $parser->insert(new static()); $parser->advance(); $parser->traverseUp(); if ($parser->accept(Token::T_VAR)) { // T_VAR as first attribute $parser->insert(new VariableNode($parser->getCurrentToken()->getValue())); $parser->setAttribute(); $parser->advance(); $parser->expect(Token::T_IDENT, 'in'); $parser->advance(); ExpressionNode::parse($parser); $parser->setAttribute(); } elseif ($parser->accept(Token::T_NUMBER)) { // T_NUMBER as first attribute $parser->insert(new NumberNode($parser->getCurrentToken()->getValue())); $parser->setAttribute(); $parser->advance(); $parser->expect(Token::T_IDENT, 'to'); $parser->advance(); if ($parser->expect(Token::T_NUMBER)) { $parser->insert(new NumberNode($parser->getCurrentToken()->getValue())); $parser->setAttribute(); $parser->advance(); if ($parser->accept(Token::T_IDENT, 'as')) { $parser->advance(); $parser->expect(Token::T_VAR); $parser->insert(new VariableNode($parser->getCurrentToken()->getValue())); $parser->setAttribute(); $parser->advance(); } } } $parser->skip(Token::T_CLOSING_TAG); $parser->parseOutsideTag(); $parser->skip(Token::T_OPENING_TAG); $parser->skip(Token::T_IDENT, '/for'); $parser->skip(Token::T_CLOSING_TAG); $parser->traverseDown(); $parser->parseOutsideTag(); return true; } return false; }