Skip to content

Commit 36c3c47

Browse files
committed
Set %expect to 0 in parser (Using %prec)
1 parent 306a0f2 commit 36c3c47

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

Zend/zend_language_parser.y

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
5252
%}
5353

5454
%pure_parser
55-
%expect 8 /* 6 because traits */
55+
%expect 0
5656

5757
%code requires {
5858
}
@@ -88,6 +88,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
8888
%right T_POW
8989
%right '['
9090
%nonassoc T_NEW T_CLONE
91+
%left "if_without_else"
9192
%left T_ELSEIF
9293
%left T_ELSE
9394
%left T_ENDIF
@@ -260,7 +261,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
260261
%type <ast> identifier
261262

262263
%type <num> returns_ref function is_reference is_variadic variable_modifiers
263-
%type <num> method_modifiers trait_modifiers non_empty_member_modifiers member_modifier
264+
%type <num> method_modifiers non_empty_member_modifiers member_modifier
264265
%type <num> class_modifiers class_modifier use_type
265266

266267
%type <str> backup_doc_comment
@@ -271,17 +272,21 @@ start:
271272
top_statement_list { CG(ast) = $1; }
272273
;
273274

274-
semi_reserved:
275+
reserved_non_modifiers:
275276
T_INCLUDE | T_INCLUDE_ONCE | T_EVAL | T_REQUIRE | T_REQUIRE_ONCE | T_LOGICAL_OR | T_LOGICAL_XOR | T_LOGICAL_AND
276277
| T_INSTANCEOF | T_NEW | T_CLONE | T_EXIT | T_IF | T_ELSEIF | T_ELSE | T_ENDIF | T_ECHO | T_DO | T_WHILE | T_ENDWHILE
277278
| T_FOR | T_ENDFOR | T_FOREACH | T_ENDFOREACH | T_DECLARE | T_ENDDECLARE | T_AS | T_TRY | T_CATCH | T_FINALLY
278279
| T_THROW | T_USE | T_INSTEADOF | T_GLOBAL | T_VAR | T_UNSET | T_ISSET | T_EMPTY | T_CONTINUE | T_GOTO
279280
| T_FUNCTION | T_CONST | T_RETURN | T_PRINT | T_YIELD | T_LIST | T_SWITCH | T_ENDSWITCH | T_CASE | T_DEFAULT | T_BREAK
280281
| T_ARRAY | T_CALLABLE | T_EXTENDS | T_IMPLEMENTS | T_NAMESPACE | T_TRAIT | T_INTERFACE
281-
| T_STATIC | T_ABSTRACT | T_FINAL | T_PRIVATE | T_PROTECTED | T_PUBLIC
282282
// | T_CLASS
283283
;
284284

285+
semi_reserved:
286+
reserved_non_modifiers
287+
| T_STATIC | T_ABSTRACT | T_FINAL | T_PRIVATE | T_PROTECTED | T_PUBLIC
288+
;
289+
285290
identifier:
286291
T_STRING { $$ = $1; }
287292
| semi_reserved {
@@ -583,7 +588,7 @@ if_stmt_without_else:
583588
;
584589

585590
if_stmt:
586-
if_stmt_without_else { $$ = $1; }
591+
if_stmt_without_else %prec "if_without_else" { $$ = $1; }
587592
| if_stmt_without_else T_ELSE statement
588593
{ $$ = zend_ast_list_add($1, zend_ast_create(ZEND_AST_IF_ELEM, NULL, $3)); }
589594
;
@@ -730,9 +735,13 @@ trait_precedence:
730735
;
731736

732737
trait_alias:
733-
trait_method_reference T_AS trait_modifiers identifier
738+
trait_method_reference T_AS T_STRING
739+
{ $$ = zend_ast_create_ex(ZEND_AST_TRAIT_ALIAS, 0, $1, $3); }
740+
| trait_method_reference T_AS reserved_non_modifiers
741+
{ zval zv; zend_lex_tstring(&zv); $$ = zend_ast_create_ex(ZEND_AST_TRAIT_ALIAS, 0, $1, zend_ast_create_zval(&zv)); }
742+
| trait_method_reference T_AS member_modifier identifier
734743
{ $$ = zend_ast_create_ex(ZEND_AST_TRAIT_ALIAS, $3, $1, $4); }
735-
| trait_method_reference T_AS member_modifier
744+
| trait_method_reference T_AS member_modifier %prec '+'
736745
{ $$ = zend_ast_create_ex(ZEND_AST_TRAIT_ALIAS, $3, $1, NULL); }
737746
;
738747

@@ -747,11 +756,6 @@ absolute_trait_method_reference:
747756
{ $$ = zend_ast_create(ZEND_AST_METHOD_REFERENCE, $1, $3); }
748757
;
749758

750-
trait_modifiers:
751-
/* empty */ { $$ = 0; }
752-
| member_modifier { $$ = $1; }
753-
;
754-
755759
method_body:
756760
';' /* abstract method */ { $$ = NULL; }
757761
| '{' inner_statement_list '}' { $$ = $2; }

0 commit comments

Comments
 (0)