[PHP 8.0] Add trailing comma in parameter list

This commit is contained in:
TomasVotruba 2020-06-12 19:14:34 +02:00 committed by Nikita Popov
parent 53c2753d75
commit 244db65dd1
4 changed files with 188 additions and 99 deletions

View File

@ -440,7 +440,7 @@ foreach_variable:
;
parameter_list:
non_empty_parameter_list no_comma { $$ = $1; }
non_empty_parameter_list optional_comma { $$ = $1; }
| /* empty */ { $$ = array(); }
;

View File

@ -263,7 +263,7 @@ class Php7 extends \PhpParser\ParserAbstract
582, 40, 427, 213, 274, 64, 850, 851, 303, 288,
534, 21, 684, 223, 850, 851, 430, 431, 432, 355,
384, 1019, 1082, 577, 1082, 583, 433, 434, -239, 1041,
1042, 1043, 1044, 1038, 1039, 252, -92,-32766, 588, -178,
1042, 1043, 1044, 1038, 1039, 252, -94,-32766, 588, -178,
442, 1045, 1040, 372, 850, 851, 575, 287, 65,-32766,
266, 690, 271, 276, 126, 686, 304, 882, 1019,-32766,
69, 276,-32766,-32766,-32766, 276,-32766, 822,-32766, 360,
@ -566,7 +566,7 @@ class Php7 extends \PhpParser\ParserAbstract
434, 434, 92, 92, 92, 92, 429,32767, 179, 179,
32767,32767,32767,32767,32767, 179, 91, 91, 91, 91,
179, 179, 91, 194,32767, 192, 192, 91,32767, 93,
93,32767, 93, 196,32767, 480, 196, 91, 179, 91,
93,32767, 93, 196,32767, 480, 196, 93, 179, 91,
216, 216, 409, 181, 255, 93, 255, 255, 93, 409,
255, 179, 255, 91, 91,32767, 91, 255,32767,32767,
32767, 85,32767,32767,32767,32767,32767,32767,32767,32767,
@ -610,29 +610,29 @@ class Php7 extends \PhpParser\ParserAbstract
1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1068,
1068, 798, 329, 570, 1068, 1068, 1068, 1068, 1068, 1068,
1068, 1068, 1068, 1068, 1066, 1066, 1005, 786, 1006, 1066,
1066, 1066, 1066, 1066, 1066, 1066, 1066, 1066, 1066, 494,
894, 574, 272, 466, 466, 556, 892, 254, 733, 480,
505, 466, 466, 466, 331, 332, 685, 759, 544, 760,
333, 487, 446, 446, 724, 293, 467, 446, 446, 446,
446, 446, 446, 446, 446, 446, 446, 479, 491, 492,
806, 509, 595, 522, 524, 1092, 1093, 537, 555, 558,
834, 565, 573, 830, 728, 716, 866, 901, 295, 870,
902, 724, 1105, 724, 809, 862, 696, 317, 321, 473,
496, 499, 1016, 700, 839, 315, 799, 823, 804, 804,
802, 804, 594, 390, 458, 832, 827, 538, 1115, 1115,
909, 732, 705, 1012, 755, 750, 751, 765, 975, 706,
752, 703, 753, 754, 704, 842, 758, 1115, 715, 715,
457, 457, 3, 4, 725, 725, 725, 727, 714, 504,
516, 518, 519, 567, 319, 459, 1118, 857, 302, 353,
529, 472, 1017, 837, 837, 1091, 482, 483, 720, 800,
800, 800, 800, 294, 325, 794, 801, 298, 299, 717,
1020, 1020, 1018, 1076, 403, 849, 849, 849, 849, 849,
1066, 1066, 1066, 1066, 1066, 1066, 1066, 1066, 1066, 916,
272, 510, 733, 466, 466, 254, 839, 1092, 1093, 480,
505, 466, 466, 466, 719, 520, 685, 713, 901, 532,
533, 902, 446, 446, 724, 487, 467, 446, 446, 446,
446, 446, 446, 446, 446, 446, 446, 479, 491, 494,
894, 574, 595, 522, 524, 556, 892, 537, 555, 558,
834, 565, 573, 830, 331, 332, 696, 759, 544, 760,
333, 724, 492, 724, 509, 293, 806, 823, 804, 804,
802, 804, 594, 700, 458, 832, 827, 317, 321, 473,
496, 499, 295, 728, 716, 866, 3, 4, 870, 1105,
390, 862, 705, 809, 755, 750, 751, 765, 538, 706,
752, 703, 753, 754, 704, 799, 758, 315, 715, 715,
457, 457, 975, 842, 725, 725, 725, 727, 714, 909,
732, 857, 1012, 1091, 319, 459, 504, 516, 518, 519,
567, 472, 353, 837, 837, 1016, 482, 483, 529, 800,
800, 800, 800, 302, 720, 794, 801, 298, 299, 294,
1020, 1020, 325, 717, 403, 849, 849, 849, 849, 849,
849, 849, 849, 849, 1131, 1097, 1097, 11, 867, 849,
849, 849, 916, 599, 510, 1088, 1088, 463, 543, 1020,
1020, 1020, 1020, 1013, 520, 1020, 1020, 719, 532, 533,
713, 1008, 1099, 1099, 729, 811, 871, 396, 512, 911,
1078, 772, 412, 0, 773, 0, 0, 0, 0, 0,
0, 0, 0, 1084, 0, 0, 0, 542, 0, 0,
849, 849, 1115, 1115, 599, 1088, 1088, 463, 543, 1020,
1020, 1020, 1020, 1013, 1008, 1020, 1020, 729, 811, 871,
396, 1115, 1099, 1099, 512, 1017, 911, 412, 0, 0,
1078, 772, 0, 0, 773, 0, 0, 0, 0, 0,
1118, 0, 0, 1084, 0, 1018, 1076, 542, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 478,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
869, 0, 1086, 1086, 869, 0, 0, 0, 0, 0,
@ -664,29 +664,29 @@ class Php7 extends \PhpParser\ParserAbstract
87, 87, 87, 87, 87, 87, 87, 87, 87, 138,
138, 77, 77, 77, 138, 138, 138, 138, 138, 138,
138, 138, 138, 138, 139, 139, 68, 68, 68, 139,
139, 139, 139, 139, 139, 139, 139, 139, 139, 7,
7, 7, 137, 10, 10, 7, 7, 137, 36, 10,
10, 10, 10, 10, 70, 70, 5, 55, 70, 55,
70, 140, 141, 141, 26, 70, 10, 141, 141, 141,
141, 141, 141, 141, 141, 141, 141, 39, 10, 2,
40, 2, 39, 39, 39, 146, 146, 39, 39, 39,
39, 39, 39, 39, 14, 14, 14, 113, 147, 14,
113, 26, 149, 26, 14, 96, 16, 49, 49, 49,
49, 49, 94, 13, 14, 52, 14, 16, 16, 16,
16, 16, 16, 118, 16, 16, 16, 54, 150, 150,
14, 14, 13, 14, 13, 13, 13, 13, 121, 13,
13, 13, 13, 13, 13, 89, 13, 150, 26, 26,
76, 76, 37, 37, 26, 26, 26, 26, 26, 69,
69, 69, 69, 69, 66, 66, 150, 91, 20, 90,
24, 66, 94, 86, 86, 144, 66, 66, 30, 76,
76, 76, 76, 11, 19, 76, 76, 81, 81, 28,
63, 63, 94, 94, 66, 63, 63, 63, 63, 63,
139, 139, 139, 139, 139, 139, 139, 139, 139, 15,
137, 15, 36, 10, 10, 137, 15, 146, 146, 10,
10, 10, 10, 10, 15, 74, 5, 15, 113, 74,
74, 113, 141, 141, 26, 140, 10, 141, 141, 141,
141, 141, 141, 141, 141, 141, 141, 39, 10, 7,
7, 7, 39, 39, 39, 7, 7, 39, 39, 39,
39, 39, 39, 39, 70, 70, 16, 55, 70, 55,
70, 26, 2, 26, 2, 70, 40, 16, 16, 16,
16, 16, 16, 13, 16, 16, 16, 49, 49, 49,
49, 49, 147, 14, 14, 14, 37, 37, 14, 149,
118, 96, 13, 14, 13, 13, 13, 13, 54, 13,
13, 13, 13, 13, 13, 14, 13, 52, 26, 26,
76, 76, 121, 89, 26, 26, 26, 26, 26, 14,
14, 91, 14, 144, 66, 66, 69, 69, 69, 69,
69, 66, 90, 86, 86, 94, 66, 66, 24, 76,
76, 76, 76, 20, 30, 76, 76, 81, 81, 11,
63, 63, 19, 28, 66, 63, 63, 63, 63, 63,
63, 63, 63, 63, 12, 8, 8, 66, 98, 63,
63, 63, 15, 83, 15, 99, 99, 12, 23, 63,
63, 63, 63, 130, 74, 63, 63, 15, 74, 74,
15, 127, 99, 99, 32, 80, 101, 72, 73, 116,
12, 63, 125, -1, 63, -1, -1, -1, -1, -1,
-1, -1, -1, 99, -1, -1, -1, 12, -1, -1,
63, 63, 150, 150, 83, 99, 99, 12, 23, 63,
63, 63, 63, 130, 127, 63, 63, 32, 80, 101,
72, 150, 99, 99, 73, 94, 116, 125, -1, -1,
12, 63, -1, -1, 63, -1, -1, -1, -1, -1,
150, -1, -1, 99, -1, 94, 94, 12, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, 8,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
99, -1, 99, 99, 99, -1, -1, -1, -1, -1,
@ -699,22 +699,22 @@ class Php7 extends \PhpParser\ParserAbstract
);
protected $gotoBase = array(
0, 0, -338, 0, 0, 206, 0, 194, 110, 0,
-146, 53, 89, -21, -123, -18, 264, 124, 155, 42,
63, 0, 0, 28, 44, 0, -41, 0, 45, 0,
51, 0, 32, -23, 0, 0, 199, -287, 0, -339,
221, 0, 0, 0, 0, 0, 103, 0, 0, 228,
0, 0, 239, 0, 74, 202, -90, 0, 0, 0,
0, 0, 0, 112, 0, 0, -44, 0, -145, 75,
-192, 0, 11, 2, -196, 0, 72, -97, 0, 0,
31, -249, 0, 43, 0, 0, 121, -58, 0, 56,
78, 77, -108, 0, -42, 0, 237, 0, 61, 137,
0, 33, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 20, 0, 0, 34, 0, 246, 0,
0, 59, 0, 0, 0, -7, 0, 30, 0, 0,
29, 0, 0, 0, 0, 0, 0, -64, -43, -28,
196, 10, 0, 0, 79, 0, -60, 232, 0, 235,
35, -129, 0, 0
0, 0, -315, 0, 0, 206, 0, 234, 110, 0,
-146, 59, 89, -21, -94, -191, 254, 124, 155, 50,
78, 0, 0, 28, 52, 0, -41, 0, 49, 0,
57, 0, 25, -23, 0, 0, 193, -313, 0, -339,
247, 0, 0, 0, 0, 0, 103, 0, 0, 238,
0, 0, 271, 0, 85, 242, -90, 0, 0, 0,
0, 0, 0, 112, 0, 0, -44, 0, -145, 82,
-152, 0, 4, -2, -365, 0, 72, -97, 0, 0,
24, -249, 0, 44, 0, 0, 121, -58, 0, 64,
81, 71, -108, 0, 21, 0, 263, 0, 61, 137,
0, 26, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, -19, 0, 0, 31, 0, 253, 0,
0, 73, 0, 0, 0, -12, 0, 23, 0, 0,
29, 0, 0, 0, 0, 0, 0, -66, -43, -28,
200, 10, 0, 0, 67, 0, -98, 256, 0, 262,
119, -129, 0, 0
);
protected $gotoDefault = array(

View File

@ -594,14 +594,13 @@ isset($x, );
declare(a=42, );
function foo($a, ) {}
foo($a, );
global $a, ;
static $a, ;
echo $a, ;
for ($a, ; $b, ; $c, );
function ($a, ) use ($b, ) {};
function ($a) use ($b, ) {};
-----
!!php7
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
A trailing comma is not allowed here from 14:14 to 14:14
A trailing comma is not allowed here from 16:22 to 16:22
A trailing comma is not allowed here from 21:13 to 21:13
A trailing comma is not allowed here from 23:16 to 23:16
A trailing comma is not allowed here from 24:10 to 24:10
A trailing comma is not allowed here from 25:10 to 25:10
A trailing comma is not allowed here from 26:10 to 26:10
A trailing comma is not allowed here from 27:8 to 27:8
A trailing comma is not allowed here from 29:8 to 29:8
A trailing comma is not allowed here from 29:14 to 29:14
A trailing comma is not allowed here from 29:20 to 29:20
A trailing comma is not allowed here from 30:13 to 30:13
A trailing comma is not allowed here from 30:24 to 30:24
A trailing comma is not allowed here from 26:8 to 26:8
A trailing comma is not allowed here from 28:8 to 28:8
A trailing comma is not allowed here from 28:14 to 28:14
A trailing comma is not allowed here from 28:20 to 28:20
A trailing comma is not allowed here from 29:22 to 29:22
array(
0: Stmt_GroupUse(
type: TYPE_UNKNOWN (0)
@ -811,27 +808,7 @@ array(
)
stmts: null
)
9: Stmt_Function(
byRef: false
name: Identifier(
name: foo
)
params: array(
0: Param(
type: null
byRef: false
variadic: false
var: Expr_Variable(
name: a
)
default: null
)
)
returnType: null
stmts: array(
)
)
10: Stmt_Expression(
9: Stmt_Expression(
expr: Expr_FuncCall(
name: Name(
parts: array(
@ -849,14 +826,14 @@ array(
)
)
)
11: Stmt_Global(
10: Stmt_Global(
vars: array(
0: Expr_Variable(
name: a
)
)
)
12: Stmt_Static(
11: Stmt_Static(
vars: array(
0: Stmt_StaticVar(
var: Expr_Variable(
@ -866,14 +843,14 @@ array(
)
)
)
13: Stmt_Echo(
12: Stmt_Echo(
exprs: array(
0: Expr_Variable(
name: a
)
)
)
14: Stmt_For(
13: Stmt_For(
init: array(
0: Expr_Variable(
name: a
@ -892,7 +869,7 @@ array(
stmts: array(
)
)
15: Stmt_Expression(
14: Stmt_Expression(
expr: Expr_Closure(
static: false
byRef: false

View File

@ -0,0 +1,112 @@
Trailing comma in parameter list
-----
<?php
function foo($bar, ) {
}
-----
!!php7
array(
0: Stmt_Function(
byRef: false
name: Identifier(
name: foo
)
params: array(
0: Param(
type: null
byRef: false
variadic: false
var: Expr_Variable(
name: bar
)
default: null
)
)
returnType: null
stmts: array(
)
)
)
-----
<?php
class Foo
{
function __construct($name, $value, )
{
}
}
-----
!!php7
array(
0: Stmt_Class(
flags: 0
name: Identifier(
name: Foo
)
extends: null
implements: array(
)
stmts: array(
0: Stmt_ClassMethod(
flags: 0
byRef: false
name: Identifier(
name: __construct
)
params: array(
0: Param(
type: null
byRef: false
variadic: false
var: Expr_Variable(
name: name
)
default: null
)
1: Param(
type: null
byRef: false
variadic: false
var: Expr_Variable(
name: value
)
default: null
)
)
returnType: null
stmts: array(
)
)
)
)
)
-----
<?php
fn($foo, ) => $bar;
-----
!!php7
array(
0: Stmt_Expression(
expr: Expr_ArrowFunction(
static: false
byRef: false
params: array(
0: Param(
type: null
byRef: false
variadic: false
var: Expr_Variable(
name: foo
)
default: null
)
)
returnType: null
expr: Expr_Variable(
name: bar
)
)
)
)