Permalink
Browse files

Allow trailing comma in function calls

  • Loading branch information...
ptarjan authored and sgolemon committed Feb 8, 2013
1 parent 1d6df52 commit c1b7da6a4c128af5ddfc75f515c205de9f417a1e

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,20 @@
<?php
function id($x,) {return $x;}
var_dump(id(1,));
function multiline(
$x,
$y,
) { return $x+$y; }
var_dump(multiline(
1,
2,
));
$x = 3;
$y = 4;
$c = function () use (
$x,
$y,
) { return $x+$y; };
var_dump($c());
@@ -0,0 +1,3 @@
int(1)
int(3)
int(7)
@@ -0,0 +1,3 @@
<?php
function id($x) { }
id(1,,);
@@ -0,0 +1 @@
HipHop Fatal error: syntax error, unexpected ',', expecting ')' in hphp/test/vm/trailing_comma_bad1.php on line 3
@@ -0,0 +1,3 @@
<?php
function id($x) { }
id(,1);
@@ -0,0 +1 @@
HipHop Fatal error: syntax error, unexpected ',', expecting ')' in hphp/test/vm/trailing_comma_bad2.php on line 3
@@ -0,0 +1,2 @@
<?php
function id(,$x) { }
@@ -0,0 +1 @@
HipHop Fatal error: syntax error, unexpected ',', expecting '&' or T_VARIABLE in hphp/test/vm/trailing_comma_bad3.php on line 2
@@ -0,0 +1,2 @@
<?php
function id($x,,) { }
@@ -0,0 +1 @@
HipHop Fatal error: syntax error, unexpected ',', expecting '&' or T_VARIABLE in hphp/test/vm/trailing_comma_bad4.php on line 2
@@ -0,0 +1,2 @@
<?php
function () use (,$x) { }
@@ -0,0 +1 @@
HipHop Fatal error: syntax error, unexpected ',', expecting '&' or T_VARIABLE in hphp/test/vm/trailing_comma_bad5.php on line 2
@@ -0,0 +1,2 @@
<?php
function () use ($x,,) { }
@@ -0,0 +1 @@
HipHop Fatal error: syntax error, unexpected ',', expecting ')' in hphp/test/vm/trailing_comma_bad6.php on line 2
@@ -917,6 +917,13 @@ static void only_in_strict_mode(Parser *_p) {
}
}
static void only_in_hphp_syntax(Parser *_p) {
if (!_p->enableHipHopSyntax()) {
HPHP_PARSER_ERROR("Syntax only allowed with -v Eval.EnableHipHopSyntax=true", _p);
}
}
///////////////////////////////////////////////////////////////////////////////
static int yylex(YYSTYPE *token, HPHP::Location *loc, Parser *_p) {
@@ -1474,7 +1481,8 @@ new_else_single:
parameter_list:
non_empty_parameter_list ',' T_VARARG
{ only_in_strict_mode(_p); $$ = $1; }
| non_empty_parameter_list { $$ = $1;}
| non_empty_parameter_list
possible_comma_in_hphp_syntax { $$ = $1;}
| T_VARARG { only_in_strict_mode(_p); $$.reset(); }
| { $$.reset();}
;
@@ -1507,7 +1515,8 @@ non_empty_parameter_list:
;
function_call_parameter_list:
non_empty_fcall_parameter_list { $$ = $1;}
non_empty_fcall_parameter_list
possible_comma_in_hphp_syntax { $$ = $1;}
| { $$.reset();}
;
non_empty_fcall_parameter_list:
@@ -1871,7 +1880,10 @@ dim_expr_base:
;
lexical_vars:
T_USE '(' lexical_var_list ')' { $$ = $3;}
T_USE '('
lexical_var_list
possible_comma_in_hphp_syntax
')' { $$ = $3;}
| { $$.reset();}
;
@@ -2116,6 +2128,10 @@ possible_comma:
',' { $$.reset();}
| { $$.reset();}
;
possible_comma_in_hphp_syntax:
',' { only_in_hphp_syntax(_p); $$.reset();}
| { $$.reset();}
;
non_empty_static_array_pair_list:
non_empty_static_array_pair_list
',' static_scalar T_DOUBLE_ARROW
Oops, something went wrong.

0 comments on commit c1b7da6

Please sign in to comment.