public function parse($comment, $context) { $annotations = ['params' => [], 'returns' => [], 'vars' => []]; $lexer = new DocLexer(); $lexer->setInput($comment); while (true) { $lexer->moveNext(); $lexer->skipUntil(DocLexer::T_AT); if ($lexer->lookahead === null) { break; } if ($a = $this->parseReturnComment($lexer, $context)) { $annotations['returns'][] = $a; } if ($a = $this->parseParamComment($lexer, $context)) { $annotations['params'][] = $a; } if ($a = $this->parseVarComment($lexer, $context)) { $annotations['vars'][] = $a; } } if (count($annotations['returns']) > 1) { throw AnnotationException::semanticalError("Duplicated return: {$context}"); } if (count($annotations['vars']) > 1) { throw AnnotationException::semanticalError("Duplicated var: {$context}"); } return $annotations; }