@@ -4673,6 +4673,7 @@ var parser = function(lexer, ast) {
4673
4673
this . token = null ;
4674
4674
this . prev = null ;
4675
4675
this . debug = false ;
4676
+ this . php7 = true ;
4676
4677
this . extractDoc = false ;
4677
4678
this . suppressErrors = false ;
4678
4679
var mapIt = function ( item ) {
@@ -5388,7 +5389,7 @@ module.exports = {
5388
5389
var result = this . node ( 'classconstant' ) ,
5389
5390
name = null ,
5390
5391
value = null ;
5391
- if ( this . token === this . tok . T_STRING || this . is ( 'IDENTIFIER' ) ) {
5392
+ if ( this . token === this . tok . T_STRING || ( this . php7 && this . is ( 'IDENTIFIER' ) ) ) {
5392
5393
name = this . text ( ) ;
5393
5394
this . next ( ) ;
5394
5395
} else {
@@ -5615,7 +5616,7 @@ module.exports = {
5615
5616
if ( this . token === this . tok . T_DOUBLE_COLON ) {
5616
5617
this . next ( ) ;
5617
5618
5618
- if ( this . token === this . tok . T_STRING || this . is ( 'IDENTIFIER' ) ) {
5619
+ if ( this . token === this . tok . T_STRING || ( this . php7 && this . is ( 'IDENTIFIER' ) ) ) {
5619
5620
trait = method ;
5620
5621
method = this . text ( ) ;
5621
5622
this . next ( ) ;
@@ -5645,7 +5646,7 @@ module.exports = {
5645
5646
flags = this . read_member_flags ( ) ;
5646
5647
}
5647
5648
5648
- if ( this . token === this . tok . T_STRING || this . is ( 'IDENTIFIER' ) ) {
5649
+ if ( this . token === this . tok . T_STRING || ( this . php7 && this . is ( 'IDENTIFIER' ) ) ) {
5649
5650
alias = this . text ( ) ;
5650
5651
this . next ( ) ;
5651
5652
} else if ( flags === false ) {
@@ -6347,7 +6348,7 @@ module.exports = {
6347
6348
var name = false , use = [ ] , returnType = null , nullable = false ;
6348
6349
if ( type !== 1 ) {
6349
6350
if ( type === 2 ) {
6350
- if ( this . token === this . tok . T_STRING || this . is ( 'IDENTIFIER' ) ) {
6351
+ if ( this . token === this . tok . T_STRING || ( this . php7 && this . is ( 'IDENTIFIER' ) ) ) {
6351
6352
name = this . text ( ) ;
6352
6353
this . next ( ) ;
6353
6354
} else {
@@ -7959,7 +7960,7 @@ module.exports = {
7959
7960
} else if (
7960
7961
this . token === this . tok . T_STRING
7961
7962
|| this . token === this . tok . T_CLASS
7962
- || this . is ( 'IDENTIFIER' )
7963
+ || ( this . php7 && this . is ( 'IDENTIFIER' ) )
7963
7964
) {
7964
7965
offset = this . node ( 'constref' ) ;
7965
7966
var name = this . text ( ) ;
@@ -8009,20 +8010,28 @@ module.exports = {
8009
8010
result = node ( result , offset ) ;
8010
8011
break ;
8011
8012
case this . tok . T_DOUBLE_COLON :
8012
- if ( ( this . next ( ) . token === this . tok . T_STRING || this . is ( 'IDENTIFIER' ) ) ) {
8013
- var node = this . node ( 'staticlookup' ) ;
8013
+
8014
+ // @see https://github.com/glayzzle/php-parser/issues/107#issuecomment-354104574
8015
+ if ( result . kind === 'staticlookup' ) {
8016
+ this . error ( ) ;
8017
+ }
8018
+
8019
+ var node = this . node ( 'staticlookup' ) ;
8020
+ if ( this . next ( ) . token === this . tok . T_STRING || ( this . php7 && this . is ( 'IDENTIFIER' ) ) ) {
8014
8021
var offset = this . node ( 'constref' ) ;
8015
8022
var name = this . text ( ) ;
8016
-
8017
8023
this . next ( ) ;
8018
8024
offset = offset ( name ) ;
8019
-
8020
- if ( this . token === this . tok . T_OBJECT_OPERATOR || this . token === this . tok . T_DOUBLE_COLON ) {
8025
+ if ( this . token === this . tok . T_OBJECT_OPERATOR ) {
8021
8026
this . error ( ) ;
8022
8027
}
8023
-
8024
- result = node ( result , offset ) ;
8028
+ } else {
8029
+ this . error ( this . tok . T_STRING ) ;
8030
+ // fallback on a constref node
8031
+ var offset = this . node ( 'constref' ) ( this . text ( ) ) ;
8032
+ this . next ( ) ;
8025
8033
}
8034
+ result = node ( result , offset ) ;
8026
8035
break ;
8027
8036
case this . tok . T_OBJECT_OPERATOR :
8028
8037
var node = this . node ( 'propertylookup' ) ;
@@ -8529,7 +8538,8 @@ function combine(src, to) {
8529
8538
* var instance = new parser({
8530
8539
* parser: {
8531
8540
* extractDoc: true,
8532
- * suppressErrors: true
8541
+ * suppressErrors: true,
8542
+ * php7: true
8533
8543
* },
8534
8544
* ast: {
8535
8545
* withPositions: true
0 commit comments