1
- /*! php-parser - BSD3 License - 2017-01-02 */
1
+ /*! php-parser - BSD3 License - 2017-01-03 */
2
2
3
3
require = ( function e ( t , n , r ) { function s ( o , u ) { if ( ! n [ o ] ) { if ( ! t [ o ] ) { var a = typeof require == "function" && require ; if ( ! u && a ) return a ( o , ! 0 ) ; if ( i ) return i ( o , ! 0 ) ; var f = new Error ( "Cannot find module '" + o + "'" ) ; throw f . code = "MODULE_NOT_FOUND" , f } var l = n [ o ] = { exports :{ } } ; t [ o ] [ 0 ] . call ( l . exports , function ( e ) { var n = t [ o ] [ 1 ] [ e ] ; return s ( n ?n :e ) } , l , l . exports , e , t , n , r ) } return n [ o ] . exports } var i = typeof require == "function" && require ; for ( var o = 0 ; o < r . length ; o ++ ) s ( r [ o ] ) ; return s } ) ( { 1 :[ function ( require , module , exports ) {
4
4
// shim for using process in browser
@@ -3626,13 +3626,17 @@ module.exports = {
3626
3626
if ( ch === '-' ) {
3627
3627
ch = this . input ( ) ;
3628
3628
if ( ch === '>' ) {
3629
+ // https://github.com/php/php-src/blob/master/Zend/zend_language_scanner.l#L1296
3629
3630
return this . tok . T_OBJECT_OPERATOR ;
3630
3631
}
3631
3632
this . unput ( 1 ) ;
3632
3633
} else if ( this . is_LABEL_START ( ) ) {
3634
+ // https://github.com/php/php-src/blob/master/Zend/zend_language_scanner.l#L1300
3633
3635
this . consume_LABEL ( ) ;
3636
+ this . popState ( ) ;
3634
3637
return this . tok . T_STRING ;
3635
3638
}
3639
+ // https://github.com/php/php-src/blob/master/Zend/zend_language_scanner.l#L1306
3636
3640
this . popState ( ) ;
3637
3641
this . unput ( 1 ) ;
3638
3642
return false ;
@@ -4532,11 +4536,6 @@ module.exports = {
4532
4536
var ch = this . _input [ this . offset - 1 ] ;
4533
4537
return tokens . indexOf ( ch ) !== - 1 ;
4534
4538
} ,
4535
- // check if current char is a newline
4536
- is_NEWLINE : function ( ) {
4537
- var ch = this . _input [ this . offset - 1 ] ;
4538
- return ch === '\n' || ch === '\r' ;
4539
- } ,
4540
4539
// check if current char is a whitespace
4541
4540
is_WHITESPACE : function ( ) {
4542
4541
var ch = this . _input [ this . offset - 1 ] ;
@@ -4601,12 +4600,19 @@ var parser = function(lexer, ast) {
4601
4600
this . extractDoc = false ;
4602
4601
this . suppressErrors = false ;
4603
4602
this . entries = {
4603
+ 'VARIABLE' : [
4604
+ this . tok . T_VARIABLE ,
4605
+ '$' , '&' ,
4606
+ this . tok . T_NS_SEPARATOR ,
4607
+ this . tok . T_STRING ,
4608
+ this . tok . T_NAMESPACE ,
4609
+ this . tok . T_STATIC
4610
+ ] ,
4604
4611
'SCALAR' : [
4605
4612
this . tok . T_CONSTANT_ENCAPSED_STRING ,
4606
4613
this . tok . T_START_HEREDOC ,
4607
4614
this . tok . T_LNUMBER ,
4608
4615
this . tok . T_DNUMBER ,
4609
- this . tok . T_STRING ,
4610
4616
this . tok . T_ARRAY , '[' ,
4611
4617
this . tok . T_CLASS_C ,
4612
4618
this . tok . T_TRAIT_C ,
@@ -4616,7 +4622,6 @@ var parser = function(lexer, ast) {
4616
4622
this . tok . T_FILE ,
4617
4623
this . tok . T_DIR ,
4618
4624
this . tok . T_NS_C ,
4619
- this . tok . T_NAMESPACE ,
4620
4625
'"' ,
4621
4626
'b"' ,
4622
4627
'B"' ,
@@ -4641,13 +4646,6 @@ var parser = function(lexer, ast) {
4641
4646
this . tok . T_ABSTRACT ,
4642
4647
this . tok . T_FINAL
4643
4648
] ,
4644
- 'VARIABLE' : [
4645
- this . tok . T_VARIABLE ,
4646
- '$' , '&' ,
4647
- this . tok . T_NS_SEPARATOR ,
4648
- this . tok . T_STRING ,
4649
- this . tok . T_STATIC
4650
- ] ,
4651
4649
'EOS' : [
4652
4650
';' ,
4653
4651
this . tok . T_CLOSE_TAG ,
@@ -4934,16 +4932,6 @@ parser.prototype.is = function(type) {
4934
4932
}
4935
4933
} ;
4936
4934
4937
- /** convert an token to ast **/
4938
- parser . prototype . read_token = function ( ) {
4939
- var result = this . token ;
4940
- if ( isNumber ( result ) ) {
4941
- result = [ result , this . text ( ) , this . lexer . yylloc . first_line ] ;
4942
- }
4943
- this . next ( ) ;
4944
- return result ;
4945
- } ;
4946
-
4947
4935
// extends the parser with syntax files
4948
4936
[
4949
4937
require ( './parser/array.js' ) ,
@@ -6029,7 +6017,11 @@ module.exports = {
6029
6017
* ```
6030
6018
*/
6031
6019
, read_class_name_reference : function ( ) {
6032
- if ( this . token === '\\' || this . token === this . tok . T_STRING ) {
6020
+ if (
6021
+ this . token === this . tok . T_NS_SEPARATOR ||
6022
+ this . token === this . tok . T_STRING ||
6023
+ this . token === this . tok . T_NAMESPACE
6024
+ ) {
6033
6025
var result = this . read_namespace_name ( ) ;
6034
6026
if ( this . token === this . tok . T_DOUBLE_COLON ) {
6035
6027
result = this . read_static_getter ( result ) ;
@@ -6860,41 +6852,14 @@ module.exports = {
6860
6852
return node ( 'binary' , what ) ;
6861
6853
6862
6854
// NUMERIC
6863
- case '-' : // long
6864
6855
case this . tok . T_LNUMBER : // long
6865
6856
case this . tok . T_DNUMBER : // double
6866
6857
var result = this . node ( 'number' ) ;
6867
6858
var value = this . text ( ) ;
6868
- if ( this . token === '-' ) {
6869
- this . next ( ) . expect ( [ this . tok . T_LNUMBER , this . tok . T_DNUMBER ] ) ;
6870
- value += this . text ( ) ;
6871
- }
6872
6859
this . next ( ) ;
6873
6860
result = result ( value ) ;
6874
6861
return result ;
6875
6862
6876
- // CONSTANTS
6877
- case this . tok . T_NAMESPACE :
6878
- case this . tok . T_NS_SEPARATOR :
6879
- case this . tok . T_STRING :
6880
- var value = this . read_namespace_name ( ) ;
6881
- var result = [ 'constant' , value ] ;
6882
- if ( this . token == this . tok . T_DOUBLE_COLON ) {
6883
- // class constant MyClass::CONSTANT
6884
- if ( this . next ( ) . expect ( [ this . tok . T_STRING , this . tok . T_CLASS ] ) ) {
6885
- result [ 1 ] = [ value , this . text ( ) ] ;
6886
- this . next ( ) ;
6887
- }
6888
- }
6889
- // CONSTANT ARRAYS OFFSET : MYCONST[1][0]...
6890
- while ( this . token === '[' ) {
6891
- var node = this . node ( 'offsetlookup' ) ;
6892
- var offset = this . next ( ) . read_expr ( ) ;
6893
- if ( this . expect ( ']' ) ) this . next ( ) ;
6894
- result = node ( result , offset ) ;
6895
- }
6896
- return result ;
6897
-
6898
6863
// ARRAYS
6899
6864
case this . tok . T_ARRAY : // array parser
6900
6865
case '[' : // short array format
@@ -6979,18 +6944,18 @@ module.exports = {
6979
6944
// https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L1246
6980
6945
else if ( this . token === this . tok . T_CURLY_OPEN ) {
6981
6946
result = this . next ( ) . read_variable ( false , false , false ) ;
6982
- if ( this . expect ( '}' ) ) this . next ( ) ;
6947
+ this . expect ( '}' ) && this . next ( ) ;
6983
6948
}
6984
6949
6985
6950
// plain variable
6986
6951
// https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L1231
6987
6952
else if ( this . token === this . tok . T_VARIABLE ) {
6988
- result = this . read_variable ( false , true , false ) ;
6953
+ result = this . read_simple_variable ( false ) ;
6989
6954
6990
6955
// https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L1233
6991
6956
if ( this . token === '[' ) {
6992
6957
var node = this . node ( 'offsetlookup' ) ;
6993
- var offset = this . next ( ) . read_expr ( ) ;
6958
+ var offset = this . next ( ) . read_encaps_var_offset ( ) ;
6994
6959
this . expect ( ']' ) && this . next ( ) ;
6995
6960
result = node ( result , offset ) ;
6996
6961
}
@@ -7272,16 +7237,15 @@ module.exports = {
7272
7237
this . expectEndOfStatement ( ) ;
7273
7238
return result ( expr ) ;
7274
7239
7240
+ // https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L429
7275
7241
case this . tok . T_BREAK :
7276
7242
case this . tok . T_CONTINUE :
7277
7243
var result = this . node (
7278
7244
this . token === this . tok . T_CONTINUE ? 'continue' : 'break'
7279
7245
) , level = null ;
7280
- if ( this . next ( ) . token === this . tok . T_LNUMBER ) {
7281
- level = this . node ( 'number' ) ;
7282
- var value = this . text ( ) ;
7283
- this . next ( ) ;
7284
- level = level ( value ) ;
7246
+ this . next ( ) ; // look ahead
7247
+ if ( this . token !== ';' && this . token !== this . tok . T_CLOSE_TAG ) {
7248
+ level = this . read_expr ( ) ;
7285
7249
}
7286
7250
this . expectEndOfStatement ( ) ;
7287
7251
return result ( level ) ;
@@ -7336,27 +7300,29 @@ module.exports = {
7336
7300
if ( this . token === ':' ) {
7337
7301
this . nextWithComments ( ) ;
7338
7302
while ( this . token != this . EOF && this . token !== this . tok . T_ENDDECLARE ) {
7339
- body . push ( this . read_statement ( ) ) ;
7303
+ // @todo : check declare_statement from php / not valid
7304
+ body . push ( this . read_top_statement ( ) ) ;
7340
7305
}
7341
7306
this . expect ( this . tok . T_ENDDECLARE ) && this . next ( ) ;
7342
7307
this . expectEndOfStatement ( ) ;
7343
7308
mode = this . ast . declare . MODE_SHORT ;
7344
7309
} else if ( this . token === '{' ) {
7345
7310
this . nextWithComments ( ) ;
7346
7311
while ( this . token != this . EOF && this . token !== '}' ) {
7347
- body . push ( this . read_statement ( ) ) ;
7312
+ // @todo : check declare_statement from php / not valid
7313
+ body . push ( this . read_top_statement ( ) ) ;
7348
7314
}
7349
7315
this . expect ( '}' ) && this . next ( ) ;
7350
7316
mode = this . ast . declare . MODE_BLOCK ;
7351
7317
} else {
7352
7318
this . expect ( ';' ) && this . next ( ) ;
7353
7319
while ( this . token != this . EOF && this . token !== this . tok . T_DECLARE ) {
7354
- body . push ( this . read_statement ( ) ) ;
7320
+ // @todo : check declare_statement from php / not valid
7321
+ body . push ( this . read_top_statement ( ) ) ;
7355
7322
}
7356
7323
mode = this . ast . declare . MODE_NONE ;
7357
7324
}
7358
7325
return result ( what , body , mode ) ;
7359
- break ;
7360
7326
7361
7327
case this . tok . T_TRY :
7362
7328
return this . read_try ( ) ;
@@ -7718,7 +7684,7 @@ module.exports = {
7718
7684
// reads the entry point
7719
7685
if ( this . is ( [ this . tok . T_VARIABLE , '$' ] ) ) {
7720
7686
result = this . read_reference_variable ( encapsed , byref ) ;
7721
- } else if ( this . is ( [ this . tok . T_NS_SEPARATOR , this . tok . T_STRING ] ) ) {
7687
+ } else if ( this . is ( [ this . tok . T_NS_SEPARATOR , this . tok . T_STRING , this . tok . T_NAMESPACE ] ) ) {
7722
7688
result = this . node ( ) ;
7723
7689
var name = this . read_namespace_name ( ) ;
7724
7690
if (
@@ -7920,13 +7886,14 @@ module.exports = {
7920
7886
while ( this . token != this . EOF ) {
7921
7887
var node = this . node ( ) ;
7922
7888
if ( this . token == '[' ) {
7889
+ var offset = null ;
7923
7890
if ( encapsed ) {
7924
- result = this . next ( ) . read_encaps_var_offset ( ) ;
7891
+ offset = this . next ( ) . read_encaps_var_offset ( ) ;
7925
7892
} else {
7926
- var offset = this . next ( ) . token === ']' ? null : this . read_dim_offset ( ) ;
7927
- result = node ( 'offsetlookup' , result , offset ) ;
7893
+ offset = this . next ( ) . token === ']' ? null : this . read_dim_offset ( ) ;
7928
7894
}
7929
7895
this . expect ( ']' ) && this . next ( ) ;
7896
+ result = node ( 'offsetlookup' , result , offset ) ;
7930
7897
} else if ( this . token == '{' && ! encapsed ) {
7931
7898
var offset = this . next ( ) . read_expr ( ) ;
7932
7899
this . expect ( '}' ) && this . next ( ) ;
0 commit comments