aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src/grammar
diff options
context:
space:
mode:
authorTomasKralCZ <[email protected]>2020-01-19 16:51:03 +0000
committerTomasKralCZ <[email protected]>2020-01-19 16:51:03 +0000
commit514df15d9e32e057ba23dda0d4f5c07e82e7ed23 (patch)
tree41e93f63182bae10a7325fc50220f67df79aaece /crates/ra_parser/src/grammar
parentc3b9a19eb72ae9542272ae7a22ac3fb57c75daca (diff)
parent3a7724e44181ccd5c248589538bd82458b5a9407 (diff)
Merge branch 'master' of https://github.com/rust-analyzer/rust-analyzer
Diffstat (limited to 'crates/ra_parser/src/grammar')
-rw-r--r--crates/ra_parser/src/grammar/expressions.rs28
-rw-r--r--crates/ra_parser/src/grammar/expressions/atom.rs15
2 files changed, 27 insertions, 16 deletions
diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs
index d733499d1..06c92645e 100644
--- a/crates/ra_parser/src/grammar/expressions.rs
+++ b/crates/ra_parser/src/grammar/expressions.rs
@@ -19,6 +19,26 @@ pub(super) fn expr(p: &mut Parser) -> (Option<CompletedMarker>, BlockLike) {
19 expr_bp(p, r, 1) 19 expr_bp(p, r, 1)
20} 20}
21 21
22pub(super) fn expr_with_attrs(p: &mut Parser) -> bool {
23 let m = p.start();
24 let has_attrs = p.at(T![#]);
25 attributes::outer_attributes(p);
26
27 let (cm, _block_like) = expr(p);
28 let success = cm.is_some();
29
30 match (has_attrs, cm) {
31 (true, Some(cm)) => {
32 let kind = cm.kind();
33 cm.undo_completion(p).abandon(p);
34 m.complete(p, kind);
35 }
36 _ => m.abandon(p),
37 }
38
39 success
40}
41
22pub(super) fn expr_stmt(p: &mut Parser) -> (Option<CompletedMarker>, BlockLike) { 42pub(super) fn expr_stmt(p: &mut Parser) -> (Option<CompletedMarker>, BlockLike) {
23 let r = Restrictions { forbid_structs: false, prefer_stmt: true }; 43 let r = Restrictions { forbid_structs: false, prefer_stmt: true };
24 expr_bp(p, r, 1) 44 expr_bp(p, r, 1)
@@ -540,11 +560,13 @@ fn arg_list(p: &mut Parser) {
540 let m = p.start(); 560 let m = p.start();
541 p.bump(T!['(']); 561 p.bump(T!['(']);
542 while !p.at(T![')']) && !p.at(EOF) { 562 while !p.at(T![')']) && !p.at(EOF) {
543 if !p.at_ts(EXPR_FIRST) { 563 // test arg_with_attr
544 p.error("expected expression"); 564 // fn main() {
565 // foo(#[attr] 92)
566 // }
567 if !expr_with_attrs(p) {
545 break; 568 break;
546 } 569 }
547 expr(p);
548 if !p.at(T![')']) && !p.expect(T![,]) { 570 if !p.at(T![')']) && !p.expect(T![,]) {
549 break; 571 break;
550 } 572 }
diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs
index a98a2a3ef..2cc321473 100644
--- a/crates/ra_parser/src/grammar/expressions/atom.rs
+++ b/crates/ra_parser/src/grammar/expressions/atom.rs
@@ -191,19 +191,8 @@ fn array_expr(p: &mut Parser) -> CompletedMarker {
191 191
192 // test array_attrs 192 // test array_attrs
193 // const A: &[i64] = &[1, #[cfg(test)] 2]; 193 // const A: &[i64] = &[1, #[cfg(test)] 2];
194 let m = p.start(); 194 if !expr_with_attrs(p) {
195 let has_attrs = p.at(T![#]); 195 break;
196 attributes::outer_attributes(p);
197
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 } 196 }
208 197
209 if n_exprs == 1 && p.eat(T![;]) { 198 if n_exprs == 1 && p.eat(T![;]) {