예제 #1
0
 protected function _DocBlock(DocblockLexer $lexer, $location, $namespaces)
 {
     $annotations = array();
     while ($lexer->skipToType(DocblockLexer::T_PREAMBLE)) {
         $next = $lexer->next();
         if ($next["type"] !== DocblockLexer::T_AT) {
             // Skip because it doesn't have an annotation at the start
             continue;
         }
         $pos = $lexer->cur();
         try {
             $annotation = $this->_Annotation($lexer, $location, $namespaces);
             $this->_expectNext($lexer, DocblockLexer::$TREAT_AS_WS);
             if (isset($annotation)) {
                 $annotations[$annotation[0]][] = $annotation[1];
             } else {
                 // If not then it parsed fine, but it isn't something we know about
             }
         } catch (\Exception $e) {
             // OK, try starting 1 char after the @ to find the next annotation.
             if ($this->logger) {
                 $this->logger->debug("Skipping syntax error: " . $e->getMessage(), array("exception" => $e));
             }
             $lexer->seek($pos);
             if (!$lexer->next()) {
                 break;
             }
         }
     }
     return $annotations;
 }
예제 #2
0
 /**
  * @covers \Weasel\Annotation\DocblockLexer::seek
  * @covers \Weasel\Annotation\DocblockLexer::cur
  */
 public function testSeek()
 {
     $testIn = '@ 1   \\     true   "foo"  bar';
     $lexer = new DocblockLexer($testIn);
     $this->assertEquals(0, $lexer->cur());
     $cur = $lexer->seek(4);
     $this->assertEquals(4, $lexer->cur());
     $this->assertEquals(DocblockLexer::T_BACKSLASH, $cur["type"]);
     $this->assertEquals($lexer->get(), $cur);
     $cur = $lexer->seek(-3);
     $this->assertEquals(8, $lexer->cur());
     $this->assertEquals(DocblockLexer::T_QUOTED_STRING, $cur["type"]);
     $this->assertEquals($lexer->get(), $cur);
     $this->assertNull($lexer->seek(12));
     $this->assertEquals(8, $lexer->cur());
     $cur = $lexer->seek(0);
     $this->assertEquals(0, $lexer->cur());
     $this->assertEquals(DocblockLexer::T_AT, $cur["type"]);
     $this->assertEquals($lexer->get(), $cur);
 }