Ejemplo n.º 1
0
 /**
  * Parse indented block token. 
  * 
  * @return  BlockNode
  */
 protected function parseBlock()
 {
     $node = new BlockNode($this->lexer->getCurrentLine());
     $this->expectTokenType('indent');
     while ('outdent' !== $this->lexer->predictToken()->type) {
         if ('newline' === $this->lexer->predictToken()->type) {
             $this->lexer->getAdvancedToken();
         } else {
             $node->addChild($this->parseExpression());
         }
     }
     $this->expectTokenType('outdent');
     return $node;
 }
Ejemplo n.º 2
0
 /**
  * Dump block node to string. 
  * 
  * @param   BlockNode   $node   block node
  * @param   integer     $level  indentation level
  *
  * @return  string
  */
 protected function dumpBlock(BlockNode $node, $level = 0)
 {
     $html = '';
     $last = '';
     $childs = $node->getChilds();
     foreach ($childs as $i => $child) {
         if (!empty($html) && !empty($last)) {
             $html .= "\n";
         }
         $this->nextExtendsIf[$level] = isset($childs[$i + 1]) && $childs[$i + 1] instanceof CodeNode && preg_match($this->nextExtendsIfRegexp, $childs[$i + 1]->getCode());
         $last = $this->dumpNode($child, $level);
         $html .= $last;
     }
     return $html;
 }