示例#1
0
 /**
  * @return Annotation|false
  */
 private static function parseLine($line)
 {
     if (empty($line) || $line[0] !== '@') {
         return false;
     }
     $annotationName = '';
     $annotationAttrs = array();
     $state = State::START;
     for ($i = 0, $len = strlen($line); $i < $len && $state != State::END; $i++) {
         $c = $line[$i];
         switch ($state) {
             case State::START:
                 $state = Lexer::isAnnotationMarker($c) ? State::NAME : State::NOTANNOTATION;
                 break;
             case State::NAME:
                 $p = self::getName($line, $len, $i);
                 if ($p == -1) {
                     $state = State::NOTANNOTATION;
                 } else {
                     $annotationName = substr($line, $i, $p);
                     $state = State::BEFOREBODY;
                     $i += $p - 1;
                 }
                 break;
             case State::NOTANNOTATION:
                 return false;
             case State::BEFOREBODY:
                 if (Lexer::isAttributesListStart($c)) {
                     $p = self::getBraketsBlock($line, $len, $i, $c);
                     if ($p != -1) {
                         $block = substr($line, $i, $p);
                         $i += $p - 1;
                         $annotationAttrs = self::getAttributes($block);
                     } else {
                         throw new ErrorException("Error parsing {$annotationName} annotation attributes");
                     }
                 }
                 if (Lexer::isSpace($c)) {
                     continue;
                 }
                 $state = State::END;
                 break;
             default:
                 throw new RuntimeException("Wrong state: {$state}");
         }
     }
     return new Annotation($annotationName, $annotationAttrs);
 }