diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-01-16 17:40:25 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-01-16 17:40:25 +0000 |
commit | 91171dedd45b93bf6a4f1b9662ebb8106f80c3b6 (patch) | |
tree | dc1c18aa49beaef7e8cf305e7b020d25cb10a58c /crates/ra_parser/src | |
parent | d3c4fbbbc45afc7d480185493b5ce77b5daa1747 (diff) | |
parent | 5398b9eeba14a3e73eb9a8b7e0d2e703e052585d (diff) |
Merge #2863
2863: Minimize test r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_parser/src')
-rw-r--r-- | crates/ra_parser/src/grammar/attributes.rs | 22 | ||||
-rw-r--r-- | crates/ra_parser/src/grammar/expressions/atom.rs | 59 |
2 files changed, 27 insertions, 54 deletions
diff --git a/crates/ra_parser/src/grammar/attributes.rs b/crates/ra_parser/src/grammar/attributes.rs index eeae37aef..f3158ade3 100644 --- a/crates/ra_parser/src/grammar/attributes.rs +++ b/crates/ra_parser/src/grammar/attributes.rs | |||
@@ -8,28 +8,6 @@ pub(super) fn inner_attributes(p: &mut Parser) { | |||
8 | } | 8 | } |
9 | } | 9 | } |
10 | 10 | ||
11 | pub(super) fn with_outer_attributes( | ||
12 | p: &mut Parser, | ||
13 | f: impl Fn(&mut Parser) -> Option<CompletedMarker>, | ||
14 | ) -> bool { | ||
15 | let am = p.start(); | ||
16 | let has_attrs = p.at(T![#]); | ||
17 | attributes::outer_attributes(p); | ||
18 | let cm = f(p); | ||
19 | let success = cm.is_some(); | ||
20 | |||
21 | match (has_attrs, cm) { | ||
22 | (true, Some(cm)) => { | ||
23 | let kind = cm.kind(); | ||
24 | cm.undo_completion(p).abandon(p); | ||
25 | am.complete(p, kind); | ||
26 | } | ||
27 | _ => am.abandon(p), | ||
28 | } | ||
29 | |||
30 | success | ||
31 | } | ||
32 | |||
33 | pub(super) fn outer_attributes(p: &mut Parser) { | 11 | pub(super) fn outer_attributes(p: &mut Parser) { |
34 | while p.at(T![#]) { | 12 | while p.at(T![#]) { |
35 | attribute(p, false) | 13 | attribute(p, false) |
diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs index 700994e80..a98a2a3ef 100644 --- a/crates/ra_parser/src/grammar/expressions/atom.rs +++ b/crates/ra_parser/src/grammar/expressions/atom.rs | |||
@@ -181,47 +181,42 @@ fn tuple_expr(p: &mut Parser) -> CompletedMarker { | |||
181 | fn array_expr(p: &mut Parser) -> CompletedMarker { | 181 | fn array_expr(p: &mut Parser) -> CompletedMarker { |
182 | assert!(p.at(T!['['])); | 182 | assert!(p.at(T!['['])); |
183 | let m = p.start(); | 183 | let m = p.start(); |
184 | p.bump(T!['[']); | ||
185 | if p.eat(T![']']) { | ||
186 | return m.complete(p, ARRAY_EXPR); | ||
187 | } | ||
188 | 184 | ||
189 | // test first_array_member_attributes | 185 | let mut n_exprs = 0u32; |
190 | // pub const A: &[i64] = &[ | 186 | let mut has_semi = false; |
191 | // #[cfg(test)] | ||
192 | // 1, | ||
193 | // 2, | ||
194 | // ]; | ||
195 | attributes::with_outer_attributes(p, |p| expr(p).0); | ||
196 | 187 | ||
197 | if p.eat(T![;]) { | 188 | p.bump(T!['[']); |
198 | expr(p); | ||
199 | p.expect(T![']']); | ||
200 | return m.complete(p, ARRAY_EXPR); | ||
201 | } | ||
202 | while !p.at(EOF) && !p.at(T![']']) { | 189 | while !p.at(EOF) && !p.at(T![']']) { |
203 | p.expect(T![,]); | 190 | n_exprs += 1; |
204 | if p.at(T![']']) { | 191 | |
205 | break; | 192 | // test array_attrs |
206 | } | 193 | // const A: &[i64] = &[1, #[cfg(test)] 2]; |
194 | let m = p.start(); | ||
195 | let has_attrs = p.at(T![#]); | ||
196 | attributes::outer_attributes(p); | ||
207 | 197 | ||
208 | // test subsequent_array_member_attributes | 198 | let cm = expr(p).0; |
209 | // pub const A: &[i64] = &[ | 199 | |
210 | // 1, | 200 | match (has_attrs, cm) { |
211 | // #[cfg(test)] | 201 | (true, Some(cm)) => { |
212 | // 2, | 202 | let kind = cm.kind(); |
213 | // ]; | 203 | cm.undo_completion(p).abandon(p); |
214 | if !attributes::with_outer_attributes(p, |p| { | 204 | m.complete(p, kind); |
215 | if !p.at_ts(EXPR_FIRST) { | ||
216 | p.error("expected expression"); | ||
217 | return None; | ||
218 | } | 205 | } |
219 | expr(p).0 | 206 | _ => m.abandon(p), |
220 | }) { | 207 | } |
208 | |||
209 | if n_exprs == 1 && p.eat(T![;]) { | ||
210 | has_semi = true; | ||
211 | continue; | ||
212 | } | ||
213 | |||
214 | if has_semi || !p.at(T![']']) && !p.expect(T![,]) { | ||
221 | break; | 215 | break; |
222 | } | 216 | } |
223 | } | 217 | } |
224 | p.expect(T![']']); | 218 | p.expect(T![']']); |
219 | |||
225 | m.complete(p, ARRAY_EXPR) | 220 | m.complete(p, ARRAY_EXPR) |
226 | } | 221 | } |
227 | 222 | ||