aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src
diff options
context:
space:
mode:
authorVille Penttinen <[email protected]>2019-02-17 20:19:21 +0000
committerVille Penttinen <[email protected]>2019-02-17 21:32:10 +0000
commit58d14bcaf70662506e1a289494365d976b40fc4e (patch)
treec67fd94ddc80df9dce459f4cdc526d89e4284e99 /crates/ra_syntax/src
parenta725dd4f7ac2b88541189f0f726ce86876c36add (diff)
Enable parsing attributes for generic lifetimes and type parameters
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r--crates/ra_syntax/src/ast/generated.rs2
-rw-r--r--crates/ra_syntax/src/grammar.ron7
-rw-r--r--crates/ra_syntax/src/grammar/type_params.rs22
3 files changed, 22 insertions, 9 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
index c7aaccc95..47107a58b 100644
--- a/crates/ra_syntax/src/ast/generated.rs
+++ b/crates/ra_syntax/src/ast/generated.rs
@@ -1716,6 +1716,7 @@ impl ToOwned for LifetimeParam {
1716} 1716}
1717 1717
1718 1718
1719impl ast::AttrsOwner for LifetimeParam {}
1719impl LifetimeParam { 1720impl LifetimeParam {
1720 pub fn lifetime(&self) -> Option<&Lifetime> { 1721 pub fn lifetime(&self) -> Option<&Lifetime> {
1721 super::child_opt(self) 1722 super::child_opt(self)
@@ -4076,6 +4077,7 @@ impl ToOwned for TypeParam {
4076 4077
4077 4078
4078impl ast::NameOwner for TypeParam {} 4079impl ast::NameOwner for TypeParam {}
4080impl ast::AttrsOwner for TypeParam {}
4079impl TypeParam {} 4081impl TypeParam {}
4080 4082
4081// TypeParamList 4083// TypeParamList
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron
index 193b563aa..b1775d0f8 100644
--- a/crates/ra_syntax/src/grammar.ron
+++ b/crates/ra_syntax/src/grammar.ron
@@ -559,8 +559,11 @@ Grammar(
559 ["lifetime_params", "LifetimeParam" ], 559 ["lifetime_params", "LifetimeParam" ],
560 ] 560 ]
561 ), 561 ),
562 "TypeParam": ( traits: ["NameOwner"] ), 562 "TypeParam": ( traits: ["NameOwner", "AttrsOwner"] ),
563 "LifetimeParam": ( options: [ "Lifetime" ] ), 563 "LifetimeParam": (
564 options: [ "Lifetime"],
565 traits: ["AttrsOwner"],
566 ),
564 "Lifetime": ( traits: ["AstToken"] ), 567 "Lifetime": ( traits: ["AstToken"] ),
565 "WhereClause": (), 568 "WhereClause": (),
566 "ExprStmt": ( 569 "ExprStmt": (
diff --git a/crates/ra_syntax/src/grammar/type_params.rs b/crates/ra_syntax/src/grammar/type_params.rs
index 1ec813b3e..40f998682 100644
--- a/crates/ra_syntax/src/grammar/type_params.rs
+++ b/crates/ra_syntax/src/grammar/type_params.rs
@@ -13,10 +13,20 @@ fn type_param_list(p: &mut Parser) {
13 p.bump(); 13 p.bump();
14 14
15 while !p.at(EOF) && !p.at(R_ANGLE) { 15 while !p.at(EOF) && !p.at(R_ANGLE) {
16 let m = p.start();
17
18 // test generic_lifetime_type_attribute
19 // fn foo<#[derive(Lifetime)] 'a, #[derive(Type)] T>(_: &'a T) {
20 // }
21 attributes::outer_attributes(p);
22
16 match p.current() { 23 match p.current() {
17 LIFETIME => lifetime_param(p), 24 LIFETIME => lifetime_param(p, m),
18 IDENT => type_param(p), 25 IDENT => type_param(p, m),
19 _ => p.err_and_bump("expected type parameter"), 26 _ => {
27 m.abandon(p);
28 p.err_and_bump("expected type parameter")
29 }
20 } 30 }
21 if !p.at(R_ANGLE) && !p.expect(COMMA) { 31 if !p.at(R_ANGLE) && !p.expect(COMMA) {
22 break; 32 break;
@@ -26,9 +36,8 @@ fn type_param_list(p: &mut Parser) {
26 m.complete(p, TYPE_PARAM_LIST); 36 m.complete(p, TYPE_PARAM_LIST);
27} 37}
28 38
29fn lifetime_param(p: &mut Parser) { 39fn lifetime_param(p: &mut Parser, m: Marker) {
30 assert!(p.at(LIFETIME)); 40 assert!(p.at(LIFETIME));
31 let m = p.start();
32 p.bump(); 41 p.bump();
33 if p.at(COLON) { 42 if p.at(COLON) {
34 lifetime_bounds(p); 43 lifetime_bounds(p);
@@ -36,9 +45,8 @@ fn lifetime_param(p: &mut Parser) {
36 m.complete(p, LIFETIME_PARAM); 45 m.complete(p, LIFETIME_PARAM);
37} 46}
38 47
39fn type_param(p: &mut Parser) { 48fn type_param(p: &mut Parser, m: Marker) {
40 assert!(p.at(IDENT)); 49 assert!(p.at(IDENT));
41 let m = p.start();
42 name(p); 50 name(p);
43 if p.at(COLON) { 51 if p.at(COLON) {
44 bounds(p); 52 bounds(p);