Skip to content

Commit 481b21c

Browse files
committed
Bison grammar: parse higher ranked constraints in where clauses
1 parent f1fe1b5 commit 481b21c

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/grammar/parser-lalr.y

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ extern char *yytext;
152152
%precedence MOD_SEP
153153
%precedence RARROW ':'
154154
155+
// In where clauses, "for" should have greater precedence when used as
156+
// a higher ranked constraint than when used as the beginning of a
157+
// for_in_type (which is a ty)
158+
%precedence FORTYPE
159+
%precedence FOR
160+
155161
// Binops & unops, and their precedences
156162
%precedence BOX
157163
%precedence BOXPLACE
@@ -777,10 +783,14 @@ where_predicates
777783
;
778784

779785
where_predicate
780-
: lifetime ':' bounds { $$ = mk_node("WherePredicate", 2, $1, $3); }
781-
| ty ':' ty_param_bounds { $$ = mk_node("WherePredicate", 2, $1, $3); }
786+
: maybe_for_lifetimes lifetime ':' bounds { $$ = mk_node("WherePredicate", 3, $1, $2, $4); }
787+
| maybe_for_lifetimes ty ':' ty_param_bounds { $$ = mk_node("WherePredicate", 3, $1, $2, $4); }
782788
;
783789

790+
maybe_for_lifetimes
791+
: FOR '<' lifetimes '>' { $$ = mk_none(); }
792+
| %prec FORTYPE %empty { $$ = mk_none(); }
793+
784794
ty_params
785795
: ty_param { $$ = mk_node("TyParams", 1, $1); }
786796
| ty_params ',' ty_param { $$ = ext_node($1, 1, $3); }

0 commit comments

Comments
 (0)