Skip to content

Commit cd479e6

Browse files
committed
zend_language_parser: Improve parser definition for clone()
1 parent 2e2cbc8 commit cd479e6

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

Zend/zend_language_parser.y

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
4646
%define api.pure full
4747
%define api.value.type {zend_parser_stack_elem}
4848
%define parse.error verbose
49-
%expect 1
49+
%expect 0
5050

5151
%destructor { zend_ast_destroy($$); } <ast>
5252
%destructor { if ($$) zend_string_release_ex($$, 0); } <str>
@@ -259,7 +259,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
259259
%type <ast> unprefixed_use_declarations const_decl inner_statement
260260
%type <ast> expr optional_expr while_statement for_statement foreach_variable
261261
%type <ast> foreach_statement declare_statement finally_statement unset_variable variable
262-
%type <ast> extends_from parameter optional_type_without_static argument global_var
262+
%type <ast> extends_from parameter optional_type_without_static argument argument_no_expr global_var
263263
%type <ast> static_var class_statement trait_adaptation trait_precedence trait_alias
264264
%type <ast> absolute_trait_method_reference trait_method_reference property echo_expr
265265
%type <ast> new_dereferenceable new_non_dereferenceable anonymous_class class_name class_name_reference simple_variable
@@ -287,7 +287,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
287287
%type <ast> enum_declaration_statement enum_backing_type enum_case enum_case_expr
288288
%type <ast> function_name non_empty_member_modifiers
289289
%type <ast> property_hook property_hook_list optional_property_hook_list hooked_property property_hook_body
290-
%type <ast> optional_parameter_list
290+
%type <ast> optional_parameter_list clone_argument_list non_empty_clone_argument_list
291291

292292
%type <num> returns_ref function fn is_reference is_variadic property_modifiers property_hook_modifiers
293293
%type <num> method_modifiers class_const_modifiers member_modifier optional_cpp_modifiers
@@ -914,13 +914,33 @@ non_empty_argument_list:
914914
{ $$ = zend_ast_list_add($1, $3); }
915915
;
916916

917-
argument:
918-
expr { $$ = $1; }
919-
| identifier ':' expr
917+
clone_argument_list:
918+
'(' ')' { $$ = zend_ast_create_list(0, ZEND_AST_ARG_LIST); }
919+
| '(' non_empty_clone_argument_list possible_comma ')' { $$ = $2; }
920+
| '(' expr ',' ')' { $$ = zend_ast_create_list(1, ZEND_AST_ARG_LIST, $2); }
921+
| '(' T_ELLIPSIS ')' { $$ = zend_ast_create_fcc(); }
922+
;
923+
924+
non_empty_clone_argument_list:
925+
expr ',' argument
926+
{ $$ = zend_ast_create_list(2, ZEND_AST_ARG_LIST, $1, $3); }
927+
| argument_no_expr
928+
{ $$ = zend_ast_create_list(1, ZEND_AST_ARG_LIST, $1); }
929+
| non_empty_clone_argument_list ',' argument
930+
{ $$ = zend_ast_list_add($1, $3); }
931+
;
932+
933+
argument_no_expr:
934+
identifier ':' expr
920935
{ $$ = zend_ast_create(ZEND_AST_NAMED_ARG, $1, $3); }
921936
| T_ELLIPSIS expr { $$ = zend_ast_create(ZEND_AST_UNPACK, $2); }
922937
;
923938

939+
argument:
940+
expr { $$ = $1; }
941+
| argument_no_expr { $$ = $1; }
942+
;
943+
924944
global_var_list:
925945
global_var_list ',' global_var { $$ = zend_ast_list_add($1, $3); }
926946
| global_var { $$ = zend_ast_create_list(1, ZEND_AST_STMT_LIST, $1); }
@@ -1228,7 +1248,7 @@ expr:
12281248
{ $$ = zend_ast_create(ZEND_AST_ASSIGN, $1, $3); }
12291249
| variable '=' ampersand variable
12301250
{ $$ = zend_ast_create(ZEND_AST_ASSIGN_REF, $1, $4); }
1231-
| T_CLONE argument_list {
1251+
| T_CLONE clone_argument_list {
12321252
zend_ast *name = zend_ast_create_zval_from_str(ZSTR_KNOWN(ZEND_STR_CLONE));
12331253
name->attr = ZEND_NAME_FQ;
12341254
$$ = zend_ast_create(ZEND_AST_CALL, name, $2);

0 commit comments

Comments
 (0)