File tree Expand file tree Collapse file tree 9 files changed +327
-15
lines changed Expand file tree Collapse file tree 9 files changed +327
-15
lines changed Original file line number Diff line number Diff line change @@ -353,11 +353,15 @@ module.exports = {
353
353
case this . tok . T_STRING : {
354
354
const result = this . node ( ) ;
355
355
const current = [ this . token , this . lexer . getState ( ) ] ;
356
- const label = this . text ( ) ;
356
+ const labelNameText = this . text ( ) ;
357
+ let labelName = this . node ( "identifier" ) ;
357
358
// AST : https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L457
358
359
if ( this . next ( ) . token === ":" ) {
360
+ labelName = labelName ( labelNameText ) ;
359
361
this . next ( ) ;
360
- return result ( "label" , label ) ;
362
+ return result ( "label" , labelName ) ;
363
+ } else {
364
+ labelName . destroy ( ) ;
361
365
}
362
366
363
367
// default fallback expr / T_STRING '::' (etc...)
@@ -371,12 +375,15 @@ module.exports = {
371
375
372
376
case this . tok . T_GOTO : {
373
377
const result = this . node ( "goto" ) ;
374
- let label = null ;
378
+ let labelName = null ;
375
379
if ( this . next ( ) . expect ( this . tok . T_STRING ) ) {
376
- label = this . text ( ) ;
377
- this . next ( ) . expectEndOfStatement ( ) ;
380
+ labelName = this . node ( "identifier" ) ;
381
+ const name = this . text ( ) ;
382
+ this . next ( ) ;
383
+ labelName = labelName ( name ) ;
384
+ this . expectEndOfStatement ( ) ;
378
385
}
379
- return result ( label ) ;
386
+ return result ( labelName ) ;
380
387
}
381
388
382
389
default : {
Original file line number Diff line number Diff line change @@ -3118,7 +3118,23 @@ Program {
3118
3118
" offset" : 1660 ,
3119
3119
},
3120
3120
},
3121
- " name" : " next" ,
3121
+ " name" : Identifier {
3122
+ " kind" : " identifier" ,
3123
+ " loc" : Location {
3124
+ " end" : Position {
3125
+ " column" : 4 ,
3126
+ " line" : 83 ,
3127
+ " offset" : 1664 ,
3128
+ },
3129
+ " source" : " next" ,
3130
+ " start" : Position {
3131
+ " column" : 0 ,
3132
+ " line" : 83 ,
3133
+ " offset" : 1660 ,
3134
+ },
3135
+ },
3136
+ " name" : " next" ,
3137
+ },
3122
3138
},
3123
3139
ExpressionStatement {
3124
3140
" expression" : Assign {
@@ -3663,7 +3679,23 @@ Program {
3663
3679
" alternate" : null ,
3664
3680
" body" : Goto {
3665
3681
" kind" : " goto" ,
3666
- " label" : " next" ,
3682
+ " label" : Identifier {
3683
+ " kind" : " identifier" ,
3684
+ " loc" : Location {
3685
+ " end" : Position {
3686
+ " column" : 49 ,
3687
+ " line" : 90 ,
3688
+ " offset" : 1847 ,
3689
+ },
3690
+ " source" : " next" ,
3691
+ " start" : Position {
3692
+ " column" : 45 ,
3693
+ " line" : 90 ,
3694
+ " offset" : 1843 ,
3695
+ },
3696
+ },
3697
+ " name" : " next" ,
3698
+ },
3667
3699
" loc" : Location {
3668
3700
" end" : Position {
3669
3701
" column" : 50 ,
Original file line number Diff line number Diff line change @@ -5,7 +5,39 @@ Program {
5
5
" children" : Array [
6
6
Goto {
7
7
" kind" : " goto" ,
8
- " label" : " a" ,
8
+ " label" : Identifier {
9
+ " kind" : " identifier" ,
10
+ " name" : " a" ,
11
+ },
12
+ },
13
+ Echo {
14
+ " expressions" : Array [
15
+ String {
16
+ " isDoubleQuote" : true ,
17
+ " kind" : " string" ,
18
+ " raw" : " \\ " Foo \\" " ,
19
+ " unicode" : false ,
20
+ " value" : " Foo" ,
21
+ },
22
+ ],
23
+ " kind" : " echo" ,
24
+ " shortForm" : false ,
25
+ },
26
+ ],
27
+ " errors" : Array [],
28
+ " kind" : " program" ,
29
+ }
30
+ ` ;
31
+
32
+ exports [` goto simple 2` ] = `
33
+ Program {
34
+ " children" : Array [
35
+ Goto {
36
+ " kind" : " goto" ,
37
+ " label" : Identifier {
38
+ " kind" : " identifier" ,
39
+ " name" : " longName" ,
40
+ },
9
41
},
10
42
Echo {
11
43
" expressions" : Array [
Original file line number Diff line number Diff line change @@ -5,7 +5,39 @@ Program {
5
5
" children" : Array [
6
6
Label {
7
7
" kind" : " label" ,
8
- " name" : " a" ,
8
+ " name" : Identifier {
9
+ " kind" : " identifier" ,
10
+ " name" : " a" ,
11
+ },
12
+ },
13
+ Echo {
14
+ " expressions" : Array [
15
+ String {
16
+ " isDoubleQuote" : true ,
17
+ " kind" : " string" ,
18
+ " raw" : " \\ " Foo \\" " ,
19
+ " unicode" : false ,
20
+ " value" : " Foo" ,
21
+ },
22
+ ],
23
+ " kind" : " echo" ,
24
+ " shortForm" : false ,
25
+ },
26
+ ],
27
+ " errors" : Array [],
28
+ " kind" : " program" ,
29
+ }
30
+ ` ;
31
+
32
+ exports [` label simple 2` ] = `
33
+ Program {
34
+ " children" : Array [
35
+ Label {
36
+ " kind" : " label" ,
37
+ " name" : Identifier {
38
+ " kind" : " identifier" ,
39
+ " name" : " longName" ,
40
+ },
9
41
},
10
42
Echo {
11
43
" expressions" : Array [
Original file line number Diff line number Diff line change @@ -5873,12 +5873,83 @@ Program {
5873
5873
}
5874
5874
` ;
5875
5875
5876
+ exports [` Test locations goto #2 1` ] = `
5877
+ Program {
5878
+ " children" : Array [
5879
+ Goto {
5880
+ " kind" : " goto" ,
5881
+ " label" : Identifier {
5882
+ " kind" : " identifier" ,
5883
+ " loc" : Location {
5884
+ " end" : Position {
5885
+ " column" : 13 ,
5886
+ " line" : 1 ,
5887
+ " offset" : 13 ,
5888
+ },
5889
+ " source" : " longName" ,
5890
+ " start" : Position {
5891
+ " column" : 5 ,
5892
+ " line" : 1 ,
5893
+ " offset" : 5 ,
5894
+ },
5895
+ },
5896
+ " name" : " longName" ,
5897
+ },
5898
+ " loc" : Location {
5899
+ " end" : Position {
5900
+ " column" : 14 ,
5901
+ " line" : 1 ,
5902
+ " offset" : 14 ,
5903
+ },
5904
+ " source" : " goto longName;" ,
5905
+ " start" : Position {
5906
+ " column" : 0 ,
5907
+ " line" : 1 ,
5908
+ " offset" : 0 ,
5909
+ },
5910
+ },
5911
+ },
5912
+ ],
5913
+ " errors" : Array [],
5914
+ " kind" : " program" ,
5915
+ " loc" : Location {
5916
+ " end" : Position {
5917
+ " column" : 14 ,
5918
+ " line" : 1 ,
5919
+ " offset" : 14 ,
5920
+ },
5921
+ " source" : " goto longName;" ,
5922
+ " start" : Position {
5923
+ " column" : 0 ,
5924
+ " line" : 1 ,
5925
+ " offset" : 0 ,
5926
+ },
5927
+ },
5928
+ }
5929
+ ` ;
5930
+
5876
5931
exports [` Test locations goto 1` ] = `
5877
5932
Program {
5878
5933
" children" : Array [
5879
5934
Goto {
5880
5935
" kind" : " goto" ,
5881
- " label" : " a" ,
5936
+ " label" : Identifier {
5937
+ " kind" : " identifier" ,
5938
+ " loc" : Location {
5939
+ " end" : Position {
5940
+ " column" : 6 ,
5941
+ " line" : 1 ,
5942
+ " offset" : 6 ,
5943
+ },
5944
+ " source" : " a" ,
5945
+ " start" : Position {
5946
+ " column" : 5 ,
5947
+ " line" : 1 ,
5948
+ " offset" : 5 ,
5949
+ },
5950
+ },
5951
+ " name" : " a" ,
5952
+ },
5882
5953
" loc" : Location {
5883
5954
" end" : Position {
5884
5955
" column" : 7 ,
@@ -6766,6 +6837,100 @@ Program {
6766
6837
}
6767
6838
` ;
6768
6839
6840
+ exports [` Test locations label #2 1` ] = `
6841
+ Program {
6842
+ " children" : Array [
6843
+ Label {
6844
+ " kind" : " label" ,
6845
+ " loc" : Location {
6846
+ " end" : Position {
6847
+ " column" : 9 ,
6848
+ " line" : 1 ,
6849
+ " offset" : 9 ,
6850
+ },
6851
+ " source" : " longName:" ,
6852
+ " start" : Position {
6853
+ " column" : 0 ,
6854
+ " line" : 1 ,
6855
+ " offset" : 0 ,
6856
+ },
6857
+ },
6858
+ " name" : Identifier {
6859
+ " kind" : " identifier" ,
6860
+ " loc" : Location {
6861
+ " end" : Position {
6862
+ " column" : 8 ,
6863
+ " line" : 1 ,
6864
+ " offset" : 8 ,
6865
+ },
6866
+ " source" : " longName" ,
6867
+ " start" : Position {
6868
+ " column" : 0 ,
6869
+ " line" : 1 ,
6870
+ " offset" : 0 ,
6871
+ },
6872
+ },
6873
+ " name" : " longName" ,
6874
+ },
6875
+ },
6876
+ Echo {
6877
+ " expressions" : Array [
6878
+ String {
6879
+ " isDoubleQuote" : true ,
6880
+ " kind" : " string" ,
6881
+ " loc" : Location {
6882
+ " end" : Position {
6883
+ " column" : 26 ,
6884
+ " line" : 1 ,
6885
+ " offset" : 26 ,
6886
+ },
6887
+ " source" : " \\ " something \\" " ,
6888
+ " start" : Position {
6889
+ " column" : 15 ,
6890
+ " line" : 1 ,
6891
+ " offset" : 15 ,
6892
+ },
6893
+ },
6894
+ " raw" : " \\ " something \\" " ,
6895
+ " unicode" : false ,
6896
+ " value" : " something" ,
6897
+ },
6898
+ ],
6899
+ " kind" : " echo" ,
6900
+ " loc" : Location {
6901
+ " end" : Position {
6902
+ " column" : 27 ,
6903
+ " line" : 1 ,
6904
+ " offset" : 27 ,
6905
+ },
6906
+ " source" : " echo \\ " something \\" ;" ,
6907
+ " start" : Position {
6908
+ " column" : 10 ,
6909
+ " line" : 1 ,
6910
+ " offset" : 10 ,
6911
+ },
6912
+ },
6913
+ " shortForm" : false ,
6914
+ },
6915
+ ],
6916
+ " errors" : Array [],
6917
+ " kind" : " program" ,
6918
+ " loc" : Location {
6919
+ " end" : Position {
6920
+ " column" : 27 ,
6921
+ " line" : 1 ,
6922
+ " offset" : 27 ,
6923
+ },
6924
+ " source" : " longName: echo \\ " something \\" ;" ,
6925
+ " start" : Position {
6926
+ " column" : 0 ,
6927
+ " line" : 1 ,
6928
+ " offset" : 0 ,
6929
+ },
6930
+ },
6931
+ }
6932
+ ` ;
6933
+
6769
6934
exports [` Test locations label 1` ] = `
6770
6935
Program {
6771
6936
" children" : Array [
@@ -6784,7 +6949,23 @@ Program {
6784
6949
" offset" : 0 ,
6785
6950
},
6786
6951
},
6787
- " name" : " a" ,
6952
+ " name" : Identifier {
6953
+ " kind" : " identifier" ,
6954
+ " loc" : Location {
6955
+ " end" : Position {
6956
+ " column" : 1 ,
6957
+ " line" : 1 ,
6958
+ " offset" : 1 ,
6959
+ },
6960
+ " source" : " a" ,
6961
+ " start" : Position {
6962
+ " column" : 0 ,
6963
+ " line" : 1 ,
6964
+ " offset" : 0 ,
6965
+ },
6966
+ },
6967
+ " name" : " a" ,
6968
+ },
6788
6969
},
6789
6970
Echo {
6790
6971
" expressions" : Array [
You can’t perform that action at this time.
0 commit comments