aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src/grammar/expressions
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_parser/src/grammar/expressions')
-rw-r--r--crates/ra_parser/src/grammar/expressions/atom.rs57
1 files changed, 27 insertions, 30 deletions
diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs
index 4ac1d6334..a98a2a3ef 100644
--- a/crates/ra_parser/src/grammar/expressions/atom.rs
+++ b/crates/ra_parser/src/grammar/expressions/atom.rs
@@ -181,45 +181,42 @@ fn tuple_expr(p: &mut Parser) -> CompletedMarker {
181fn array_expr(p: &mut Parser) -> CompletedMarker { 181fn 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::outer_attributes(p);
196 187
197 expr(p); 188 p.bump(T!['[']);
198 if p.eat(T![;]) {
199 expr(p);
200 p.expect(T![']']);
201 return m.complete(p, ARRAY_EXPR);
202 }
203 while !p.at(EOF) && !p.at(T![']']) { 189 while !p.at(EOF) && !p.at(T![']']) {
204 p.expect(T![,]); 190 n_exprs += 1;
205 if p.at(T![']']) {
206 break;
207 }
208 191
209 // test subsequent_array_member_attributes 192 // test array_attrs
210 // pub const A: &[i64] = &[ 193 // const A: &[i64] = &[1, #[cfg(test)] 2];
211 // 1, 194 let m = p.start();
212 // #[cfg(test)] 195 let has_attrs = p.at(T![#]);
213 // 2,
214 // ];
215 attributes::outer_attributes(p); 196 attributes::outer_attributes(p);
216 if !p.at_ts(EXPR_FIRST) { 197
217 p.error("expected expression"); 198 let cm = expr(p).0;
199
200 match (has_attrs, cm) {
201 (true, Some(cm)) => {
202 let kind = cm.kind();
203 cm.undo_completion(p).abandon(p);
204 m.complete(p, kind);
205 }
206 _ => m.abandon(p),
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![,]) {
218 break; 215 break;
219 } 216 }
220 expr(p);
221 } 217 }
222 p.expect(T![']']); 218 p.expect(T![']']);
219
223 m.complete(p, ARRAY_EXPR) 220 m.complete(p, ARRAY_EXPR)
224} 221}
225 222