File tree Expand file tree Collapse file tree 10 files changed +144
-1
lines changed
php/PDepend/Source/Language/PHP
resources/files/Source/Language/PHP
PHPParserGenericVersion56 Expand file tree Collapse file tree 10 files changed +144
-1
lines changed Original file line number Diff line number Diff line change @@ -140,6 +140,7 @@ protected function parseStaticValueVersionSpecific(ASTValue $value)
140
140
case Tokens::T_MUL :
141
141
case Tokens::T_DIV :
142
142
case Tokens::T_MOD :
143
+ case Tokens::T_POW :
143
144
case Tokens::T_IS_EQUAL : // TODO: Implement compare expressions
144
145
case Tokens::T_IS_NOT_EQUAL :
145
146
case Tokens::T_IS_IDENTICAL :
@@ -247,4 +248,48 @@ protected function parseStaticValueVersionSpecific(ASTValue $value)
247
248
248
249
return $ value ;
249
250
}
251
+
252
+ /**
253
+ * This method will be called when the base parser cannot handle an expression
254
+ * in the base version. In this method you can implement version specific
255
+ * expressions.
256
+ *
257
+ * @return \PDepend\Source\AST\ASTNode
258
+ * @throws \PDepend\Source\Parser\UnexpectedTokenException
259
+ * @since 2.2
260
+ */
261
+ protected function parseOptionalExpressionForVersion ()
262
+ {
263
+ if ($ expression = $ this ->parseExpressionVersion56 ()) {
264
+ return $ expression ;
265
+ }
266
+ return parent ::parseOptionalExpressionForVersion ();
267
+ }
268
+
269
+ /**
270
+ * In this method we implement parsing of PHP 5.6 specific expressions.
271
+ *
272
+ * @return \PDepend\Source\AST\ASTNode
273
+ * @since 2.3
274
+ */
275
+ protected function parseExpressionVersion56 ()
276
+ {
277
+ $ this ->consumeComments ();
278
+ $ nextTokenType = $ this ->tokenizer ->peek ();
279
+
280
+ switch ($ nextTokenType ) {
281
+ case Tokens::T_POW :
282
+ $ token = $ this ->consumeToken ($ nextTokenType );
283
+
284
+ $ expr = $ this ->builder ->buildAstExpression ($ token ->image );
285
+ $ expr ->configureLinesAndColumns (
286
+ $ token ->startLine ,
287
+ $ token ->endLine ,
288
+ $ token ->startColumn ,
289
+ $ token ->endColumn
290
+ );
291
+
292
+ return $ expr ;
293
+ }
294
+ }
250
295
}
Original file line number Diff line number Diff line change 159
159
define ('T_COALESCE ' , 42014 );
160
160
}
161
161
162
+ /**
163
+ * Define PHP 7's '**' token constant
164
+ */
165
+ if (!defined ('T_POW ' )) {
166
+ define ('T_POW ' , 42015 );
167
+ }
168
+
162
169
/**
163
170
* This tokenizer uses the internal {@link token_get_all()} function as token stream
164
171
* generator.
@@ -183,6 +190,7 @@ class PHPTokenizerInternal implements Tokenizer
183
190
T_FOR => Tokens::T_FOR ,
184
191
T_INC => Tokens::T_INC ,
185
192
T_NEW => Tokens::T_NEW ,
193
+ T_POW => Tokens::T_POW ,
186
194
T_TRY => Tokens::T_TRY ,
187
195
T_USE => Tokens::T_USE ,
188
196
T_VAR => Tokens::T_VAR ,
@@ -486,6 +494,13 @@ class PHPTokenizerInternal implements Tokenizer
486
494
'image ' => '?? ' ,
487
495
)
488
496
),
497
+
498
+ Tokens::T_MUL => array (
499
+ Tokens::T_MUL => array (
500
+ 'type ' => Tokens::T_POW ,
501
+ 'image ' => '** ' ,
502
+ )
503
+ ),
489
504
);
490
505
491
506
/**
Original file line number Diff line number Diff line change @@ -867,6 +867,11 @@ interface Tokens
867
867
*/
868
868
const T_COALESCE = 163 ;
869
869
870
+ /**
871
+ * Token that represents the '**' null coalescing operator
872
+ */
873
+ const T_POW = 164 ;
874
+
870
875
/**
871
876
* Marks any content not between php tags.
872
877
*/
Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ interface CacheDriver
55
55
/**
56
56
* The current cache version.
57
57
*/
58
- const VERSION = '@version:60fe3ebc147c387ccab6869746c14cea :@ ' ;
58
+ const VERSION = '@version:9d43b6160799565e7b28225144228960 :@ ' ;
59
59
60
60
/**
61
61
* Sets the type for the next <em>store()</em> or <em>restore()</em> method
Original file line number Diff line number Diff line change @@ -205,4 +205,30 @@ public function testComplexExpressionInFieldDeclaration()
205
205
206
206
$ this ->assertNotNull ($ node );
207
207
}
208
+
209
+ /**
210
+ * testPowExpressionInMethodBody
211
+ *
212
+ * @return void
213
+ */
214
+ public function testPowExpressionInMethodBody ()
215
+ {
216
+ $ node = $ this ->getFirstClassForTestCase ()
217
+ ->getFirstChildOfType ('PDepend \\Source \\AST \\ASTReturnStatement ' );
218
+
219
+ $ this ->assertSame ('** ' , $ node ->getChild (0 )->getChild (1 )->getImage ());
220
+ }
221
+
222
+ /**
223
+ * testPowExpressionInFieldDeclaration
224
+ *
225
+ * @return void
226
+ */
227
+ public function testPowExpressionInFieldDeclaration ()
228
+ {
229
+ $ node = $ this ->getFirstClassForTestCase ()
230
+ ->getFirstChildOfType ('PDepend \\Source \\AST \\ASTFieldDeclaration ' );
231
+
232
+ $ this ->assertNotNull ($ node );
233
+ }
208
234
}
Original file line number Diff line number Diff line change @@ -99,6 +99,32 @@ public function testComplexExpressionInFieldDeclaration()
99
99
$ this ->assertNotNull ($ node );
100
100
}
101
101
102
+ /**
103
+ * testPowExpressionInMethodBody
104
+ *
105
+ * @return void
106
+ */
107
+ public function testPowExpressionInMethodBody ()
108
+ {
109
+ $ node = $ this ->getFirstClassForTestCase ()
110
+ ->getFirstChildOfType ('PDepend \\Source \\AST \\ASTReturnStatement ' );
111
+
112
+ $ this ->assertSame ('** ' , $ node ->getChild (0 )->getChild (1 )->getImage ());
113
+ }
114
+
115
+ /**
116
+ * testPowExpressionInFieldDeclaration
117
+ *
118
+ * @return void
119
+ */
120
+ public function testPowExpressionInFieldDeclaration ()
121
+ {
122
+ $ node = $ this ->getFirstClassForTestCase ()
123
+ ->getFirstChildOfType ('PDepend \\Source \\AST \\ASTFieldDeclaration ' );
124
+
125
+ $ this ->assertNotNull ($ node );
126
+ }
127
+
102
128
/**
103
129
* @param \PDepend\Source\Tokenizer\Tokenizer $tokenizer
104
130
* @param \PDepend\Source\Builder\Builder $builder
Original file line number Diff line number Diff line change
1
+ <?php
2
+ class testPowExpressionInFieldDeclaration_class
3
+ {
4
+ public $ x = 42 **23 ;
5
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ class testPowOperatorIsHandled_class
3
+ {
4
+ public function testPowOperatorIsHandled ()
5
+ {
6
+ return 42 ** 23 ;
7
+ }
8
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ class testPowExpressionInFieldDeclaration_class
3
+ {
4
+ public $ x = 42 **23 ;
5
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ class testPowOperatorIsHandled_class
3
+ {
4
+ public function testPowOperatorIsHandled ()
5
+ {
6
+ return 42 ** 23 ;
7
+ }
8
+ }
You can’t perform that action at this time.
0 commit comments