From 481b21cf1927a84d6fea1b7389a3a8d827656998 Mon Sep 17 00:00:00 2001 From: Brian Leibig Date: Sun, 1 Mar 2015 13:59:12 -0800 Subject: [PATCH] Bison grammar: parse higher ranked constraints in where clauses --- src/grammar/parser-lalr.y | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/grammar/parser-lalr.y b/src/grammar/parser-lalr.y index 4727b1b23fb..6c3fd186cd4 100644 --- a/src/grammar/parser-lalr.y +++ b/src/grammar/parser-lalr.y @@ -152,6 +152,12 @@ extern char *yytext; %precedence MOD_SEP %precedence RARROW ':' +// In where clauses, "for" should have greater precedence when used as +// a higher ranked constraint than when used as the beginning of a +// for_in_type (which is a ty) +%precedence FORTYPE +%precedence FOR + // Binops & unops, and their precedences %precedence BOX %precedence BOXPLACE @@ -777,10 +783,14 @@ where_predicates ; where_predicate -: lifetime ':' bounds { $$ = mk_node("WherePredicate", 2, $1, $3); } -| ty ':' ty_param_bounds { $$ = mk_node("WherePredicate", 2, $1, $3); } +: maybe_for_lifetimes lifetime ':' bounds { $$ = mk_node("WherePredicate", 3, $1, $2, $4); } +| maybe_for_lifetimes ty ':' ty_param_bounds { $$ = mk_node("WherePredicate", 3, $1, $2, $4); } ; +maybe_for_lifetimes +: FOR '<' lifetimes '>' { $$ = mk_none(); } +| %prec FORTYPE %empty { $$ = mk_none(); } + ty_params : ty_param { $$ = mk_node("TyParams", 1, $1); } | ty_params ',' ty_param { $$ = ext_node($1, 1, $3); }