/** * Parses the comment by looking for the end marker * + }. * * @param ezcTemplateCursor $cursor * @return bool */ protected function parseCurrent(ezcTemplateCursor $cursor) { $cursor->advance(); if ($cursor->atEnd()) { return false; } $checkInlineComment = false; // Check for a slash after the asterix, this typically means a typo for an inline comment // Better give an error for this to warn the user. if ($cursor->current() == '/') { $checkInlineComment = true; } $endPosition = $cursor->findPosition('*}'); if ($endPosition === false) { return false; } // If we found an end for an inline comment we need to check if there // is an end for an inline comment if ($checkInlineComment) { $commentCursor = $cursor->cursorAt($cursor->position, $endPosition); $commentCursor->advance(); $inlineCommentPosition = $commentCursor->findPosition('*/'); // We found the end of the inline comment, this is most likely a user error if ($inlineCommentPosition !== false) { $cursor->gotoPosition($inlineCommentPosition); return false; } } // reached end of comment $cursor->gotoPosition($endPosition + 2); $commentBlock = new ezcTemplateDocCommentTstNode($this->parser->source, clone $this->startCursor, clone $cursor); $commentBlock->commentText = substr($commentBlock->text(), 2, -2); $this->appendElement($commentBlock); return true; }
/** * Parses the code by looking for start of expression blocks and then * passing control to the block parser (ezcTemplateBlockSourceToTstParser). The * text which is not covered by the block parser will be added as * text elements. * * @param ezcTemplateCursor $cursor * @return bool */ protected function parseCurrent(ezcTemplateCursor $cursor) { $this->program = new ezcTemplateProgramTstNode($this->parser->source, $this->startCursor, $cursor); $this->lastBlock = $this->program; while (!$cursor->atEnd()) { // Find the first block $bracePosition = $cursor->findPosition("{", true); if ($bracePosition === false) { $cursor->gotoEnd(); // This will cause handleSuccessfulResult() to be called return true; } // Reached a block {...} $cursor->gotoPosition($bracePosition); $blockCursor = clone $cursor; $cursor->advance(1); if ($this->lastCursor->length($blockCursor) > 0) { $textElement = new ezcTemplateTextBlockTstNode($this->parser->source, clone $this->lastCursor, clone $blockCursor); $this->handleElements(array($textElement)); unset($textElement); } $this->startCursor->copy($blockCursor); $this->lastCursor->copy($cursor); if (!$this->parseRequiredType('Block', $this->startCursor, false)) { return false; } $this->startCursor->copy($cursor); $elements = $this->lastParser->elements; // Sanity checking to make sure element list does not contain duplicates, // this avoids having infinite recursions $count = count($elements); if ($count > 0) { $offset = 0; while ($offset < $count) { $element = $elements[$offset]; for ($i = $offset + 1; $i < $count; ++$i) { if ($element === $elements[$i]) { throw new ezcTemplateInternalException("Received element list with duplicate objects from parser " . get_class($this->lastParser)); } } ++$offset; } } $this->handleElements($elements); } // This will cause handleSuccessfulResult() to be called return true; }
/** * Parses the comment by looking for the end marker * + /. * * @param ezcTemplateCursor $cursor * @return bool */ protected function parseCurrent(ezcTemplateCursor $cursor) { if (!$cursor->atEnd()) { $cursor->advance(2); $tagPos = $cursor->findPosition('*/'); if ($tagPos !== false) { // reached end of comment $cursor->gotoPosition($tagPos + 2); $commentBlock = new ezcTemplateBlockCommentTstNode($this->parser->source, $this->startCursor, clone $cursor); $commentBlock->commentText = substr($commentBlock->text(), 2, -2); $this->appendElement($commentBlock); return true; } } return false; }
/** * Parses the literal by using the ezcTemplateLiteralParser class. * * @param ezcTemplateCursor $cursor * @return bool */ protected function parseCurrent(ezcTemplateCursor $cursor) { // $cursor will be update as the parser continues $this->block = new ezcTemplateLiteralBlockTstNode($this->parser->source, clone $this->startCursor, $cursor); // skip whitespace and comments if (!$this->findNextElement()) { return false; } $hasClosingMarker = $cursor->current() == '/'; if ($hasClosingMarker) { $closingCursor = clone $cursor; $cursor->advance(); $this->findNextElement(); } $matches = $cursor->pregMatchComplete("#^(literal)(?:[^a-zA-Z0-9_])#"); if ($matches === false) { return false; } $cursor->advance(strlen($matches[1][0])); // skip whitespace and comments if (!$this->findNextElement()) { return false; } // Assume end of first {literal} block if (!$cursor->match("}")) { throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $cursor, ezcTemplateSourceToTstErrorMessages::MSG_EXPECT_CURLY_BRACKET_CLOSE); } if ($hasClosingMarker) { throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $cursor, "Found closing block {/literal} without an opening block."); } $literalTextCursor = clone $cursor; // Start searching for ending literal block. while (!$cursor->atEnd()) { // Find the next block $tagPos = $cursor->findPosition("{"); if ($tagPos === false) { return false; } $tagCursor = clone $cursor; $tagCursor->gotoPosition($tagPos - 1); if ($tagCursor->current() == "\\") { // This means the tag is escaped and should be treated as text. $cursor->copy($tagCursor); $cursor->advance(2); unset($tagCursor); continue; } // Reached a block {...} $cursor->gotoPosition($tagPos); $literalTextEndCursor = clone $cursor; $cursor->advance(); $continue = false; while (!$cursor->atEnd()) { // skip whitespace and comments if (!$this->findNextElement()) { return false; } // Check for end, if not continue search if (!$cursor->match('/literal')) { $continue = true; break; } // skip whitespace and comments if (!$this->findNextElement()) { return false; } if ($cursor->current() == '}') { $this->block->textStartCursor = $literalTextCursor; $this->block->textEndCursor = $literalTextEndCursor; $cursor->advance(); $this->block->endCursor = clone $cursor; // Make sure the text is extracted now that the cursor are correct $this->block->storeText(); $this->appendElement($this->block); return true; } } if ($continue) { continue; } } return false; }