@@ -203,6 +203,40 @@ module.exports = {
203
203
204
204
return result ( null , items , flags ) ;
205
205
} ,
206
+
207
+ read_member_modifier : function ( ) {
208
+ let modifier ;
209
+
210
+ switch ( this . token ) {
211
+ case this . tok . T_PUBLIC :
212
+ modifier = 0 ;
213
+ break ;
214
+ case this . tok . T_PROTECTED :
215
+ modifier = 1 ;
216
+ break ;
217
+ case this . tok . T_PRIVATE :
218
+ modifier = 2 ;
219
+ break ;
220
+ case this . tok . T_STATIC :
221
+ modifier = 3 ;
222
+ break ;
223
+ case this . tok . T_ABSTRACT :
224
+ modifier = 4 ;
225
+ break ;
226
+ case this . tok . T_FINAL :
227
+ modifier = 5 ;
228
+ break ;
229
+ default : {
230
+ const err = this . error ( "T_MEMBER_FLAGS" ) ;
231
+ this . next ( ) ;
232
+ return err ;
233
+ }
234
+ }
235
+
236
+ this . next ( ) ;
237
+ return modifier ;
238
+ } ,
239
+
206
240
/**
207
241
* Read member flags
208
242
* @return array
@@ -213,31 +247,34 @@ module.exports = {
213
247
read_member_flags : function ( asInterface ) {
214
248
const result = [ - 1 , - 1 , - 1 ] ;
215
249
if ( this . is ( "T_MEMBER_FLAGS" ) ) {
216
- let idx = 0 ,
217
- val = 0 ;
218
250
do {
219
- switch ( this . token ) {
220
- case this . tok . T_PUBLIC :
251
+ let idx = 0 ;
252
+ let val = 0 ;
253
+
254
+ const visibility = this . read_member_modifier ( ) ;
255
+
256
+ switch ( visibility ) {
257
+ case 0 :
221
258
idx = 0 ;
222
259
val = 0 ;
223
260
break ;
224
- case this . tok . T_PROTECTED :
261
+ case 1 :
225
262
idx = 0 ;
226
263
val = 1 ;
227
264
break ;
228
- case this . tok . T_PRIVATE :
265
+ case 2 :
229
266
idx = 0 ;
230
267
val = 2 ;
231
268
break ;
232
- case this . tok . T_STATIC :
269
+ case 3 :
233
270
idx = 1 ;
234
271
val = 1 ;
235
272
break ;
236
- case this . tok . T_ABSTRACT :
273
+ case 4 :
237
274
idx = 2 ;
238
275
val = 1 ;
239
276
break ;
240
- case this . tok . T_FINAL :
277
+ case 5 :
241
278
idx = 2 ;
242
279
val = 2 ;
243
280
break ;
@@ -259,7 +296,7 @@ module.exports = {
259
296
} else if ( val !== - 1 ) {
260
297
result [ idx ] = val ;
261
298
}
262
- } while ( this . next ( ) . is ( "T_MEMBER_FLAGS" ) ) ;
299
+ } while ( this . is ( "T_MEMBER_FLAGS" ) ) ;
263
300
}
264
301
265
302
if ( result [ 1 ] == - 1 ) result [ 1 ] = 0 ;
@@ -372,18 +409,18 @@ module.exports = {
372
409
const node = this . node ( "traituse" ) ;
373
410
this . expect ( this . tok . T_USE ) && this . next ( ) ;
374
411
const traits = [ this . read_namespace_name ( ) ] ;
375
- let adaptations = null ;
376
412
while ( this . token === "," ) {
377
413
traits . push ( this . next ( ) . read_namespace_name ( ) ) ;
378
414
}
415
+ const adaptations = this . read_trait_adaptations ( ) ;
416
+ return node ( traits , adaptations ) ;
417
+ } ,
418
+
419
+ read_trait_adaptations : function ( ) {
420
+ let adaptations = null ;
421
+
379
422
if ( this . token === "{" ) {
380
- adaptations = [ ] ;
381
- // defines alias statements
382
- while ( this . next ( ) . token !== this . EOF ) {
383
- if ( this . token === "}" ) break ;
384
- adaptations . push ( this . read_trait_use_alias ( ) ) ;
385
- this . expect ( ";" ) ;
386
- }
423
+ adaptations = this . read_trait_adaptation_list ( ) ;
387
424
if ( this . expect ( "}" ) ) {
388
425
this . next ( ) ;
389
426
}
@@ -392,17 +429,34 @@ module.exports = {
392
429
this . next ( ) ;
393
430
}
394
431
}
395
- return node ( traits , adaptations ) ;
432
+
433
+ return adaptations ;
396
434
} ,
435
+
436
+ /*
437
+ * Reads trait adaptation list
438
+ */
439
+ read_trait_adaptation_list : function ( ) {
440
+ let adaptations = [ ] ;
441
+ // defines alias statements
442
+ while ( this . next ( ) . token !== this . EOF ) {
443
+ if ( this . token === "}" ) break ;
444
+ adaptations . push ( this . read_trait_adaptation ( ) ) ;
445
+ this . expect ( ";" ) ;
446
+ }
447
+
448
+ return adaptations ;
449
+ } ,
450
+
397
451
/**
398
- * Reading trait alias
452
+ * Reading trait adaptation
399
453
* ```ebnf
400
454
* trait_use_alias ::= namespace_name ( T_DOUBLE_COLON T_STRING )? (T_INSTEADOF namespace_name) | (T_AS member_flags? T_STRING)
401
455
* ```
402
456
* name list : https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L303
403
457
* trait adaptation : https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L742
404
458
*/
405
- read_trait_use_alias : function ( ) {
459
+ read_trait_adaptation : function ( ) {
406
460
const node = this . node ( ) ;
407
461
let trait = null ;
408
462
let method ;
@@ -445,10 +499,11 @@ module.exports = {
445
499
) ;
446
500
} else if ( this . token === this . tok . T_AS ) {
447
501
// handle trait alias
448
- let flags = null ;
502
+ let visibility = null ;
449
503
let alias = null ;
450
- if ( this . next ( ) . is ( "T_MEMBER_FLAGS" ) ) {
451
- flags = this . read_member_flags ( ) ;
504
+ this . next ( ) ;
505
+ if ( this . is ( "T_MEMBER_FLAGS" ) ) {
506
+ visibility = this . read_member_modifier ( ) ;
452
507
}
453
508
454
509
if (
@@ -459,12 +514,12 @@ module.exports = {
459
514
const name = this . text ( ) ;
460
515
this . next ( ) ;
461
516
alias = alias ( name ) ;
462
- } else if ( flags === false ) {
517
+ } else if ( visibility === false ) {
463
518
// no visibility flags and no name => too bad
464
519
this . expect ( this . tok . T_STRING ) ;
465
520
}
466
521
467
- return node ( "traitalias" , trait , method , alias , flags ) ;
522
+ return node ( "traitalias" , trait , method , alias , visibility ) ;
468
523
}
469
524
470
525
// handle errors
0 commit comments