protected function Twig_Parser::filterBodyNodes

2 calls to Twig_Parser::filterBodyNodes()
TestParser::filterBodyNodes in drupal/core/vendor/twig/twig/test/Twig/Tests/ParserTest.php
Twig_Parser::parse in drupal/core/vendor/twig/twig/lib/Twig/Parser.php
Converts a token stream to a node tree.
1 method overrides Twig_Parser::filterBodyNodes()
TestParser::filterBodyNodes in drupal/core/vendor/twig/twig/test/Twig/Tests/ParserTest.php

File

drupal/core/vendor/twig/twig/lib/Twig/Parser.php, line 352

Class

Twig_Parser
Default parser implementation.

Code

protected function filterBodyNodes(Twig_NodeInterface $node) {

  // check that the body does not contain non-empty output nodes
  if ($node instanceof Twig_Node_Text && !ctype_space($node
    ->getAttribute('data')) || !$node instanceof Twig_Node_Text && !$node instanceof Twig_Node_BlockReference && $node instanceof Twig_NodeOutputInterface) {
    if (false !== strpos((string) $node, chr(0xef) . chr(0xbb) . chr(0xbf))) {
      throw new Twig_Error_Syntax('A template that extends another one cannot have a body but a byte order mark (BOM) has been detected; it must be removed.', $node
        ->getLine(), $this->stream
        ->getFilename());
    }
    throw new Twig_Error_Syntax('A template that extends another one cannot have a body.', $node
      ->getLine(), $this->stream
      ->getFilename());
  }

  // bypass "set" nodes as they "capture" the output
  if ($node instanceof Twig_Node_Set) {
    return $node;
  }
  if ($node instanceof Twig_NodeOutputInterface) {
    return;
  }
  foreach ($node as $k => $n) {
    if (null !== $n && null === ($n = $this
      ->filterBodyNodes($n))) {
      $node
        ->removeNode($k);
    }
  }
  return $node;
}