diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2015-03-04 15:46:07 +0530 |
|---|---|---|
| committer | Manish Goregaokar <manishsmail@gmail.com> | 2015-03-05 12:37:48 +0530 |
| commit | 478c396b7a9e2d12ad1d15d13126ecf52f333086 (patch) | |
| tree | 6119fa19f842459a4d9c9d703d8c5e21719e3211 | |
| parent | d693ec17a502ee16689ff18f95d189870a727fb4 (diff) | |
| parent | 481b21cf1927a84d6fea1b7389a3a8d827656998 (diff) | |
| download | rust-478c396b7a9e2d12ad1d15d13126ecf52f333086.tar.gz rust-478c396b7a9e2d12ad1d15d13126ecf52f333086.zip | |
Rollup merge of #22939 - bleibig:grammar-updates, r=sanxiyn
Updates to the bison grammar to account for recent grammar additions and new tests. In particular:
* Support parsing `impl MyTrait for .. { }`
* Support parsing ExprQualifiedPaths without \"as TRAIT_REF\" such as `<Foo>::bar(&Foo)`
* Support parsing \"for\" clauses at the beginning of where clauses such as `where for<'a, 'b> &'a T: Bar<'b>`
| -rw-r--r-- | src/grammar/parser-lalr.y | 53 |
1 files changed, 38 insertions, 15 deletions
diff --git a/src/grammar/parser-lalr.y b/src/grammar/parser-lalr.y index 6a6f7e0e9f9..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 @@ -582,6 +588,14 @@ item_impl { $$ = mk_node("ItemImplNeg", 7, $1, $3, $5, $7, $8, $10, $11); } +| maybe_unsafe IMPL generic_params trait_ref FOR DOTDOT '{' '}' +{ + $$ = mk_node("ItemImplDefault", 3, $1, $3, $4); +} +| maybe_unsafe IMPL generic_params '!' trait_ref FOR DOTDOT '{' '}' +{ + $$ = mk_node("ItemImplDefaultNeg", 3, $1, $3, $4); +} ; maybe_impl_items @@ -769,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); } @@ -1024,7 +1042,8 @@ ty_qualified_path_and_generic_values } | ty_qualified_path ',' ty_sums maybe_bindings { - $$ = mk_node("GenericValues", 3, mk_none(), ext_node(mk_node("TySums", 1, $1), 1, $3), $4); } + $$ = mk_node("GenericValues", 3, mk_none(), mk_node("TySums", 2, $1, $3), $4); +} ; ty_qualified_path @@ -1513,31 +1532,35 @@ nonblock_prefix_expr ; expr_qualified_path -: '<' ty_sum AS trait_ref '>' MOD_SEP ident +: '<' ty_sum maybe_as_trait_ref '>' MOD_SEP ident { - $$ = mk_node("ExprQualifiedPath", 3, $2, $4, $7); + $$ = mk_node("ExprQualifiedPath", 3, $2, $3, $6); } -| '<' ty_sum AS trait_ref '>' MOD_SEP ident generic_args +| '<' ty_sum maybe_as_trait_ref '>' MOD_SEP ident generic_args { - $$ = mk_node("ExprQualifiedPath", 4, $2, $4, $7, $8); + $$ = mk_node("ExprQualifiedPath", 4, $2, $3, $6, $7); } -| SHL ty_sum AS trait_ref '>' MOD_SEP ident AS trait_ref '>' MOD_SEP ident +| SHL ty_sum maybe_as_trait_ref '>' MOD_SEP ident maybe_as_trait_ref '>' MOD_SEP ident { - $$ = mk_node("ExprQualifiedPath", 3, mk_node("ExprQualifiedPath", 3, $2, $4, $7), $9, $12); + $$ = mk_node("ExprQualifiedPath", 3, mk_node("ExprQualifiedPath", 3, $2, $3, $6), $7, $10); } -| SHL ty_sum AS trait_ref '>' MOD_SEP ident generic_args AS trait_ref '>' MOD_SEP ident +| SHL ty_sum maybe_as_trait_ref '>' MOD_SEP ident generic_args maybe_as_trait_ref '>' MOD_SEP ident { - $$ = mk_node("ExprQualifiedPath", 3, mk_node("ExprQualifiedPath", 4, $2, $4, $7, $8), $10, $13); + $$ = mk_node("ExprQualifiedPath", 3, mk_node("ExprQualifiedPath", 4, $2, $3, $6, $7), $8, $11); } -| SHL ty_sum AS trait_ref '>' MOD_SEP ident AS trait_ref '>' MOD_SEP ident generic_args +| SHL ty_sum maybe_as_trait_ref '>' MOD_SEP ident maybe_as_trait_ref '>' MOD_SEP ident generic_args { - $$ = mk_node("ExprQualifiedPath", 4, mk_node("ExprQualifiedPath", 3, $2, $4, $7), $9, $12, $13); + $$ = mk_node("ExprQualifiedPath", 4, mk_node("ExprQualifiedPath", 3, $2, $3, $6), $7, $10, $11); } -| SHL ty_sum AS trait_ref '>' MOD_SEP ident generic_args AS trait_ref '>' MOD_SEP ident generic_args +| SHL ty_sum maybe_as_trait_ref '>' MOD_SEP ident generic_args maybe_as_trait_ref '>' MOD_SEP ident generic_args { - $$ = mk_node("ExprQualifiedPath", 4, mk_node("ExprQualifiedPath", 4, $2, $4, $7, $8), $10, $13, $14); + $$ = mk_node("ExprQualifiedPath", 4, mk_node("ExprQualifiedPath", 4, $2, $3, $6, $7), $8, $11, $12); } +maybe_as_trait_ref +: AS trait_ref { $$ = $2; } +| %empty { $$ = mk_none(); } +; lambda_expr : %prec LAMBDA |
