@@ -30,23 +30,24 @@ class Lexer
3030 public const TOKEN_OPEN_PHPDOC = 15 ;
3131 public const TOKEN_CLOSE_PHPDOC = 16 ;
3232 public const TOKEN_PHPDOC_TAG = 17 ;
33- public const TOKEN_FLOAT = 18 ;
34- public const TOKEN_INTEGER = 19 ;
35- public const TOKEN_SINGLE_QUOTED_STRING = 20 ;
36- public const TOKEN_DOUBLE_QUOTED_STRING = 21 ;
37- public const TOKEN_IDENTIFIER = 22 ;
38- public const TOKEN_THIS_VARIABLE = 23 ;
39- public const TOKEN_VARIABLE = 24 ;
40- public const TOKEN_HORIZONTAL_WS = 25 ;
41- public const TOKEN_PHPDOC_EOL = 26 ;
42- public const TOKEN_OTHER = 27 ;
43- public const TOKEN_END = 28 ;
44- public const TOKEN_COLON = 29 ;
45- public const TOKEN_WILDCARD = 30 ;
46- public const TOKEN_OPEN_CURLY_BRACKET = 31 ;
47- public const TOKEN_CLOSE_CURLY_BRACKET = 32 ;
48- public const TOKEN_NEGATED = 33 ;
49- public const TOKEN_ARROW = 34 ;
33+ public const TOKEN_DOCTRINE_TAG = 18 ;
34+ public const TOKEN_FLOAT = 19 ;
35+ public const TOKEN_INTEGER = 20 ;
36+ public const TOKEN_SINGLE_QUOTED_STRING = 21 ;
37+ public const TOKEN_DOUBLE_QUOTED_STRING = 22 ;
38+ public const TOKEN_IDENTIFIER = 23 ;
39+ public const TOKEN_THIS_VARIABLE = 24 ;
40+ public const TOKEN_VARIABLE = 25 ;
41+ public const TOKEN_HORIZONTAL_WS = 26 ;
42+ public const TOKEN_PHPDOC_EOL = 27 ;
43+ public const TOKEN_OTHER = 28 ;
44+ public const TOKEN_END = 29 ;
45+ public const TOKEN_COLON = 30 ;
46+ public const TOKEN_WILDCARD = 31 ;
47+ public const TOKEN_OPEN_CURLY_BRACKET = 32 ;
48+ public const TOKEN_CLOSE_CURLY_BRACKET = 33 ;
49+ public const TOKEN_NEGATED = 34 ;
50+ public const TOKEN_ARROW = 35 ;
5051
5152 public const TOKEN_LABELS = [
5253 self ::TOKEN_REFERENCE => '\'& \'' ,
@@ -72,6 +73,7 @@ class Lexer
7273 self ::TOKEN_OPEN_PHPDOC => '\'/** \'' ,
7374 self ::TOKEN_CLOSE_PHPDOC => '\'*/ \'' ,
7475 self ::TOKEN_PHPDOC_TAG => 'TOKEN_PHPDOC_TAG ' ,
76+ self ::TOKEN_DOCTRINE_TAG => 'TOKEN_DOCTRINE_TAG ' ,
7577 self ::TOKEN_PHPDOC_EOL => 'TOKEN_PHPDOC_EOL ' ,
7678 self ::TOKEN_FLOAT => 'TOKEN_FLOAT ' ,
7779 self ::TOKEN_INTEGER => 'TOKEN_INTEGER ' ,
@@ -90,9 +92,17 @@ class Lexer
9092 public const TYPE_OFFSET = 1 ;
9193 public const LINE_OFFSET = 2 ;
9294
95+ /** @var bool */
96+ private $ parseDoctrineAnnotations ;
97+
9398 /** @var string|null */
9499 private $ regexp ;
95100
101+ public function __construct (bool $ parseDoctrineAnnotations = false )
102+ {
103+ $ this ->parseDoctrineAnnotations = $ parseDoctrineAnnotations ;
104+ }
105+
96106 /**
97107 * @return list<array{string, int, int}>
98108 */
@@ -166,11 +176,15 @@ private function generateRegexp(): string
166176 self ::TOKEN_DOUBLE_QUOTED_STRING => '"(?: \\\\[^ \\r \\n]|[^" \\r \\n \\\\])*+" ' ,
167177
168178 self ::TOKEN_WILDCARD => '\\* ' ,
169-
170- // anything but TOKEN_CLOSE_PHPDOC or TOKEN_HORIZONTAL_WS or TOKEN_EOL
171- self ::TOKEN_OTHER => '(?:(?! \\*/)[^ \\s])++ ' ,
172179 ];
173180
181+ if ($ this ->parseDoctrineAnnotations ) {
182+ $ patterns [self ::TOKEN_DOCTRINE_TAG ] = '@[a-z_ \\\\][a-z0-9_\: \\\\]*[a-z_][a-z0-9_]* ' ;
183+ }
184+
185+ // anything but TOKEN_CLOSE_PHPDOC or TOKEN_HORIZONTAL_WS or TOKEN_EOL
186+ $ patterns [self ::TOKEN_OTHER ] = '(?:(?! \\*/)[^ \\s])++ ' ;
187+
174188 foreach ($ patterns as $ type => &$ pattern ) {
175189 $ pattern = '(?: ' . $ pattern . ')(*MARK: ' . $ type . ') ' ;
176190 }
0 commit comments