/** * Annotations ::= Annotation {[ "*" ]* [Annotation]}* * @param $record_doc 记录文档 * @return array */ private function Annotations($record_doc = false) { $annotations = array(); $doc_begin = 0; while (null !== $this->lexer->lookahead) { if (DocLexer::T_AT !== $this->lexer->lookahead['type']) { $this->lexer->moveNext(); continue; } // make sure the @ is preceded by non-catchable pattern if (null !== $this->lexer->token && $this->lexer->lookahead['position'] === $this->lexer->token['position'] + strlen($this->lexer->token['value'])) { $this->lexer->moveNext(); continue; } // make sure the @ is followed by either a namespace separator, or // an identifier token if (null === ($peek = $this->lexer->glimpse()) || DocLexer::T_NAMESPACE_SEPARATOR !== $peek['type'] && !in_array($peek['type'], self::$classIdentifiers, true) || $peek['position'] !== $this->lexer->lookahead['position'] + 1) { $this->lexer->moveNext(); continue; } $doc_end = $this->lexer->lookahead['position']; $this->match(DocLexer::T_AT); $name = $this->Identifier(); $value = $this->MethodCall(); if ($record_doc) { if (($count = count($annotations)) !== 0) { $doc = $this->lexer->getInputUntilPosition($doc_end); $text = substr($doc, $doc_begin); $annotations[$count - 1][1]['doc'] = $text; $text = strstr($text, ')'); $annotations[$count - 1][1]['desc'] = substr($text, 1); } $doc_begin = $doc_end; } $annotations[] = array($name, $value); } if ($record_doc) { if (($count = count($annotations)) !== 0) { $doc = $this->lexer->getInputUntilPosition(0xffff); $text = substr($doc, $doc_begin); $annotations[$count - 1][1]['doc'] = $text; $text = strstr($text, ')'); $annotations[$count - 1][1]['desc'] = substr($text, 1); } } return $annotations; }