/** * Compiles haml from an array of lines. * * @param array $rawLines */ public function parseLines(array $rawLines = array()) { $this->_currLine = 0; $this->_lines = $rawLines; // $this->removeEmptyLines($rawLines); $rootNode = new RootNode(); $rootNode->setCompiler($this); $rootNode->setLineNumber(0); $nodeFactory = $this->_hamlphp->getNodeFactory(); $filterContext = false; $filterIndentLevel = 0; $filterNode = null; for ($len = count($this->_lines); $this->_currLine < $len; ++$this->_currLine) { $currLine = $this->_lines[$this->_currLine]; try { if ($this->getIndentLevel($currLine) <= $filterIndentLevel) { $filterContext = false; } if ($filterContext) { $nd = new HamlNode($currLine); $filterNode->addNode($nd); } else { if (trim($currLine) == '') { continue; } $nd = $nodeFactory->createNode($currLine, $this->_currLine, $this); if ($nd instanceof FilterNode) { if ($filterContext) { throw new SyntaxErrorException('You cannot nest filters.'); } $filterContext = true; $filterNode = $nd; $filterIndentLevel = $this->getIndentLevel($currLine); } $rootNode->addNode($nd); } } catch (Exception $e) { throw new SyntaxErrorException("Error parsing line:\n{$currLine}\n" . $e->getMessage(), $e->getCode()); } } return $rootNode->render(); }