@@ -38,143 +38,151 @@ final class TypeExpression
38
38
*
39
39
* @internal
40
40
*/
41
- public const REGEX_TYPES = '(?<types>(?x) # one or several types separated by `|` or `&`
42
- ' .self ::REGEX_TYPE .'
43
- (?:
44
- \h*(?<glue>[|&])\h*
45
- (?&type)
46
- )*+
47
- ) ' ;
48
-
49
- private const REGEX_TYPE = '(?<type>(?x) # single type
50
- (?<nullable>\??\h*)
51
- (?:
52
- (?<array_shape>
53
- (?<array_shape_start>(?i)(?:array|list|object)(?-i)\h*\{\h*)
54
- (?<array_shape_inners>
55
- (?<array_shape_inner>
56
- (?<array_shape_inner_key>(?:(?&constant)|(?&identifier))\h*\??\h*:\h*|)
57
- (?<array_shape_inner_value>(?&types_inner))
41
+ public const REGEX_TYPES = <<<'EOD'
42
+ (?<types>(?x) # one or several types separated by `|` or `&`
43
+
44
+ EOD.self::REGEX_TYPE.<<<'EOD'
45
+
46
+ (?:
47
+ \h*(?<glue>[|&])\h*
48
+ (?&type)
49
+ )*+
50
+ )
51
+ EOD;
52
+
53
+ private const REGEX_TYPE = <<<'EOD'
54
+ (?<type>(?x) # single type
55
+ (?<nullable>\??\h*)
56
+ (?:
57
+ (?<array_shape>
58
+ (?<array_shape_start>(?i)(?:array|list|object)(?-i)\h*\{\h*)
59
+ (?<array_shape_inners>
60
+ (?<array_shape_inner>
61
+ (?<array_shape_inner_key>(?:(?&constant)|(?&identifier))\h*\??\h*:\h*|)
62
+ (?<array_shape_inner_value>(?&types_inner))
63
+ )
64
+ (?:
65
+ \h*,\h*
66
+ (?&array_shape_inner)
67
+ )*
68
+ (?:\h*,\h*)?
69
+ |)
70
+ \h*\}
58
71
)
59
- (?:
60
- \h*,\h*
61
- (?&array_shape_inner)
62
- )*
63
- (?:\h*,\h*)?
64
- |)
65
- \h*\}
66
- )
67
- |
68
- (?<callable> # callable syntax, e.g. `callable(string, int...): bool`
69
- (?<callable_start>(?&name)\h*\(\h*)
70
- (?<callable_arguments>
71
- (?<callable_argument>
72
- (?<callable_argument_type>(?&types_inner))
73
- (?<callable_argument_is_reference>\h*&|)
74
- (?<callable_argument_is_variadic>\h*\.\.\.|)
75
- (?<callable_argument_name>\h*\$(?&identifier)|)
76
- (?<callable_argument_is_optional>\h*=|)
72
+ |
73
+ (?<callable> # callable syntax, e.g. `callable(string, int...): bool`
74
+ (?<callable_start>(?&name)\h*\(\h*)
75
+ (?<callable_arguments>
76
+ (?<callable_argument>
77
+ (?<callable_argument_type>(?&types_inner))
78
+ (?<callable_argument_is_reference>\h*&|)
79
+ (?<callable_argument_is_variadic>\h*\.\.\.|)
80
+ (?<callable_argument_name>\h*\$(?&identifier)|)
81
+ (?<callable_argument_is_optional>\h*=|)
82
+ )
83
+ (?:
84
+ \h*,\h*
85
+ (?&callable_argument)
86
+ )*
87
+ (?:\h*,\h*)?
88
+ |)
89
+ \h*\)
90
+ (?:
91
+ \h*\:\h*
92
+ (?<callable_return>(?&type))
93
+ )?
77
94
)
78
- (?:
79
- \h*,\h*
80
- (?&callable_argument)
81
- )*
82
- (?:\h*,\h*)?
83
- |)
84
- \h*\)
85
- (?:
86
- \h*\:\h*
87
- (?<callable_return>(?&type))
88
- )?
89
- )
90
- |
91
- (?<generic> # generic syntax, e.g.: `array<int, \Foo\Bar>`
92
- (?<generic_start>(?&name)\h*<\h*)
93
- (?<generic_types>
94
- (?&types_inner)
95
- (?:
96
- \h*,\h*
97
- (?&types_inner)
98
- )*
99
- (?:\h*,\h*)?
100
- )
101
- \h*>
102
- )
103
- |
104
- (?<class_constant> # class constants with optional wildcard, e.g.: `Foo::*`, `Foo::CONST_A`, `FOO::CONST_*`
105
- (?&name)::\*?(?:(?&identifier)\*?)*
106
- )
107
- |
108
- (?<constant> # single constant value (case insensitive), e.g.: 1, -1.8E+6, ` \'a \'`
109
- (?i)
110
- # all sorts of numbers: with or without sign, supports literal separator and several numeric systems,
111
- # e.g.: 1, +1.1, 1., .1, -1, 123E+8, 123_456_789, 0x7Fb4, 0b0110, 0o777
112
- [+-]?(?:
113
- (?:0b[01]++(?:_[01]++)*+)
114
- | (?:0o[0-7]++(?:_[0-7]++)*+)
115
- | (?:0x[\da-f]++(?:_[\da-f]++)*+)
116
- | (?:(?<constant_digits>\d++(?:_\d++)*+)|(?=\.\d))
117
- (?:\.(?&constant_digits)|(?<=\d)\.)?+
118
- (?:e[+-]?(?&constant_digits))?+
119
- )
120
- | \'(?:[^ \'\\\\]| \\\\.)*+ \'
121
- | "(?:[^" \\\\]| \\\\.)*+"
122
- (?-i)
123
- )
124
- |
125
- (?<this> # self reference, e.g.: $this, $self, @static
126
- (?i)
127
- [@$](?:this | self | static)
128
- (?-i)
129
- )
130
- |
131
- (?<name> # full name, e.g.: `int`, `\DateTime`, `\Foo\Bar`, `positive-int`
132
- \\\\?+
133
- (?<identifier> ' .self ::REGEX_IDENTIFIER .')
134
- (?:[ \\\\\-](?&identifier))*+
135
- )
136
- |
137
- (?<parenthesized> # parenthesized type, e.g.: `(int)`, `(int|\stdClass)`
138
- (?<parenthesized_start>
139
- \(\h*
140
- )
141
- (?:
142
- (?<parenthesized_types>
143
- (?&types_inner)
95
+ |
96
+ (?<generic> # generic syntax, e.g.: `array<int, \Foo\Bar>`
97
+ (?<generic_start>(?&name)\h*<\h*)
98
+ (?<generic_types>
99
+ (?&types_inner)
100
+ (?:
101
+ \h*,\h*
102
+ (?&types_inner)
103
+ )*
104
+ (?:\h*,\h*)?
105
+ )
106
+ \h*>
144
107
)
145
108
|
146
- (?<conditional> # conditional type, e.g.: `$foo is \Throwable ? false : $foo`
147
- (?<conditional_cond_left>
148
- (?:\$(?&identifier))
149
- |
150
- (?<conditional_cond_left_types>(?&types_inner))
109
+ (?<class_constant> # class constants with optional wildcard, e.g.: `Foo::*`, `Foo::CONST_A`, `FOO::CONST_*`
110
+ (?&name)::\*?(?:(?&identifier)\*?)*
111
+ )
112
+ |
113
+ (?<constant> # single constant value (case insensitive), e.g.: 1, -1.8E+6, `'a'`
114
+ (?i)
115
+ # all sorts of numbers: with or without sign, supports literal separator and several numeric systems,
116
+ # e.g.: 1, +1.1, 1., .1, -1, 123E+8, 123_456_789, 0x7Fb4, 0b0110, 0o777
117
+ [+-]?(?:
118
+ (?:0b[01]++(?:_[01]++)*+)
119
+ | (?:0o[0-7]++(?:_[0-7]++)*+)
120
+ | (?:0x[\da-f]++(?:_[\da-f]++)*+)
121
+ | (?:(?<constant_digits>\d++(?:_\d++)*+)|(?=\.\d))
122
+ (?:\.(?&constant_digits)|(?<=\d)\.)?+
123
+ (?:e[+-]?(?&constant_digits))?+
151
124
)
152
- (?<conditional_cond_middle>
153
- \h+(?i)is(?:\h+not)?(?-i)\h+
125
+ | '(?:[^'\\]|\\.)*+'
126
+ | "(?:[^"\\]|\\.)*+"
127
+ (?-i)
128
+ )
129
+ |
130
+ (?<this> # self reference, e.g.: $this, $self, @static
131
+ (?i)
132
+ [@$](?:this | self | static)
133
+ (?-i)
134
+ )
135
+ |
136
+ (?<name> # full name, e.g.: `int`, `\DateTime`, `\Foo\Bar`, `positive-int`
137
+ \\?+
138
+ (?<identifier>
139
+ EOD.self::REGEX_IDENTIFIER.<<<'EOD'
140
+ )
141
+ (?:[\\\-](?&identifier))*+
142
+ )
143
+ |
144
+ (?<parenthesized> # parenthesized type, e.g.: `(int)`, `(int|\stdClass)`
145
+ (?<parenthesized_start>
146
+ \(\h*
154
147
)
155
- (?<conditional_cond_right_types>(?&types_inner))
156
- (?<conditional_true_start>\h*\?\h*)
157
- (?<conditional_true_types>(?&types_inner))
158
- (?<conditional_false_start>\h*:\h*)
159
- (?<conditional_false_types>(?&types_inner))
148
+ (?:
149
+ (?<parenthesized_types>
150
+ (?&types_inner)
151
+ )
152
+ |
153
+ (?<conditional> # conditional type, e.g.: `$foo is \Throwable ? false : $foo`
154
+ (?<conditional_cond_left>
155
+ (?:\$(?&identifier))
156
+ |
157
+ (?<conditional_cond_left_types>(?&types_inner))
158
+ )
159
+ (?<conditional_cond_middle>
160
+ \h+(?i)is(?:\h+not)?(?-i)\h+
161
+ )
162
+ (?<conditional_cond_right_types>(?&types_inner))
163
+ (?<conditional_true_start>\h*\?\h*)
164
+ (?<conditional_true_types>(?&types_inner))
165
+ (?<conditional_false_start>\h*:\h*)
166
+ (?<conditional_false_types>(?&types_inner))
167
+ )
168
+ )
169
+ \h*\)
160
170
)
161
171
)
162
- \h*\)
163
- )
164
- )
165
- (?<array> # array, e.g.: `string[]`, `array<int, string>[][]`
166
- (\h*\[\h*\])*
167
- )
168
- (?:(?=1)0
169
- (?<types_inner>
170
- (?&type)
171
- (?:
172
- \h*[|&]\h*
173
- (?&type)
174
- )*+
172
+ (?<array> # array, e.g.: `string[]`, `array<int, string>[][]`
173
+ (\h*\[\h*\])*
174
+ )
175
+ (?:(?=1)0
176
+ (?<types_inner>
177
+ (?&type)
178
+ (?:
179
+ \h*[|&]\h*
180
+ (?&type)
181
+ )*+
182
+ )
183
+ |)
175
184
)
176
- |)
177
- ) ' ;
185
+ EOD;
178
186
179
187
private string $ value ;
180
188
0 commit comments