Exemplo n.º 1
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 = '';
     $children = $node->getChildren();
     foreach ($children as $i => $child) {
         if (!empty($html) && !empty($last)) {
             $html .= "\n";
         }
         $this->nextIsIf[$level] = isset($children[$i + 1]) && $children[$i + 1] instanceof CodeNode;
         $last = $this->dumpNode($child, $level);
         $html .= $last;
     }
     return $html;
 }
Exemplo n.º 2
0
 /**
  * Parse indented block token.
  *
  * @return  BlockNode
  */
 protected function parseBlock()
 {
     $node = new BlockNode($this->lexer->getCurrentLine());
     $this->expectTokenType('indent');
     while ($this->lexer->predictToken()->type !== 'outdent') {
         if ($this->lexer->predictToken()->type === 'newline') {
             $this->lexer->getAdvancedToken();
         } else {
             $node->addChild($this->parseExpression());
         }
     }
     $this->expectTokenType('outdent');
     return $node;
 }