/** * Performs checking on the parse result. * * The method will check if there are more text after the current cursor * location and if so appends a new ezcTextElement object containing the * text. * * It also checks if the $lastBlock contains the current program parser, if it * does not it means the nesting in the current source code is incorrect. * * @param ezcTemplateCursor $lastCursor * @param ezcTemplateCursor $cursor * * @throws ezcTemplateParserException if blocks are incorrectly nested. * * @return void */ protected function handleSuccessfulResult(ezcTemplateCursor $lastCursor, ezcTemplateCursor $cursor) { if ($lastCursor->length($cursor) > 0) { $textElement = new ezcTemplateTextBlockTstNode($this->parser->source, clone $lastCursor, clone $cursor); $this->handleElements(array($textElement)); } if ($this->lastBlock === null) { throw new ezcTemplateInternalException("lastBlock is null, should have been a parser element object."); } if (!$this->lastBlock instanceof ezcTemplateProgramTstNode) { $parents = array(); // Calculate level of the last block, this used to indent the last block $level = 0; $block = $this->lastBlock; while ($block->parentBlock !== null && !$block->parentBlock instanceof ezcTemplateProgramTstNode) { if ($block === $block->parentBlock) { throw new ezcTemplateInternalException("Infinite recursion found in parser element " . get_class($block)); } ++$level; $block = $block->parentBlock; } $block = $this->lastBlock; // Go trough all parents until the root is reached while ($block->parentBlock !== null && !$block->parentBlock instanceof ezcTemplateProgramTstNode) { if ($block === $block->parentBlock) { throw new ezcTemplateInternalException("Infinite recursion found in parser element " . get_class($block)); } $block = $block->parentBlock; --$level; $parents[] = str_repeat(" ", $level) . "{" . $block->name . "} @ {$block->startCursor->line}:{$block->startCursor->column}:"; } $parents = array_reverse($parents); $treeText = "The current nesting structure:\n" . join("\n", $parents); throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $this->currentCursor, "Incorrect nesting in code, close block {/" . $this->lastBlock->name . "} expected."); } // Get rid of whitespace for the block line of the program element $this->parser->trimBlockLine($this->program); }