diff options
author | Evgenii P <[email protected]> | 2019-08-07 17:42:28 +0100 |
---|---|---|
committer | Evgenii P <[email protected]> | 2019-08-07 17:42:28 +0100 |
commit | 3fb58c620ccf93487cc3b9b8718002481826b4c2 (patch) | |
tree | 74bd7954df7861c40122f8b3e09f0d293252fc8b /crates/ra_parser/src/grammar | |
parent | 9ea4ae680a2d3ce2da38cd7fc6c039e5d7d03171 (diff) |
Add function parameters attributes
Diffstat (limited to 'crates/ra_parser/src/grammar')
-rw-r--r-- | crates/ra_parser/src/grammar/params.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/crates/ra_parser/src/grammar/params.rs b/crates/ra_parser/src/grammar/params.rs index 723b56343..fce9dd218 100644 --- a/crates/ra_parser/src/grammar/params.rs +++ b/crates/ra_parser/src/grammar/params.rs | |||
@@ -5,12 +5,15 @@ use super::*; | |||
5 | // fn b(x: i32) {} | 5 | // fn b(x: i32) {} |
6 | // fn c(x: i32, ) {} | 6 | // fn c(x: i32, ) {} |
7 | // fn d(x: i32, y: ()) {} | 7 | // fn d(x: i32, y: ()) {} |
8 | // fn g1(#[attr1] #[attr2] pat: Type) {} | ||
9 | // fn g2(#[attr1] x: u8) {} | ||
8 | pub(super) fn param_list(p: &mut Parser) { | 10 | pub(super) fn param_list(p: &mut Parser) { |
9 | list_(p, Flavor::Normal) | 11 | list_(p, Flavor::Normal) |
10 | } | 12 | } |
11 | 13 | ||
12 | // test param_list_opt_patterns | 14 | // test param_list_opt_patterns |
13 | // fn foo<F: FnMut(&mut Foo<'a>)>(){} | 15 | // fn foo<F: FnMut(&mut Foo<'a>)>(){} |
16 | // fn foo<F: FnMut(#[attr] &mut Foo<'a>)>(){} | ||
14 | pub(super) fn param_list_opt_patterns(p: &mut Parser) { | 17 | pub(super) fn param_list_opt_patterns(p: &mut Parser) { |
15 | list_(p, Flavor::OptionalPattern) | 18 | list_(p, Flavor::OptionalPattern) |
16 | } | 19 | } |
@@ -41,9 +44,12 @@ fn list_(p: &mut Parser, flavor: Flavor) { | |||
41 | let m = p.start(); | 44 | let m = p.start(); |
42 | p.bump(); | 45 | p.bump(); |
43 | if flavor.type_required() { | 46 | if flavor.type_required() { |
47 | attributes::outer_attributes(p); | ||
44 | opt_self_param(p); | 48 | opt_self_param(p); |
45 | } | 49 | } |
46 | while !p.at(EOF) && !p.at(ket) && !(flavor.type_required() && p.at(T![...])) { | 50 | while !p.at(EOF) && !p.at(ket) && !(flavor.type_required() && p.at(T![...])) { |
51 | attributes::outer_attributes(p); | ||
52 | |||
47 | if !p.at_ts(VALUE_PARAMETER_FIRST) { | 53 | if !p.at_ts(VALUE_PARAMETER_FIRST) { |
48 | p.error("expected value parameter"); | 54 | p.error("expected value parameter"); |
49 | break; | 55 | break; |
@@ -55,6 +61,7 @@ fn list_(p: &mut Parser, flavor: Flavor) { | |||
55 | } | 61 | } |
56 | // test param_list_vararg | 62 | // test param_list_vararg |
57 | // extern "C" { fn printf(format: *const i8, ...) -> i32; } | 63 | // extern "C" { fn printf(format: *const i8, ...) -> i32; } |
64 | // extern "C" { fn printf(#[attr] format: *const i8, ...) -> i32; } | ||
58 | if flavor.type_required() { | 65 | if flavor.type_required() { |
59 | p.eat(T![...]); | 66 | p.eat(T![...]); |
60 | } | 67 | } |
@@ -84,6 +91,7 @@ fn value_parameter(p: &mut Parser, flavor: Flavor) { | |||
84 | // test trait_fn_placeholder_parameter | 91 | // test trait_fn_placeholder_parameter |
85 | // trait Foo { | 92 | // trait Foo { |
86 | // fn bar(_: u64, mut x: i32); | 93 | // fn bar(_: u64, mut x: i32); |
94 | // fn bar(#[attr] _: u64, #[attr] mut x: i32); | ||
87 | // } | 95 | // } |
88 | if (la0 == IDENT || la0 == T![_]) && la1 == T![:] | 96 | if (la0 == IDENT || la0 == T![_]) && la1 == T![:] |
89 | || la0 == T![mut] && la1 == IDENT && la2 == T![:] | 97 | || la0 == T![mut] && la1 == IDENT && la2 == T![:] |
@@ -107,6 +115,12 @@ fn value_parameter(p: &mut Parser, flavor: Flavor) { | |||
107 | // fn c(&'a self,) {} | 115 | // fn c(&'a self,) {} |
108 | // fn d(&'a mut self, x: i32) {} | 116 | // fn d(&'a mut self, x: i32) {} |
109 | // fn e(mut self) {} | 117 | // fn e(mut self) {} |
118 | // fn f(#[must_use] self) {} | ||
119 | // fn g1(#[attr] self) {} | ||
120 | // fn g2(#[attr] &self) {} | ||
121 | // fn g3<'a>(#[attr] &mut self) {} | ||
122 | // fn g4<'a>(#[attr] &'a self) {} | ||
123 | // fn g5<'a>(#[attr] &'a mut self) {} | ||
110 | // } | 124 | // } |
111 | fn opt_self_param(p: &mut Parser) { | 125 | fn opt_self_param(p: &mut Parser) { |
112 | let m; | 126 | let m; |
@@ -118,6 +132,8 @@ fn opt_self_param(p: &mut Parser) { | |||
118 | // impl S { | 132 | // impl S { |
119 | // fn a(self: &Self) {} | 133 | // fn a(self: &Self) {} |
120 | // fn b(mut self: Box<Self>) {} | 134 | // fn b(mut self: Box<Self>) {} |
135 | // fn c(#[attr] self: Self) {} | ||
136 | // fn d(#[attr] self: Rc<Self>) {} | ||
121 | // } | 137 | // } |
122 | if p.at(T![:]) { | 138 | if p.at(T![:]) { |
123 | types::ascription(p); | 139 | types::ascription(p); |