diff options
author | Bob Weinand <bobwei9@hotmail.com> | 2016-04-05 00:34:42 +0200 |
---|---|---|
committer | Bob Weinand <bobwei9@hotmail.com> | 2016-05-20 01:51:05 +0200 |
commit | 4f077aee836ad7d8335cf62629a8364bdf939db9 (patch) | |
tree | f9853b092345e1847f43e1e9cbb846bebe0cc3c3 /Zend/zend_language_parser.y | |
parent | 14a71cf545bf652202a3f056daefd654ad311eb5 (diff) | |
download | php-git-4f077aee836ad7d8335cf62629a8364bdf939db9.tar.gz |
Allow for [] = $array; (alias for list())
Diffstat (limited to 'Zend/zend_language_parser.y')
-rw-r--r-- | Zend/zend_language_parser.y | 69 |
1 files changed, 21 insertions, 48 deletions
diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y index bedb7e62bc..5f233d6a3b 100644 --- a/Zend/zend_language_parser.y +++ b/Zend/zend_language_parser.y @@ -241,7 +241,6 @@ static YYSIZE_T zend_yytnamerr(char*, const char*); %type <ast> exit_expr scalar backticks_expr lexical_var function_call member_name property_name %type <ast> variable_class_name dereferencable_scalar constant dereferencable %type <ast> callable_expr callable_variable static_member new_variable -%type <ast> unkeyed_assignment_list_element keyed_assignment_list_element array_pair %type <ast> encaps_var encaps_var_offset isset_variables %type <ast> top_statement_list use_declarations const_list inner_statement_list if_stmt %type <ast> alt_if_stmt for_exprs switch_case_list global_var_list static_var_list @@ -250,8 +249,8 @@ static YYSIZE_T zend_yytnamerr(char*, const char*); %type <ast> non_empty_parameter_list argument_list non_empty_argument_list property_list %type <ast> class_const_list class_const_decl name_list trait_adaptations method_body non_empty_for_exprs %type <ast> ctor_arguments alt_if_stmt_without_else trait_adaptation_list lexical_vars -%type <ast> lexical_var_list encaps_list array_pair_list non_empty_array_pair_list -%type <ast> assignment_list unkeyed_assignment_list keyed_assignment_list +%type <ast> lexical_var_list encaps_list +%type <ast> array_pair non_empty_array_pair_list array_pair_list %type <ast> isset_variable type return_type %type <ast> identifier @@ -545,7 +544,8 @@ implements_list: foreach_variable: variable { $$ = $1; } | '&' variable { $$ = zend_ast_create(ZEND_AST_REF, $2); } - | T_LIST '(' assignment_list ')' { $$ = $3; } + | T_LIST '(' array_pair_list ')' { $3->attr = 1; $$ = $3; } + | '[' array_pair_list ']' { $$ = $2; } ; for_statement: @@ -860,8 +860,10 @@ new_expr: ; expr_without_variable: - T_LIST '(' assignment_list ')' '=' expr - { $$ = zend_ast_create(ZEND_AST_ASSIGN, $3, $6); } + T_LIST '(' array_pair_list ')' '=' expr + { $3->attr = 1; $$ = zend_ast_create(ZEND_AST_ASSIGN, $3, $6); } + | '[' array_pair_list ']' '=' expr + { $$ = zend_ast_create(ZEND_AST_ASSIGN, $2, $5); } | variable '=' expr { $$ = zend_ast_create(ZEND_AST_ASSIGN, $1, $3); } | variable '=' '&' variable @@ -1086,11 +1088,6 @@ constant: { $$ = zend_ast_create(ZEND_AST_CLASS_CONST, $1, $3); } ; -possible_comma: - /* empty */ - | ',' -; - expr: variable { $$ = $1; } | expr_without_variable { $$ = $1; } @@ -1180,44 +1177,9 @@ property_name: | simple_variable { $$ = zend_ast_create(ZEND_AST_VAR, $1); } ; -assignment_list: - unkeyed_assignment_list - { $$ = $1; } - | keyed_assignment_list possible_comma - { $$ = $1; } -; - -unkeyed_assignment_list: - unkeyed_assignment_list ',' unkeyed_assignment_list_element - { $$ = zend_ast_list_add($1, $3); } - | unkeyed_assignment_list_element - { $$ = zend_ast_create_list(1, ZEND_AST_LIST, $1); } -; - -unkeyed_assignment_list_element: - variable { $$ = $1; } - | T_LIST '(' assignment_list ')' { $$ = $3; } - | /* empty */ { $$ = NULL; } -; - -keyed_assignment_list: - keyed_assignment_list ',' keyed_assignment_list_element - { $$ = zend_ast_list_add($1, $3); } - | keyed_assignment_list_element - { $$ = zend_ast_create_list(1, ZEND_AST_LIST, $1); } -; - -keyed_assignment_list_element: - expr T_DOUBLE_ARROW variable - { $$ = zend_ast_create(ZEND_AST_ARRAY_ELEM, $3, $1); } - | expr T_DOUBLE_ARROW T_LIST '(' assignment_list ')' - { $$ = zend_ast_create(ZEND_AST_ARRAY_ELEM, $5, $1); } -; - - array_pair_list: /* empty */ { $$ = zend_ast_create_list(0, ZEND_AST_ARRAY); } - | non_empty_array_pair_list possible_comma { $$ = $1; } + | non_empty_array_pair_list { /* allow single trailing comma */ zend_ast_list *list = zend_ast_get_list($$ = $1); if (list->child[list->children - 1] == NULL) { list->children--; } } ; non_empty_array_pair_list: @@ -1225,16 +1187,27 @@ non_empty_array_pair_list: { $$ = zend_ast_list_add($1, $3); } | array_pair { $$ = zend_ast_create_list(1, ZEND_AST_ARRAY, $1); } + | non_empty_array_pair_list ',' /* empty, for LHS array lists */ + { $$ = zend_ast_list_add($1, NULL); } + | ',' + { $$ = zend_ast_create_list(1, ZEND_AST_ARRAY, NULL); } + | ',' array_pair + { $$ = zend_ast_create_list(2, ZEND_AST_ARRAY, NULL, $2); } ; array_pair: expr T_DOUBLE_ARROW expr { $$ = zend_ast_create(ZEND_AST_ARRAY_ELEM, $3, $1); } - | expr { $$ = zend_ast_create(ZEND_AST_ARRAY_ELEM, $1, NULL); } + | expr + { $$ = zend_ast_create(ZEND_AST_ARRAY_ELEM, $1, NULL); } | expr T_DOUBLE_ARROW '&' variable { $$ = zend_ast_create_ex(ZEND_AST_ARRAY_ELEM, 1, $4, $1); } | '&' variable { $$ = zend_ast_create_ex(ZEND_AST_ARRAY_ELEM, 1, $2, NULL); } + | expr T_DOUBLE_ARROW T_LIST '(' array_pair_list ')' + { $5->attr = 1; $$ = zend_ast_create(ZEND_AST_ARRAY_ELEM, $5, $1); } + | T_LIST '(' array_pair_list ')' + { $3->attr = 1; $$ = zend_ast_create(ZEND_AST_ARRAY_ELEM, $3, NULL); } ; encaps_list: |