@@ -68,7 +68,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
68
68
%left T_BOOLEAN_AND
69
69
%left ' |'
70
70
%left ' ^'
71
- %left ' & '
71
+ %left T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG
72
72
%nonassoc T_IS_EQUAL T_IS_NOT_EQUAL T_IS_IDENTICAL T_IS_NOT_IDENTICAL T_SPACESHIP
73
73
%nonassoc ' <' T_IS_SMALLER_OR_EQUAL ' >' T_IS_GREATER_OR_EQUAL
74
74
%left ' .'
@@ -231,6 +231,8 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
231
231
%token T_COALESCE " '??'"
232
232
%token T_POW " '**'"
233
233
%token T_POW_EQUAL " '**='"
234
+ %token T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG " '&'"
235
+ %token T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG " '&''"
234
236
%token T_BAD_CHARACTER " invalid character"
235
237
236
238
/* Token used to force a parse error from the lexer */
@@ -264,7 +266,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
264
266
%type <ast> lexical_var_list encaps_list
265
267
%type <ast> array_pair non_empty_array_pair_list array_pair_list possible_array_pair
266
268
%type <ast> isset_variable type return_type type_expr type_without_static
267
- %type <ast> identifier type_expr_without_static union_type_without_static
269
+ %type <ast> identifier type_expr_without_static union_type_without_static intersection_type_without_static
268
270
%type <ast> inline_function union_type intersection_type
269
271
%type <ast> attributed_statement attributed_class_statement attributed_parameter
270
272
%type <ast> attribute_decl attribute attributes attribute_group namespace_declaration_name
@@ -301,6 +303,11 @@ semi_reserved:
301
303
| T_STATIC | T_ABSTRACT | T_FINAL | T_PRIVATE | T_PROTECTED | T_PUBLIC
302
304
;
303
305
306
+ ampersand :
307
+ T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG
308
+ | T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG
309
+ ;
310
+
304
311
identifier :
305
312
T_STRING { $$ = $1 ; }
306
313
| semi_reserved {
@@ -555,7 +562,7 @@ function_declaration_statement:
555
562
556
563
is_reference :
557
564
%empty { $$ = 0 ; }
558
- | ' & ' { $$ = ZEND_PARAM_REF; }
565
+ | T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG { $$ = ZEND_PARAM_REF; }
559
566
;
560
567
561
568
is_variadic :
@@ -633,7 +640,7 @@ implements_list:
633
640
634
641
foreach_variable :
635
642
variable { $$ = $1 ; }
636
- | ' & ' variable { $$ = zend_ast_create(ZEND_AST_REF, $2 ); }
643
+ | ampersand variable { $$ = zend_ast_create(ZEND_AST_REF, $2 ); }
637
644
| T_LIST ' (' array_pair_list ' )' { $$ = $3 ; $$ ->attr = ZEND_ARRAY_SYNTAX_LIST; }
638
645
| ' [' array_pair_list ' ]' { $$ = $2 ; $$ ->attr = ZEND_ARRAY_SYNTAX_SHORT; }
639
646
;
@@ -799,8 +806,8 @@ union_type:
799
806
;
800
807
801
808
intersection_type :
802
- type ' & ' type { $$ = zend_ast_create_list(2 , ZEND_AST_TYPE_INTERSECTION, $1 , $3 ); }
803
- | intersection_type ' & ' type { $$ = zend_ast_list_add($1 , $3 ); }
809
+ type T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG type { $$ = zend_ast_create_list(2 , ZEND_AST_TYPE_INTERSECTION, $1 , $3 ); }
810
+ | intersection_type T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG type { $$ = zend_ast_list_add($1 , $3 ); }
804
811
;
805
812
806
813
/* Duplicate the type rules without "static",
@@ -810,6 +817,7 @@ type_expr_without_static:
810
817
type_without_static { $$ = $1 ; }
811
818
| ' ?' type_without_static { $$ = $2 ; $$ ->attr |= ZEND_TYPE_NULLABLE; }
812
819
| union_type_without_static { $$ = $1 ; }
820
+ | intersection_type_without_static { $$ = $1 ; }
813
821
;
814
822
815
823
type_without_static :
@@ -825,7 +833,12 @@ union_type_without_static:
825
833
{ $$ = zend_ast_list_add($1 , $3 ); }
826
834
;
827
835
828
- // TODO Check if need to do intersection without static (seems weird)
836
+ intersection_type_without_static :
837
+ type_without_static T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG type_without_static
838
+ { $$ = zend_ast_create_list(2 , ZEND_AST_TYPE_INTERSECTION, $1 , $3 ); }
839
+ | intersection_type_without_static T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG type_without_static
840
+ { $$ = zend_ast_list_add($1 , $3 ); }
841
+ ;
829
842
830
843
return_type :
831
844
%empty { $$ = NULL ; }
@@ -1055,7 +1068,7 @@ expr:
1055
1068
{ $2 ->attr = ZEND_ARRAY_SYNTAX_SHORT; $$ = zend_ast_create(ZEND_AST_ASSIGN, $2 , $5 ); }
1056
1069
| variable ' =' expr
1057
1070
{ $$ = zend_ast_create(ZEND_AST_ASSIGN, $1 , $3 ); }
1058
- | variable ' =' ' & ' variable
1071
+ | variable ' =' ampersand variable
1059
1072
{ $$ = zend_ast_create(ZEND_AST_ASSIGN_REF, $1 , $4 ); }
1060
1073
| T_CLONE expr { $$ = zend_ast_create(ZEND_AST_CLONE, $2 ); }
1061
1074
| variable T_PLUS_EQUAL expr
@@ -1099,7 +1112,8 @@ expr:
1099
1112
| expr T_LOGICAL_XOR expr
1100
1113
{ $$ = zend_ast_create_binary_op(ZEND_BOOL_XOR, $1 , $3 ); }
1101
1114
| expr ' |' expr { $$ = zend_ast_create_binary_op(ZEND_BW_OR, $1 , $3 ); }
1102
- | expr ' &' expr { $$ = zend_ast_create_binary_op(ZEND_BW_AND, $1 , $3 ); }
1115
+ | expr T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG expr { $$ = zend_ast_create_binary_op(ZEND_BW_AND, $1 , $3 ); }
1116
+ | expr T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG expr { $$ = zend_ast_create_binary_op(ZEND_BW_AND, $1 , $3 ); }
1103
1117
| expr ' ^' expr { $$ = zend_ast_create_binary_op(ZEND_BW_XOR, $1 , $3 ); }
1104
1118
| expr ' .' expr { $$ = zend_ast_create_binary_op(ZEND_CONCAT, $1 , $3 ); }
1105
1119
| expr ' +' expr { $$ = zend_ast_create_binary_op(ZEND_ADD, $1 , $3 ); }
@@ -1209,7 +1223,7 @@ backup_lex_pos:
1209
1223
1210
1224
returns_ref :
1211
1225
%empty { $$ = 0 ; }
1212
- | ' & ' { $$ = ZEND_ACC_RETURN_REFERENCE; }
1226
+ | ampersand { $$ = ZEND_ACC_RETURN_REFERENCE; }
1213
1227
;
1214
1228
1215
1229
lexical_vars :
@@ -1224,7 +1238,7 @@ lexical_var_list:
1224
1238
1225
1239
lexical_var :
1226
1240
T_VARIABLE { $$ = $1 ; }
1227
- | ' & ' T_VARIABLE { $$ = $2 ; $$ ->attr = ZEND_BIND_REF; }
1241
+ | ampersand T_VARIABLE { $$ = $2 ; $$ ->attr = ZEND_BIND_REF; }
1228
1242
;
1229
1243
1230
1244
function_call :
@@ -1424,9 +1438,9 @@ array_pair:
1424
1438
{ $$ = zend_ast_create(ZEND_AST_ARRAY_ELEM, $3 , $1 ); }
1425
1439
| expr
1426
1440
{ $$ = zend_ast_create(ZEND_AST_ARRAY_ELEM, $1 , NULL ); }
1427
- | expr T_DOUBLE_ARROW ' & ' variable
1441
+ | expr T_DOUBLE_ARROW ampersand variable
1428
1442
{ $$ = zend_ast_create_ex(ZEND_AST_ARRAY_ELEM, 1 , $4 , $1 ); }
1429
- | ' & ' variable
1443
+ | ampersand variable
1430
1444
{ $$ = zend_ast_create_ex(ZEND_AST_ARRAY_ELEM, 1 , $2 , NULL ); }
1431
1445
| T_ELLIPSIS expr
1432
1446
{ $$ = zend_ast_create(ZEND_AST_UNPACK, $2 ); }
0 commit comments