diff options
Diffstat (limited to 'crates/ra_parser/src/grammar/type_params.rs')
-rw-r--r-- | crates/ra_parser/src/grammar/type_params.rs | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/crates/ra_parser/src/grammar/type_params.rs b/crates/ra_parser/src/grammar/type_params.rs index 07d9b0792..4bbfed780 100644 --- a/crates/ra_parser/src/grammar/type_params.rs +++ b/crates/ra_parser/src/grammar/type_params.rs | |||
@@ -1,18 +1,18 @@ | |||
1 | use super::*; | 1 | use super::*; |
2 | 2 | ||
3 | pub(super) fn opt_type_param_list(p: &mut Parser) { | 3 | pub(super) fn opt_type_param_list(p: &mut Parser) { |
4 | if !p.at(L_ANGLE) { | 4 | if !p.at(T![<]) { |
5 | return; | 5 | return; |
6 | } | 6 | } |
7 | type_param_list(p); | 7 | type_param_list(p); |
8 | } | 8 | } |
9 | 9 | ||
10 | fn type_param_list(p: &mut Parser) { | 10 | fn type_param_list(p: &mut Parser) { |
11 | assert!(p.at(L_ANGLE)); | 11 | assert!(p.at(T![<])); |
12 | let m = p.start(); | 12 | let m = p.start(); |
13 | p.bump(); | 13 | p.bump(); |
14 | 14 | ||
15 | while !p.at(EOF) && !p.at(R_ANGLE) { | 15 | while !p.at(EOF) && !p.at(T![>]) { |
16 | let m = p.start(); | 16 | let m = p.start(); |
17 | 17 | ||
18 | // test generic_lifetime_type_attribute | 18 | // test generic_lifetime_type_attribute |
@@ -28,18 +28,18 @@ fn type_param_list(p: &mut Parser) { | |||
28 | p.err_and_bump("expected type parameter") | 28 | p.err_and_bump("expected type parameter") |
29 | } | 29 | } |
30 | } | 30 | } |
31 | if !p.at(R_ANGLE) && !p.expect(COMMA) { | 31 | if !p.at(T![>]) && !p.expect(T![,]) { |
32 | break; | 32 | break; |
33 | } | 33 | } |
34 | } | 34 | } |
35 | p.expect(R_ANGLE); | 35 | p.expect(T![>]); |
36 | m.complete(p, TYPE_PARAM_LIST); | 36 | m.complete(p, TYPE_PARAM_LIST); |
37 | } | 37 | } |
38 | 38 | ||
39 | fn lifetime_param(p: &mut Parser, m: Marker) { | 39 | fn lifetime_param(p: &mut Parser, m: Marker) { |
40 | assert!(p.at(LIFETIME)); | 40 | assert!(p.at(LIFETIME)); |
41 | p.bump(); | 41 | p.bump(); |
42 | if p.at(COLON) { | 42 | if p.at(T![:]) { |
43 | lifetime_bounds(p); | 43 | lifetime_bounds(p); |
44 | } | 44 | } |
45 | m.complete(p, LIFETIME_PARAM); | 45 | m.complete(p, LIFETIME_PARAM); |
@@ -48,12 +48,12 @@ fn lifetime_param(p: &mut Parser, m: Marker) { | |||
48 | fn type_param(p: &mut Parser, m: Marker) { | 48 | fn type_param(p: &mut Parser, m: Marker) { |
49 | assert!(p.at(IDENT)); | 49 | assert!(p.at(IDENT)); |
50 | name(p); | 50 | name(p); |
51 | if p.at(COLON) { | 51 | if p.at(T![:]) { |
52 | bounds(p); | 52 | bounds(p); |
53 | } | 53 | } |
54 | // test type_param_default | 54 | // test type_param_default |
55 | // struct S<T = i32>; | 55 | // struct S<T = i32>; |
56 | if p.at(EQ) { | 56 | if p.at(T![=]) { |
57 | p.bump(); | 57 | p.bump(); |
58 | types::type_(p) | 58 | types::type_(p) |
59 | } | 59 | } |
@@ -63,17 +63,17 @@ fn type_param(p: &mut Parser, m: Marker) { | |||
63 | // test type_param_bounds | 63 | // test type_param_bounds |
64 | // struct S<T: 'a + ?Sized + (Copy)>; | 64 | // struct S<T: 'a + ?Sized + (Copy)>; |
65 | pub(super) fn bounds(p: &mut Parser) { | 65 | pub(super) fn bounds(p: &mut Parser) { |
66 | assert!(p.at(COLON)); | 66 | assert!(p.at(T![:])); |
67 | p.bump(); | 67 | p.bump(); |
68 | bounds_without_colon(p); | 68 | bounds_without_colon(p); |
69 | } | 69 | } |
70 | 70 | ||
71 | fn lifetime_bounds(p: &mut Parser) { | 71 | fn lifetime_bounds(p: &mut Parser) { |
72 | assert!(p.at(COLON)); | 72 | assert!(p.at(T![:])); |
73 | p.bump(); | 73 | p.bump(); |
74 | while p.at(LIFETIME) { | 74 | while p.at(LIFETIME) { |
75 | p.bump(); | 75 | p.bump(); |
76 | if !p.eat(PLUS) { | 76 | if !p.eat(T![+]) { |
77 | break; | 77 | break; |
78 | } | 78 | } |
79 | } | 79 | } |
@@ -81,7 +81,7 @@ fn lifetime_bounds(p: &mut Parser) { | |||
81 | 81 | ||
82 | pub(super) fn bounds_without_colon_m(p: &mut Parser, marker: Marker) -> CompletedMarker { | 82 | pub(super) fn bounds_without_colon_m(p: &mut Parser, marker: Marker) -> CompletedMarker { |
83 | while type_bound(p) { | 83 | while type_bound(p) { |
84 | if !p.eat(PLUS) { | 84 | if !p.eat(T![+]) { |
85 | break; | 85 | break; |
86 | } | 86 | } |
87 | } | 87 | } |
@@ -96,11 +96,11 @@ pub(super) fn bounds_without_colon(p: &mut Parser) { | |||
96 | 96 | ||
97 | fn type_bound(p: &mut Parser) -> bool { | 97 | fn type_bound(p: &mut Parser) -> bool { |
98 | let m = p.start(); | 98 | let m = p.start(); |
99 | let has_paren = p.eat(L_PAREN); | 99 | let has_paren = p.eat(T!['(']); |
100 | p.eat(QUESTION); | 100 | p.eat(T![?]); |
101 | match p.current() { | 101 | match p.current() { |
102 | LIFETIME => p.bump(), | 102 | LIFETIME => p.bump(), |
103 | FOR_KW => types::for_type(p), | 103 | T![for] => types::for_type(p), |
104 | _ if paths::is_path_start(p) => types::path_type_(p, false), | 104 | _ if paths::is_path_start(p) => types::path_type_(p, false), |
105 | _ => { | 105 | _ => { |
106 | m.abandon(p); | 106 | m.abandon(p); |
@@ -108,7 +108,7 @@ fn type_bound(p: &mut Parser) -> bool { | |||
108 | } | 108 | } |
109 | } | 109 | } |
110 | if has_paren { | 110 | if has_paren { |
111 | p.expect(R_PAREN); | 111 | p.expect(T![')']); |
112 | } | 112 | } |
113 | m.complete(p, TYPE_BOUND); | 113 | m.complete(p, TYPE_BOUND); |
114 | 114 | ||
@@ -124,7 +124,7 @@ fn type_bound(p: &mut Parser) -> bool { | |||
124 | // <T as Iterator>::Item: 'a | 124 | // <T as Iterator>::Item: 'a |
125 | // {} | 125 | // {} |
126 | pub(super) fn opt_where_clause(p: &mut Parser) { | 126 | pub(super) fn opt_where_clause(p: &mut Parser) { |
127 | if !p.at(WHERE_KW) { | 127 | if !p.at(T![where]) { |
128 | return; | 128 | return; |
129 | } | 129 | } |
130 | let m = p.start(); | 130 | let m = p.start(); |
@@ -133,7 +133,7 @@ pub(super) fn opt_where_clause(p: &mut Parser) { | |||
133 | while is_where_predicate(p) { | 133 | while is_where_predicate(p) { |
134 | where_predicate(p); | 134 | where_predicate(p); |
135 | 135 | ||
136 | let comma = p.eat(COMMA); | 136 | let comma = p.eat(T![,]); |
137 | 137 | ||
138 | if is_where_clause_end(p) { | 138 | if is_where_clause_end(p) { |
139 | break; | 139 | break; |
@@ -150,13 +150,13 @@ pub(super) fn opt_where_clause(p: &mut Parser) { | |||
150 | fn is_where_predicate(p: &mut Parser) -> bool { | 150 | fn is_where_predicate(p: &mut Parser) -> bool { |
151 | match p.current() { | 151 | match p.current() { |
152 | LIFETIME => true, | 152 | LIFETIME => true, |
153 | IMPL_KW => false, | 153 | T![impl ] => false, |
154 | token => types::TYPE_FIRST.contains(token), | 154 | token => types::TYPE_FIRST.contains(token), |
155 | } | 155 | } |
156 | } | 156 | } |
157 | 157 | ||
158 | fn is_where_clause_end(p: &mut Parser) -> bool { | 158 | fn is_where_clause_end(p: &mut Parser) -> bool { |
159 | p.current() == L_CURLY || p.current() == SEMI || p.current() == EQ | 159 | p.current() == T!['{'] || p.current() == T![;] || p.current() == T![=] |
160 | } | 160 | } |
161 | 161 | ||
162 | fn where_predicate(p: &mut Parser) { | 162 | fn where_predicate(p: &mut Parser) { |
@@ -164,13 +164,13 @@ fn where_predicate(p: &mut Parser) { | |||
164 | match p.current() { | 164 | match p.current() { |
165 | LIFETIME => { | 165 | LIFETIME => { |
166 | p.bump(); | 166 | p.bump(); |
167 | if p.at(COLON) { | 167 | if p.at(T![:]) { |
168 | bounds(p); | 168 | bounds(p); |
169 | } else { | 169 | } else { |
170 | p.error("expected colon"); | 170 | p.error("expected colon"); |
171 | } | 171 | } |
172 | } | 172 | } |
173 | IMPL_KW => { | 173 | T![impl ] => { |
174 | p.error("expected lifetime or type"); | 174 | p.error("expected lifetime or type"); |
175 | } | 175 | } |
176 | _ => { | 176 | _ => { |
@@ -181,7 +181,7 @@ fn where_predicate(p: &mut Parser) { | |||
181 | // { } | 181 | // { } |
182 | types::type_(p); | 182 | types::type_(p); |
183 | 183 | ||
184 | if p.at(COLON) { | 184 | if p.at(T![:]) { |
185 | bounds(p); | 185 | bounds(p); |
186 | } else { | 186 | } else { |
187 | p.error("expected colon"); | 187 | p.error("expected colon"); |