88use TypeLang \PHPDoc \DocBlock \Tag \Factory \MutableTagFactoryInterface ;
99use TypeLang \PHPDoc \DocBlock \Tag \Factory \TagFactory ;
1010use TypeLang \PHPDoc \DocBlock \Tag \Factory \TagFactoryInterface ;
11- use TypeLang \PHPDoc \DocBlock \Tag \MethodTag \MethodTagFactory ;
12- use TypeLang \PHPDoc \DocBlock \Tag \ParamTag \ParamTagFactory ;
13- use TypeLang \PHPDoc \DocBlock \Tag \PropertyTag \PropertyReadTagFactory ;
14- use TypeLang \PHPDoc \DocBlock \Tag \PropertyTag \PropertyTagFactory ;
15- use TypeLang \PHPDoc \DocBlock \Tag \PropertyTag \PropertyWriteTagFactory ;
16- use TypeLang \PHPDoc \DocBlock \Tag \ReturnTag \ReturnTagFactory ;
17- use TypeLang \PHPDoc \DocBlock \Tag \TemplateExtendsTag \TemplateExtendsTagFactory ;
18- use TypeLang \PHPDoc \DocBlock \Tag \TemplateExtendsTag \TemplateImplementsTagFactory ;
19- use TypeLang \PHPDoc \DocBlock \Tag \TemplateTag \TemplateCovariantTagFactory ;
20- use TypeLang \PHPDoc \DocBlock \Tag \TemplateTag \TemplateTagFactory ;
21- use TypeLang \PHPDoc \DocBlock \Tag \ThrowsTag \ThrowsTagFactory ;
22- use TypeLang \PHPDoc \DocBlock \Tag \VarTag \VarTagFactory ;
2311use TypeLang \PHPDoc \Exception \ParsingException ;
2412use TypeLang \PHPDoc \Exception \RuntimeExceptionInterface ;
2513use TypeLang \PHPDoc \Parser \Comment \CommentParserInterface ;
3018use TypeLang \PHPDoc \Parser \SourceMap ;
3119use TypeLang \PHPDoc \Parser \Tag \RegexTagParser ;
3220use TypeLang \PHPDoc \Parser \Tag \TagParserInterface ;
21+ use TypeLang \PHPDoc \Platform \PlatformInterface ;
22+ use TypeLang \PHPDoc \Platform \StandardPlatform ;
3323
3424class Parser implements ParserInterface
3525{
@@ -41,36 +31,28 @@ class Parser implements ParserInterface
4131
4232 private readonly MutableTagFactoryInterface $ factories ;
4333
44- /**
45- * @param iterable<non-empty-string, TagFactoryInterface>|null $tags
46- */
47- public function __construct (?iterable $ tags = null )
34+ public function __construct (
35+ public readonly PlatformInterface $ platform = new StandardPlatform (),
36+ ) {
37+ $ this ->factories = new TagFactory ($ platform ->getTags ());
38+ $ this ->tags = $ this ->createTagParser ($ this ->factories );
39+ $ this ->descriptions = $ this ->createDescriptionParser ($ this ->tags );
40+ $ this ->comments = $ this ->createCommentParser ();
41+ }
42+
43+ protected function createTagParser (TagFactoryInterface $ factories ): TagParserInterface
4844 {
49- $ this ->factories = new TagFactory ($ tags ?? self ::createDefaultTags ());
50- $ this ->tags = new RegexTagParser ($ this ->factories );
51- $ this ->descriptions = new RegexDescriptionParser ($ this ->tags );
52- $ this ->comments = new RegexCommentParser ();
45+ return new RegexTagParser ($ factories );
5346 }
5447
55- /**
56- * @return iterable<non-empty-string, TagFactoryInterface>
57- */
58- private static function createDefaultTags (): iterable
48+ protected function createDescriptionParser (TagParserInterface $ tags ): DescriptionParserInterface
49+ {
50+ return new RegexDescriptionParser ($ tags );
51+ }
52+
53+ protected function createCommentParser (): CommentParserInterface
5954 {
60- yield 'method ' => new MethodTagFactory ();
61- yield 'param ' => new ParamTagFactory ();
62- yield 'property ' => new PropertyTagFactory ();
63- yield 'property-read ' => new PropertyReadTagFactory ();
64- yield 'property-write ' => new PropertyWriteTagFactory ();
65- yield 'return ' => new ReturnTagFactory ();
66- yield 'throws ' => new ThrowsTagFactory ();
67- yield 'var ' => new VarTagFactory ();
68- yield 'template ' => new TemplateTagFactory ();
69- yield 'template-implements ' => $ implements = new TemplateImplementsTagFactory ();
70- yield 'implements ' => $ implements ;
71- yield 'template-extends ' => $ extends = new TemplateExtendsTagFactory ();
72- yield 'extends ' => $ extends ;
73- yield 'template-covariant ' => new TemplateCovariantTagFactory ();
55+ return new RegexCommentParser ();
7456 }
7557
7658 /**
0 commit comments