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>`
This commit is contained in:
Manish Goregaokar 2015-03-04 15:46:07 +05:30
commit 478c396b7a

View File

@ -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