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