@@ -62,47 +62,29 @@ module.exports = {
62
62
* </ebnf>
63
63
*/
64
64
, read_class_body : function ( ) {
65
- var result = {
66
- 'constants' : [ ]
67
- , 'properties' : [ ]
68
- , 'methods' : [ ]
69
- , 'use' : {
70
- // list of traits
71
- traits : [ ] ,
72
- // list of alias
73
- adaptations : [ ]
74
- }
75
- } , startAt = null , node = null , comment = false ;
76
-
77
-
65
+ var result = [ ] ;
78
66
79
67
while ( this . token !== this . EOF && this . token !== '}' ) {
80
68
81
69
if ( this . token === this . tok . T_COMMENT ) {
82
- comment = this . read_comment ( ) ;
70
+ result . push ( this . read_comment ( ) ) ;
83
71
continue ;
84
72
}
85
73
86
74
if ( this . token === this . tok . T_DOC_COMMENT ) {
87
- comment = this . read_doc_comment ( ) ;
75
+ result . push ( this . read_doc_comment ( ) ) ;
88
76
continue ;
89
77
}
90
78
91
79
// check T_USE trait
92
80
if ( this . token === this . tok . T_USE ) {
93
- comment = false ; // flush comments
94
- this . next ( ) . read_trait_use_statement ( result [ 'use' ] ) ;
81
+ result = result . concat (
82
+ this . next ( ) . read_trait_use_statement ( )
83
+ ) ;
95
84
continue ;
96
85
}
97
86
98
- // prepare here position (to avoid bad position on locations)
99
- if ( this . locations ) {
100
- startAt = [
101
- this . lexer . yylloc . first_line ,
102
- this . lexer . yylloc . first_column ,
103
- this . length - this . lexer . _input . length - this . lexer . yytext . length
104
- ] ;
105
- }
87
+
106
88
// read member flags
107
89
var flags = this . read_member_flags ( false ) ;
108
90
@@ -115,59 +97,48 @@ module.exports = {
115
97
for ( var i = 0 ; i < constants . length ; i ++ ) {
116
98
var constant = constants [ i ] ;
117
99
( this . locations ? constant [ 3 ] : constant ) . push ( flags ) ;
118
- if ( comment ) {
119
- var buffer = comment . slice ( 0 ) ;
120
- ( this . locations ? buffer [ 3 ] : buffer ) . push ( constant ) ;
121
- constant = buffer ;
122
- }
123
- result . constants . push ( constant ) ;
100
+ result . push ( constant ) ;
124
101
}
125
102
continue ;
126
103
}
127
104
128
105
// jump over T_VAR then land on T_VARIABLE
129
106
if ( this . token === this . tok . T_VAR ) {
130
107
this . next ( ) . expect ( this . tok . T_VARIABLE ) ;
108
+ flags [ 0 ] = flags [ 1 ] = 0 ; // public & non static var
131
109
}
132
110
133
- // reads a variable
134
111
if ( this . token === this . tok . T_VARIABLE ) {
112
+
113
+ // reads a variable
135
114
var variables = this . read_variable_list ( flags ) ;
136
115
this . expect ( ';' ) . nextWithComments ( ) ;
116
+
137
117
for ( var i = 0 ; i < variables . length ; i ++ ) {
138
118
var variable = variables [ i ] ;
139
119
( this . locations ? variable [ 3 ] : variable ) . push ( flags ) ;
140
- if ( comment ) {
141
- var buffer = comment . slice ( 0 ) ;
142
- ( this . locations ? buffer [ 3 ] : buffer ) . push ( variable ) ;
143
- variable = buffer ;
144
- }
145
- result . properties . push ( variable ) ;
120
+ result . push ( variable ) ;
146
121
}
147
- comment = false ;
122
+
148
123
} else if ( this . token === this . tok . T_FUNCTION ) {
124
+
149
125
// reads a function
150
126
var method = this . read_function ( false , flags [ 2 ] === 1 ) ;
151
- if ( this . locations ) {
152
- method [ 1 ] = startAt ;
153
- method [ 3 ] . push ( flags ) ;
154
- } else {
155
- method . push ( flags ) ;
156
- }
157
- if ( comment ) {
158
- ( this . locations ? comment [ 3 ] : comment ) . push ( method ) ;
159
- method = comment ;
160
- comment = false ;
161
- }
162
- result . methods . push ( method ) ;
127
+ ( this . locations ? method [ 3 ] : method ) . push ( flags ) ;
128
+ result . push ( method ) ;
129
+
163
130
} else {
131
+
164
132
// raise an error
165
- this . error ( [
166
- this . tok . T_CONST ,
167
- this . tok . T_VARIABLE ,
168
- this . tok . T_FUNCTION
169
- ] ) ;
133
+ result . push (
134
+ this . error ( [
135
+ this . tok . T_CONST ,
136
+ this . tok . T_VARIABLE ,
137
+ this . tok . T_FUNCTION
138
+ ] )
139
+ ) ;
170
140
this . next ( ) ; // ignore token
141
+
171
142
}
172
143
}
173
144
this . expect ( '}' ) . nextWithComments ( ) ;
@@ -310,10 +281,8 @@ module.exports = {
310
281
* </ebnf>
311
282
*/
312
283
, read_interface_body : function ( ) {
313
- var result = {
314
- 'constants' : [ ]
315
- , 'methods' : [ ]
316
- } , startAt = null , comment = false ;
284
+ var result = [ ] ;
285
+
317
286
while ( this . token !== this . EOF && this . token !== '}' ) {
318
287
319
288
if ( this . token === this . tok . T_COMMENT ) {
@@ -326,16 +295,6 @@ module.exports = {
326
295
continue ;
327
296
}
328
297
329
-
330
- // prepare here position (to avoid bad position on locations)
331
- if ( this . locations ) {
332
- startAt = [
333
- this . lexer . yylloc . first_line ,
334
- this . lexer . yylloc . first_column ,
335
- this . length - this . lexer . _input . length - this . lexer . yytext . length
336
- ] ;
337
- }
338
-
339
298
// read member flags
340
299
var flags = this . read_member_flags ( true ) ;
341
300
@@ -347,38 +306,25 @@ module.exports = {
347
306
for ( var i = 0 ; i < constants . length ; i ++ ) {
348
307
var constant = constants [ i ] ;
349
308
( this . locations ? constant [ 3 ] : constant ) . push ( flags ) ;
350
- if ( comment ) {
351
- var buffer = comment . slice ( 0 ) ;
352
- ( this . locations ? buffer [ 3 ] : buffer ) . push ( constant ) ;
353
- constant = buffer ;
354
- }
355
- result . constants . push ( constant ) ;
309
+ result . push ( constant ) ;
356
310
}
357
311
358
312
}
359
313
360
314
// reads a function
361
315
else if ( this . token === this . tok . T_FUNCTION ) {
362
- // reads a function
363
- var method = this . read_function_declaration ( ) . concat (
364
- [ flags ]
365
- ) ;
366
- if ( this . locations ) {
367
- method [ 1 ] = startAt ;
368
- }
369
- if ( comment ) {
370
- ( this . locations ? comment [ 3 ] : comment ) . push ( method ) ;
371
- method = comment ;
372
- comment = false ;
373
- }
374
- result . methods . push ( method ) ;
316
+ var method = this . read_function_declaration ( ) ;
317
+ ( this . locations ? method [ 3 ] : method ) . push ( flags ) ;
318
+ result . push ( method ) ;
375
319
this . expect ( ';' ) . nextWithComments ( ) ;
376
320
} else {
377
321
// raise an error
378
- this . error ( [
379
- this . tok . T_CONST ,
380
- this . tok . T_FUNCTION
381
- ] ) ;
322
+ result . push (
323
+ this . error ( [
324
+ this . tok . T_CONST ,
325
+ this . tok . T_FUNCTION
326
+ ] )
327
+ ) ;
382
328
this . next ( ) ;
383
329
}
384
330
}
@@ -422,23 +368,28 @@ module.exports = {
422
368
* trait_use_statement ::= namespace_name (',' namespace_name)* ('{' trait_use_alias '}')?
423
369
* </ebnf>
424
370
*/
425
- , read_trait_use_statement : function ( result ) {
426
- result . traits . push ( this . read_namespace_name ( ) ) ;
371
+ , read_trait_use_statement : function ( ) {
372
+ // defines use statements
373
+ var node = this . node ( 'use' ) ;
374
+ var name = this . read_namespace_name ( ) ;
375
+ var result = [ node ( name ) ] ;
427
376
while ( this . token === ',' ) {
428
- result . traits . push (
429
- this . next ( ) . read_namespace_name ( )
430
- ) ;
377
+ node = this . node ( 'use' ) ;
378
+ name = this . next ( ) . read_namespace_name ( ) ;
379
+ result . push ( node ( name ) ) ;
431
380
}
432
381
if ( this . token === '{' ) {
382
+ // defines alias statements
433
383
while ( this . next ( ) ) {
434
384
if ( this . token === '}' ) break ;
435
- result . adaptations . push ( this . read_trait_use_alias ( ) ) ;
385
+ result . push ( this . read_trait_use_alias ( ) ) ;
436
386
this . expect ( ';' ) ;
437
387
}
438
388
this . expect ( '}' ) . nextWithComments ( ) ;
439
389
} else {
440
390
this . expect ( ';' ) . nextWithComments ( ) ;
441
391
}
392
+ return result ;
442
393
}
443
394
/**
444
395
* Reading trait alias
@@ -447,42 +398,43 @@ module.exports = {
447
398
* </ebnf>
448
399
*/
449
400
, read_trait_use_alias : function ( ) {
450
- var result = {
451
- origin : this . read_namespace_name ( ) ,
452
- act : false ,
453
- target : false
454
- } ;
401
+ var node = this . node ( 'alias' ) ;
402
+ var origin = this . read_namespace_name ( ) ;
403
+ var act = false ;
404
+ var target = false ;
405
+ var flags = false ;
406
+
455
407
if ( this . token === this . tok . T_DOUBLE_COLON ) {
456
- result . origin = [
457
- result . origin ,
408
+ origin = [
409
+ 'static' ,
410
+ 'get' ,
411
+ origin ,
458
412
this . next ( ) . expect ( this . tok . T_STRING ) . text ( )
459
413
] ;
460
414
this . next ( ) ;
461
415
}
462
416
463
417
if ( this . token === this . tok . T_INSTEADOF ) {
464
- result . act = 'instead ' ;
465
- result . target = this . next ( ) . read_namespace_name ( ) ;
418
+ act = 'insteadof ' ;
419
+ target = this . next ( ) . read_namespace_name ( ) ;
466
420
} else if ( this . token === this . tok . T_AS ) {
467
- result . act = 'as' ;
421
+ act = 'as' ;
468
422
if ( this . next ( ) . is ( 'T_MEMBER_FLAGS' ) ) {
469
- result . flags = this . read_member_flags ( ) ;
470
- } else {
471
- result . flags = null ;
423
+ flags = this . read_member_flags ( ) ;
472
424
}
473
425
if ( this . token === this . tok . T_STRING ) {
474
- result . target = this . text ( ) ;
426
+ target = this . text ( ) ;
475
427
this . next ( ) ;
476
- } else if ( result . flags === null ) {
428
+ } else if ( flags === false ) {
477
429
// no visibility flags and no name => too bad
478
- this . expect ( this . tok . T_STRING )
430
+ this . expect ( this . tok . T_STRING ) ;
479
431
}
480
432
} else {
481
433
this . expect ( [
482
434
this . tok . T_AS ,
483
435
this . tok . T_INSTEADOF
484
436
] ) ;
485
437
}
486
- return result ;
438
+ return node ( origin , act , target , flags ) ;
487
439
}
488
440
} ;
0 commit comments