public function testMarkerAnnotation()
 {
     $lexer = new DocLexer();
     $lexer->setInput("@Name");
     $this->assertNull($lexer->token);
     $this->assertNull($lexer->lookahead);
     $this->assertTrue($lexer->moveNext());
     $this->assertNull($lexer->token);
     $this->assertEquals('@', $lexer->lookahead['value']);
     $this->assertTrue($lexer->moveNext());
     $this->assertEquals('@', $lexer->token['value']);
     $this->assertEquals('Name', $lexer->lookahead['value']);
     $this->assertFalse($lexer->moveNext());
 }
Example #2
0
 public function testScannerTokenizesDocBlockWhitInvalidIdentifier()
 {
     $lexer = new DocLexer();
     $docblock = '@Foo\\3.42';
     $tokens = array(array('value' => '@', 'position' => 0, 'type' => DocLexer::T_AT), array('value' => 'Foo', 'position' => 1, 'type' => DocLexer::T_IDENTIFIER), array('value' => '\\', 'position' => 4, 'type' => DocLexer::T_NAMESPACE_SEPARATOR), array('value' => 3.42, 'position' => 5, 'type' => DocLexer::T_FLOAT));
     $lexer->setInput($docblock);
     foreach ($tokens as $expected) {
         $lexer->moveNext();
         $lookahead = $lexer->lookahead;
         $this->assertEquals($expected['value'], $lookahead['value']);
         $this->assertEquals($expected['type'], $lookahead['type']);
         $this->assertEquals($expected['position'], $lookahead['position']);
     }
     $this->assertFalse($lexer->moveNext());
 }
Example #3
0
 /**
  * @group 44
  */
 public function testRecognizesDoubleQuotesEscapeSequence()
 {
     $lexer = new DocLexer();
     $docblock = '@Foo("""' . "\n" . '""")';
     $tokens = array(array('value' => '@', 'position' => 0, 'type' => DocLexer::T_AT), array('value' => 'Foo', 'position' => 1, 'type' => DocLexer::T_IDENTIFIER), array('value' => '(', 'position' => 4, 'type' => DocLexer::T_OPEN_PARENTHESIS), array('value' => "\"\n\"", 'position' => 5, 'type' => DocLexer::T_STRING), array('value' => ')', 'position' => 12, 'type' => DocLexer::T_CLOSE_PARENTHESIS));
     $lexer->setInput($docblock);
     foreach ($tokens as $expected) {
         $lexer->moveNext();
         $lookahead = $lexer->lookahead;
         $this->assertEquals($expected['value'], $lookahead['value']);
         $this->assertEquals($expected['type'], $lookahead['type']);
         $this->assertEquals($expected['position'], $lookahead['position']);
     }
     $this->assertFalse($lexer->moveNext());
 }
 /**
  * Matches any one of the tokens and advances.
  *
  * @param array $tokens The list of tokens.
  *
  * @return boolean TRUE if the next token matches, FALSE if not.
  *
  * @throws Exception
  * @throws SyntaxException If a syntax error is found.
  */
 private function matchAny(array $tokens)
 {
     if (!$this->lexer->isNextTokenAny($tokens)) {
         throw SyntaxException::expectedToken(implode(' or ', array_map(array($this->lexer, 'getLiteral'), $tokens)), null, $this->lexer);
     }
     return $this->lexer->moveNext();
 }
Example #5
0
 private function parseDocComment(DocLexer $lexer, $symbol, $repeatCount)
 {
     $lexer->resetPeek();
     if (($token = $lexer->peek()) === null) {
         return false;
     }
     if ($token['type'] !== DocLexer::T_IDENTIFIER || $token['value'] !== $symbol) {
         return false;
     }
     $ids = [];
     $tk = $lexer->peek();
     while ($repeatCount-- > 0) {
         if ($tk === null || $tk['type'] !== DocLexer::T_IDENTIFIER) {
             return false;
         }
         $tks = [$tk['value']];
         while (($tk = $lexer->peek()) && $tk['type'] === DocLexer::T_NONE && in_array($tk['value'], ['[', ']'])) {
             $tks[] = $tk['value'];
         }
         $ids[] = implode('', $tks);
     }
     return $ids;
 }
Example #6
0
 /**
  * ArrayEntry ::= Value | KeyValuePair
  * KeyValuePair ::= Key ("=" | ":") PlainValue | Constant
  * Key ::= string | integer | Constant
  *
  * @return array
  */
 private function ArrayEntry()
 {
     $peek = $this->lexer->glimpse();
     if (DocLexer::T_EQUALS === $peek['type'] || DocLexer::T_COLON === $peek['type']) {
         if ($this->lexer->isNextToken(DocLexer::T_IDENTIFIER)) {
             $key = $this->Constant();
         } else {
             $this->matchAny(array(DocLexer::T_INTEGER, DocLexer::T_STRING));
             $key = $this->lexer->token['value'];
         }
         $this->matchAny(array(DocLexer::T_EQUALS, DocLexer::T_COLON));
         return array($key, $this->PlainValue());
     }
     return array(null, $this->Value());
 }
Example #7
0
 /**
  * @group performance
  */
 public function testDocLexerPerformance()
 {
     $method = $this->getMethod();
     $methodComment = $method->getDocComment();
     $classComment = $method->getDeclaringClass()->getDocComment();
     $time = microtime(true);
     for ($i = 0, $c = 500; $i < $c; $i++) {
         $lexer = new DocLexer();
         $lexer->setInput($methodComment);
         $lexer->setInput($classComment);
     }
     $time = microtime(true) - $time;
     $this->printResults('doc-lexer', $time, $c);
 }