Skip to content

Commit 244db65

Browse files
TomasVotrubanikic
authored andcommitted
[PHP 8.0] Add trailing comma in parameter list
1 parent 53c2753 commit 244db65

File tree

4 files changed

+188
-99
lines changed

4 files changed

+188
-99
lines changed

grammar/php7.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ foreach_variable:
440440
;
441441

442442
parameter_list:
443-
non_empty_parameter_list no_comma { $$ = $1; }
443+
non_empty_parameter_list optional_comma { $$ = $1; }
444444
| /* empty */ { $$ = array(); }
445445
;
446446

lib/PhpParser/Parser/Php7.php

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ class Php7 extends \PhpParser\ParserAbstract
263263
582, 40, 427, 213, 274, 64, 850, 851, 303, 288,
264264
534, 21, 684, 223, 850, 851, 430, 431, 432, 355,
265265
384, 1019, 1082, 577, 1082, 583, 433, 434, -239, 1041,
266-
1042, 1043, 1044, 1038, 1039, 252, -92,-32766, 588, -178,
266+
1042, 1043, 1044, 1038, 1039, 252, -94,-32766, 588, -178,
267267
442, 1045, 1040, 372, 850, 851, 575, 287, 65,-32766,
268268
266, 690, 271, 276, 126, 686, 304, 882, 1019,-32766,
269269
69, 276,-32766,-32766,-32766, 276,-32766, 822,-32766, 360,
@@ -566,7 +566,7 @@ class Php7 extends \PhpParser\ParserAbstract
566566
434, 434, 92, 92, 92, 92, 429,32767, 179, 179,
567567
32767,32767,32767,32767,32767, 179, 91, 91, 91, 91,
568568
179, 179, 91, 194,32767, 192, 192, 91,32767, 93,
569-
93,32767, 93, 196,32767, 480, 196, 91, 179, 91,
569+
93,32767, 93, 196,32767, 480, 196, 93, 179, 91,
570570
216, 216, 409, 181, 255, 93, 255, 255, 93, 409,
571571
255, 179, 255, 91, 91,32767, 91, 255,32767,32767,
572572
32767, 85,32767,32767,32767,32767,32767,32767,32767,32767,
@@ -610,29 +610,29 @@ class Php7 extends \PhpParser\ParserAbstract
610610
1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1068,
611611
1068, 798, 329, 570, 1068, 1068, 1068, 1068, 1068, 1068,
612612
1068, 1068, 1068, 1068, 1066, 1066, 1005, 786, 1006, 1066,
613-
1066, 1066, 1066, 1066, 1066, 1066, 1066, 1066, 1066, 494,
614-
894, 574, 272, 466, 466, 556, 892, 254, 733, 480,
615-
505, 466, 466, 466, 331, 332, 685, 759, 544, 760,
616-
333, 487, 446, 446, 724, 293, 467, 446, 446, 446,
617-
446, 446, 446, 446, 446, 446, 446, 479, 491, 492,
618-
806, 509, 595, 522, 524, 1092, 1093, 537, 555, 558,
619-
834, 565, 573, 830, 728, 716, 866, 901, 295, 870,
620-
902, 724, 1105, 724, 809, 862, 696, 317, 321, 473,
621-
496, 499, 1016, 700, 839, 315, 799, 823, 804, 804,
622-
802, 804, 594, 390, 458, 832, 827, 538, 1115, 1115,
623-
909, 732, 705, 1012, 755, 750, 751, 765, 975, 706,
624-
752, 703, 753, 754, 704, 842, 758, 1115, 715, 715,
625-
457, 457, 3, 4, 725, 725, 725, 727, 714, 504,
626-
516, 518, 519, 567, 319, 459, 1118, 857, 302, 353,
627-
529, 472, 1017, 837, 837, 1091, 482, 483, 720, 800,
628-
800, 800, 800, 294, 325, 794, 801, 298, 299, 717,
629-
1020, 1020, 1018, 1076, 403, 849, 849, 849, 849, 849,
613+
1066, 1066, 1066, 1066, 1066, 1066, 1066, 1066, 1066, 916,
614+
272, 510, 733, 466, 466, 254, 839, 1092, 1093, 480,
615+
505, 466, 466, 466, 719, 520, 685, 713, 901, 532,
616+
533, 902, 446, 446, 724, 487, 467, 446, 446, 446,
617+
446, 446, 446, 446, 446, 446, 446, 479, 491, 494,
618+
894, 574, 595, 522, 524, 556, 892, 537, 555, 558,
619+
834, 565, 573, 830, 331, 332, 696, 759, 544, 760,
620+
333, 724, 492, 724, 509, 293, 806, 823, 804, 804,
621+
802, 804, 594, 700, 458, 832, 827, 317, 321, 473,
622+
496, 499, 295, 728, 716, 866, 3, 4, 870, 1105,
623+
390, 862, 705, 809, 755, 750, 751, 765, 538, 706,
624+
752, 703, 753, 754, 704, 799, 758, 315, 715, 715,
625+
457, 457, 975, 842, 725, 725, 725, 727, 714, 909,
626+
732, 857, 1012, 1091, 319, 459, 504, 516, 518, 519,
627+
567, 472, 353, 837, 837, 1016, 482, 483, 529, 800,
628+
800, 800, 800, 302, 720, 794, 801, 298, 299, 294,
629+
1020, 1020, 325, 717, 403, 849, 849, 849, 849, 849,
630630
849, 849, 849, 849, 1131, 1097, 1097, 11, 867, 849,
631-
849, 849, 916, 599, 510, 1088, 1088, 463, 543, 1020,
632-
1020, 1020, 1020, 1013, 520, 1020, 1020, 719, 532, 533,
633-
713, 1008, 1099, 1099, 729, 811, 871, 396, 512, 911,
634-
1078, 772, 412, 0, 773, 0, 0, 0, 0, 0,
635-
0, 0, 0, 1084, 0, 0, 0, 542, 0, 0,
631+
849, 849, 1115, 1115, 599, 1088, 1088, 463, 543, 1020,
632+
1020, 1020, 1020, 1013, 1008, 1020, 1020, 729, 811, 871,
633+
396, 1115, 1099, 1099, 512, 1017, 911, 412, 0, 0,
634+
1078, 772, 0, 0, 773, 0, 0, 0, 0, 0,
635+
1118, 0, 0, 1084, 0, 1018, 1076, 542, 0, 0,
636636
0, 0, 0, 0, 0, 0, 0, 0, 0, 478,
637637
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
638638
869, 0, 1086, 1086, 869, 0, 0, 0, 0, 0,
@@ -664,29 +664,29 @@ class Php7 extends \PhpParser\ParserAbstract
664664
87, 87, 87, 87, 87, 87, 87, 87, 87, 138,
665665
138, 77, 77, 77, 138, 138, 138, 138, 138, 138,
666666
138, 138, 138, 138, 139, 139, 68, 68, 68, 139,
667-
139, 139, 139, 139, 139, 139, 139, 139, 139, 7,
668-
7, 7, 137, 10, 10, 7, 7, 137, 36, 10,
669-
10, 10, 10, 10, 70, 70, 5, 55, 70, 55,
670-
70, 140, 141, 141, 26, 70, 10, 141, 141, 141,
671-
141, 141, 141, 141, 141, 141, 141, 39, 10, 2,
672-
40, 2, 39, 39, 39, 146, 146, 39, 39, 39,
673-
39, 39, 39, 39, 14, 14, 14, 113, 147, 14,
674-
113, 26, 149, 26, 14, 96, 16, 49, 49, 49,
675-
49, 49, 94, 13, 14, 52, 14, 16, 16, 16,
676-
16, 16, 16, 118, 16, 16, 16, 54, 150, 150,
677-
14, 14, 13, 14, 13, 13, 13, 13, 121, 13,
678-
13, 13, 13, 13, 13, 89, 13, 150, 26, 26,
679-
76, 76, 37, 37, 26, 26, 26, 26, 26, 69,
680-
69, 69, 69, 69, 66, 66, 150, 91, 20, 90,
681-
24, 66, 94, 86, 86, 144, 66, 66, 30, 76,
682-
76, 76, 76, 11, 19, 76, 76, 81, 81, 28,
683-
63, 63, 94, 94, 66, 63, 63, 63, 63, 63,
667+
139, 139, 139, 139, 139, 139, 139, 139, 139, 15,
668+
137, 15, 36, 10, 10, 137, 15, 146, 146, 10,
669+
10, 10, 10, 10, 15, 74, 5, 15, 113, 74,
670+
74, 113, 141, 141, 26, 140, 10, 141, 141, 141,
671+
141, 141, 141, 141, 141, 141, 141, 39, 10, 7,
672+
7, 7, 39, 39, 39, 7, 7, 39, 39, 39,
673+
39, 39, 39, 39, 70, 70, 16, 55, 70, 55,
674+
70, 26, 2, 26, 2, 70, 40, 16, 16, 16,
675+
16, 16, 16, 13, 16, 16, 16, 49, 49, 49,
676+
49, 49, 147, 14, 14, 14, 37, 37, 14, 149,
677+
118, 96, 13, 14, 13, 13, 13, 13, 54, 13,
678+
13, 13, 13, 13, 13, 14, 13, 52, 26, 26,
679+
76, 76, 121, 89, 26, 26, 26, 26, 26, 14,
680+
14, 91, 14, 144, 66, 66, 69, 69, 69, 69,
681+
69, 66, 90, 86, 86, 94, 66, 66, 24, 76,
682+
76, 76, 76, 20, 30, 76, 76, 81, 81, 11,
683+
63, 63, 19, 28, 66, 63, 63, 63, 63, 63,
684684
63, 63, 63, 63, 12, 8, 8, 66, 98, 63,
685-
63, 63, 15, 83, 15, 99, 99, 12, 23, 63,
686-
63, 63, 63, 130, 74, 63, 63, 15, 74, 74,
687-
15, 127, 99, 99, 32, 80, 101, 72, 73, 116,
688-
12, 63, 125, -1, 63, -1, -1, -1, -1, -1,
689-
-1, -1, -1, 99, -1, -1, -1, 12, -1, -1,
685+
63, 63, 150, 150, 83, 99, 99, 12, 23, 63,
686+
63, 63, 63, 130, 127, 63, 63, 32, 80, 101,
687+
72, 150, 99, 99, 73, 94, 116, 125, -1, -1,
688+
12, 63, -1, -1, 63, -1, -1, -1, -1, -1,
689+
150, -1, -1, 99, -1, 94, 94, 12, -1, -1,
690690
-1, -1, -1, -1, -1, -1, -1, -1, -1, 8,
691691
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
692692
99, -1, 99, 99, 99, -1, -1, -1, -1, -1,
@@ -699,22 +699,22 @@ class Php7 extends \PhpParser\ParserAbstract
699699
);
700700

701701
protected $gotoBase = array(
702-
0, 0, -338, 0, 0, 206, 0, 194, 110, 0,
703-
-146, 53, 89, -21, -123, -18, 264, 124, 155, 42,
704-
63, 0, 0, 28, 44, 0, -41, 0, 45, 0,
705-
51, 0, 32, -23, 0, 0, 199, -287, 0, -339,
706-
221, 0, 0, 0, 0, 0, 103, 0, 0, 228,
707-
0, 0, 239, 0, 74, 202, -90, 0, 0, 0,
708-
0, 0, 0, 112, 0, 0, -44, 0, -145, 75,
709-
-192, 0, 11, 2, -196, 0, 72, -97, 0, 0,
710-
31, -249, 0, 43, 0, 0, 121, -58, 0, 56,
711-
78, 77, -108, 0, -42, 0, 237, 0, 61, 137,
712-
0, 33, 0, 0, 0, 0, 0, 0, 0, 0,
713-
0, 0, 0, 20, 0, 0, 34, 0, 246, 0,
714-
0, 59, 0, 0, 0, -7, 0, 30, 0, 0,
715-
29, 0, 0, 0, 0, 0, 0, -64, -43, -28,
716-
196, 10, 0, 0, 79, 0, -60, 232, 0, 235,
717-
35, -129, 0, 0
702+
0, 0, -315, 0, 0, 206, 0, 234, 110, 0,
703+
-146, 59, 89, -21, -94, -191, 254, 124, 155, 50,
704+
78, 0, 0, 28, 52, 0, -41, 0, 49, 0,
705+
57, 0, 25, -23, 0, 0, 193, -313, 0, -339,
706+
247, 0, 0, 0, 0, 0, 103, 0, 0, 238,
707+
0, 0, 271, 0, 85, 242, -90, 0, 0, 0,
708+
0, 0, 0, 112, 0, 0, -44, 0, -145, 82,
709+
-152, 0, 4, -2, -365, 0, 72, -97, 0, 0,
710+
24, -249, 0, 44, 0, 0, 121, -58, 0, 64,
711+
81, 71, -108, 0, 21, 0, 263, 0, 61, 137,
712+
0, 26, 0, 0, 0, 0, 0, 0, 0, 0,
713+
0, 0, 0, -19, 0, 0, 31, 0, 253, 0,
714+
0, 73, 0, 0, 0, -12, 0, 23, 0, 0,
715+
29, 0, 0, 0, 0, 0, 0, -66, -43, -28,
716+
200, 10, 0, 0, 67, 0, -98, 256, 0, 262,
717+
119, -129, 0, 0
718718
);
719719

720720
protected $gotoDefault = array(

test/code/parser/errorHandling/recovery.test

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -594,14 +594,13 @@ isset($x, );
594594

595595
declare(a=42, );
596596

597-
function foo($a, ) {}
598597
foo($a, );
599598
global $a, ;
600599
static $a, ;
601600
echo $a, ;
602601

603602
for ($a, ; $b, ; $c, );
604-
function ($a, ) use ($b, ) {};
603+
function ($a) use ($b, ) {};
605604
-----
606605
!!php7
607606
A trailing comma is not allowed here from 5:6 to 5:6
@@ -614,15 +613,13 @@ A trailing comma is not allowed here from 13:17 to 13:17
614613
A trailing comma is not allowed here from 14:14 to 14:14
615614
A trailing comma is not allowed here from 16:22 to 16:22
616615
A trailing comma is not allowed here from 21:13 to 21:13
617-
A trailing comma is not allowed here from 23:16 to 23:16
616+
A trailing comma is not allowed here from 24:10 to 24:10
618617
A trailing comma is not allowed here from 25:10 to 25:10
619-
A trailing comma is not allowed here from 26:10 to 26:10
620-
A trailing comma is not allowed here from 27:8 to 27:8
621-
A trailing comma is not allowed here from 29:8 to 29:8
622-
A trailing comma is not allowed here from 29:14 to 29:14
623-
A trailing comma is not allowed here from 29:20 to 29:20
624-
A trailing comma is not allowed here from 30:13 to 30:13
625-
A trailing comma is not allowed here from 30:24 to 30:24
618+
A trailing comma is not allowed here from 26:8 to 26:8
619+
A trailing comma is not allowed here from 28:8 to 28:8
620+
A trailing comma is not allowed here from 28:14 to 28:14
621+
A trailing comma is not allowed here from 28:20 to 28:20
622+
A trailing comma is not allowed here from 29:22 to 29:22
626623
array(
627624
0: Stmt_GroupUse(
628625
type: TYPE_UNKNOWN (0)
@@ -811,27 +808,7 @@ array(
811808
)
812809
stmts: null
813810
)
814-
9: Stmt_Function(
815-
byRef: false
816-
name: Identifier(
817-
name: foo
818-
)
819-
params: array(
820-
0: Param(
821-
type: null
822-
byRef: false
823-
variadic: false
824-
var: Expr_Variable(
825-
name: a
826-
)
827-
default: null
828-
)
829-
)
830-
returnType: null
831-
stmts: array(
832-
)
833-
)
834-
10: Stmt_Expression(
811+
9: Stmt_Expression(
835812
expr: Expr_FuncCall(
836813
name: Name(
837814
parts: array(
@@ -849,14 +826,14 @@ array(
849826
)
850827
)
851828
)
852-
11: Stmt_Global(
829+
10: Stmt_Global(
853830
vars: array(
854831
0: Expr_Variable(
855832
name: a
856833
)
857834
)
858835
)
859-
12: Stmt_Static(
836+
11: Stmt_Static(
860837
vars: array(
861838
0: Stmt_StaticVar(
862839
var: Expr_Variable(
@@ -866,14 +843,14 @@ array(
866843
)
867844
)
868845
)
869-
13: Stmt_Echo(
846+
12: Stmt_Echo(
870847
exprs: array(
871848
0: Expr_Variable(
872849
name: a
873850
)
874851
)
875852
)
876-
14: Stmt_For(
853+
13: Stmt_For(
877854
init: array(
878855
0: Expr_Variable(
879856
name: a
@@ -892,7 +869,7 @@ array(
892869
stmts: array(
893870
)
894871
)
895-
15: Stmt_Expression(
872+
14: Stmt_Expression(
896873
expr: Expr_Closure(
897874
static: false
898875
byRef: false
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
Trailing comma in parameter list
2+
-----
3+
<?php
4+
5+
function foo($bar, ) {
6+
}
7+
-----
8+
!!php7
9+
array(
10+
0: Stmt_Function(
11+
byRef: false
12+
name: Identifier(
13+
name: foo
14+
)
15+
params: array(
16+
0: Param(
17+
type: null
18+
byRef: false
19+
variadic: false
20+
var: Expr_Variable(
21+
name: bar
22+
)
23+
default: null
24+
)
25+
)
26+
returnType: null
27+
stmts: array(
28+
)
29+
)
30+
)
31+
-----
32+
<?php
33+
34+
class Foo
35+
{
36+
function __construct($name, $value, )
37+
{
38+
}
39+
}
40+
-----
41+
!!php7
42+
array(
43+
0: Stmt_Class(
44+
flags: 0
45+
name: Identifier(
46+
name: Foo
47+
)
48+
extends: null
49+
implements: array(
50+
)
51+
stmts: array(
52+
0: Stmt_ClassMethod(
53+
flags: 0
54+
byRef: false
55+
name: Identifier(
56+
name: __construct
57+
)
58+
params: array(
59+
0: Param(
60+
type: null
61+
byRef: false
62+
variadic: false
63+
var: Expr_Variable(
64+
name: name
65+
)
66+
default: null
67+
)
68+
1: Param(
69+
type: null
70+
byRef: false
71+
variadic: false
72+
var: Expr_Variable(
73+
name: value
74+
)
75+
default: null
76+
)
77+
)
78+
returnType: null
79+
stmts: array(
80+
)
81+
)
82+
)
83+
)
84+
)
85+
-----
86+
<?php
87+
fn($foo, ) => $bar;
88+
-----
89+
!!php7
90+
array(
91+
0: Stmt_Expression(
92+
expr: Expr_ArrowFunction(
93+
static: false
94+
byRef: false
95+
params: array(
96+
0: Param(
97+
type: null
98+
byRef: false
99+
variadic: false
100+
var: Expr_Variable(
101+
name: foo
102+
)
103+
default: null
104+
)
105+
)
106+
returnType: null
107+
expr: Expr_Variable(
108+
name: bar
109+
)
110+
)
111+
)
112+
)

0 commit comments

Comments
 (0)