public function parse(\Twig_Token $token) { $lineno = $token->getLine(); $stream = $this->parser->getStream(); // 'svg' $name = $stream->expect(\Twig_Token::STRING_TYPE)->getValue(); // %} (from {% stamp %}) $stream->expect(\Twig_Token::BLOCK_END_TYPE); $aboveDumps = []; while (true) { // everything above {% stamp_dump %} $aboveDumps[] = $this->parser->subparse(function (\Twig_Token $token) { return $token->test('stamp_dump'); }); // allow nested {% stamp %} usage using distinct names $dumpName = $stream->next() && $stream->expect(\Twig_Token::STRING_TYPE)->getValue(); if ($dumpName == $name) { break; } } // %} (from {% stamp_dump %}) $stream->expect(\Twig_Token::BLOCK_END_TYPE); // everything below {% stamp_dump %} $belowDump = $this->parser->subparse(function (\Twig_Token $token) { return $token->test('endstamp'); }); // %} (from {% endstamp %}) $stream->next() && $stream->expect(\Twig_Token::BLOCK_END_TYPE); return new StampNode($name, $aboveDumps, $belowDump, $lineno, $this->getTag()); }
/** * {@inheritdoc} */ public function parse(\Twig_Token $token) { $lineno = $token->getLine(); $stream = $this->parser->getStream(); $name = $stream->expect(\Twig_Token::STRING_TYPE)->getValue(); $options = []; while (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) { if (!$stream->test(\Twig_Token::NAME_TYPE)) { $this->throwSyntaxError($stream); } $key = $stream->getCurrent()->getValue(); $stream->next(); if (!$stream->test(\Twig_Token::OPERATOR_TYPE, '=')) { $options[$key] = true; continue; } $stream->next(); if (!$this->testOptionValue($stream)) { $this->throwSyntaxError($stream); } $options[$key] = $this->getOptionValue($stream); $stream->next(); } $stream->next(); $body = $this->parser->subparse(function (\Twig_Token $token) { return $token->test(['endcontenteditable']); }, true); if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) { throw new \Twig_Error_Syntax('A text inside a contenteditable tag must be a simple text.', $body->getLine(), $stream->getFilename()); } $stream->expect(\Twig_Token::BLOCK_END_TYPE); return new ContentEditableNode(['body' => $body], ['name' => $name, 'options' => $options], $lineno, $this->getTag()); }
/** * @see Twig_TokenParserInterface::parse() */ public function parse(\Twig_Token $token) { $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE); $body = $this->parser->subparse(function (\Twig_Token $token) { return $token->test('endmarkdown'); }, true); $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE); return new TwigMarkdownNode($body, $token->getLine(), $this->getTag()); }
public function parse(\Twig_Token $token) { $lineno = $token->getLine(); $stream = $this->parser->getStream(); // key, item in items $targets = $this->parser->getExpressionParser()->parseAssignmentExpression(); $stream->expect(\Twig_Token::OPERATOR_TYPE, 'in'); $seq = $this->parser->getExpressionParser()->parseExpression(); // as treeA $as = 'default'; if ($stream->nextIf(\Twig_Token::NAME_TYPE, 'as')) { $as = $stream->expect(\Twig_Token::NAME_TYPE)->getValue(); } // %} $stream->expect(\Twig_Token::BLOCK_END_TYPE); $data = array(); while (true) { // backing up tag content $data[] = array('type' => 'body', 'node' => $this->parser->subparse(function (\Twig_Token $token) { return $token->test(array('subtree', 'endtree')); })); // {% subtree if ($stream->next()->getValue() == 'subtree') { // item $child = $this->parser->getExpressionParser()->parseExpression(); // with treeA $with = $as; if ($stream->nextIf(\Twig_Token::NAME_TYPE, 'with')) { $with = $stream->expect(\Twig_Token::NAME_TYPE)->getValue(); } // %} $stream->expect(\Twig_Token::BLOCK_END_TYPE); // backing up subtree details $data[] = array('type' => 'subtree', 'with' => $with, 'child' => $child); // {% endtree } else { // %} $stream->expect(\Twig_Token::BLOCK_END_TYPE); break; } } // key, item if (count($targets) > 1) { $keyTarget = $targets->getNode(0); $keyTarget = new \Twig_Node_Expression_AssignName($keyTarget->getAttribute('name'), $keyTarget->getLine()); $valueTarget = $targets->getNode(1); $valueTarget = new \Twig_Node_Expression_AssignName($valueTarget->getAttribute('name'), $valueTarget->getLine()); // (implicit _key,) item } else { $keyTarget = new \Twig_Node_Expression_AssignName('_key', $lineno); $valueTarget = $targets->getNode(0); $valueTarget = new \Twig_Node_Expression_AssignName($valueTarget->getAttribute('name'), $valueTarget->getLine()); } return new TreeNode($keyTarget, $valueTarget, $seq, $as, $data, $lineno, $this->getTag()); }
/** * Разбирает выражение * * @param TwigToken $token Токен. * * @return WhileNode */ public function parse(TwigToken $token) { $lineNumber = $token->getLine(); $condition = $this->parser->getExpressionParser()->parseExpression(); $stream = $this->parser->getStream(); $stream->expect(TwigToken::BLOCK_END_TYPE); $callback = function (TwigToken $token) { return $token->test(['endwhile']); }; $body = $this->parser->subparse($callback, true); $stream->expect(TwigToken::BLOCK_END_TYPE); return new WhileNode($condition, $body, $lineNumber, $this->getTag()); }
public function decideBlockEnd(Twig_Token $token) { return $token->test('endfilter'); }
public function testEndTag(\Twig_Token $token) { return $token->test(array('end' . $this->getTag())); }
public function decideForEnd(Twig_Token $token) { return $token->test('endfor'); }
public function decideBlockEnd(Twig_Token $token) { return $token->test('endautoescape'); }
/** * @param \Twig_Token $token * * @return bool */ public function decideCacheEnd(\Twig_Token $token) { return $token->test('endcache'); }
/** * @param \Twig_Token $token * * @return bool */ public function decideNavEnd(\Twig_Token $token) { return $token->test('endnav'); }
public function decideMarkdownEnd(Twig_Token $token) { return $token->test('endmarkdown'); }
/** * @param Twig_Token $token * @return bool */ public function decideHmacEnd(\Twig_Token $token) { return $token->test('endhmac'); }
public function decideWithEnd(Twig_Token $token) { return $token->test('endwith'); }
public function decideStopwatchEnd(\Twig_Token $token) { return $token->test('endstopwatch'); }
public function decideIfEnd(Twig_Token $token) { return $token->test(array('endif')); }
/** * @param \Twig_Token $token * * @return bool */ public function decideEnd(\Twig_Token $token) { return $token->test('endcontainer'); }
/** * Test for end tag * * @param \Twig_Token $token * * @return bool */ public function testEndTag(\Twig_Token $token) { return $token->test(['end' . $this->tag]); }
public function decideGimmeListFork(\Twig_Token $token) { return $token->test(['else', 'endgimmelist']); }
public function decideBlockEnd(\Twig_Token $token) { return $token->test('endassets'); }
/** * Define how a page tag ends. Returns `endpage`. * * * @param \Twig_Token $token An instance of a \Twig_Token. * * @return string */ public function endOfTag(\Twig_Token $token) { return $token->test('endpage'); }
public function decideEnd(\Twig_Token $token) { return $token->test(array('endtry')); }
public function decideSpacelessEnd(Twig_Token $token) { return $token->test('endspaceless'); }
public function decideBlockEnd(\Twig_Token $token) { return $token->test('end_ui_sections'); }
/** * @param \Twig_Token $token * * @return bool */ public function decideRoleEnd(\Twig_Token $token) { return $token->test('endrole'); }
public function decideCSPScriptEnd(\Twig_Token $token) { return $token->test('end' . $this->tag); }
public function decideBlockEnd(Twig_Token $token) { return $token->test('endsandbox'); }
public function decideBlockEnd(\Twig_Token $token) { return $token->test('ENDDEFINE'); }
protected function isBinary(Twig_Token $token) { return $token->test(Twig_Token::OPERATOR_TYPE) && isset($this->binaryOperators[$token->getValue()]); }
public function decideIfVariant(\Twig_Token $token) { return $token->test(array('variant', 'endab')); }