예제 #1
0
 /**
  * Parses the comment by looking for the end marker \n.
  *
  * @param ezcTemplateCursor $cursor
  * @return bool
  */
 protected function parseCurrent(ezcTemplateCursor $cursor)
 {
     $cutOff = false;
     if (!$cursor->atEnd()) {
         $cursor->advance(2);
         $matches = $cursor->pregMatchComplete("#^([^}\r\n]*)(?:(?:})|(\r|\r\n|\n))#");
         if ($matches) {
             // reached end of comment
             $cutOff = false;
             if (isset($matches[2])) {
                 $cursor->advance($matches[2][1] + strlen($matches[2][0]));
                 // Do not include the newline itself in the comment.
                 $cutOff = -1;
             } else {
                 $cursor->advance($matches[1][1] + strlen($matches[1][0]));
             }
         } else {
             $cursor->gotoEnd();
         }
         $commentBlock = new ezcTemplateEolCommentTstNode($this->parser->source, $this->startCursor, clone $cursor);
         if ($cutOff) {
             $commentBlock->commentText = substr($commentBlock->text(), 2, $cutOff);
         } else {
             $commentBlock->commentText = substr($commentBlock->text(), 2);
         }
         $this->appendElement($commentBlock);
         return true;
     }
     return false;
 }
예제 #2
0
 /**
  * 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;
 }