diff options
Diffstat (limited to 'crates')
9 files changed, 88 insertions, 190 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 | ||
diff --git a/crates/ra_syntax/test_data/parser/err/0022_bad_exprs.txt b/crates/ra_syntax/test_data/parser/err/0022_bad_exprs.txt index ee0ac52c3..310a82464 100644 --- a/crates/ra_syntax/test_data/parser/err/0022_bad_exprs.txt +++ b/crates/ra_syntax/test_data/parser/err/0022_bad_exprs.txt | |||
@@ -12,8 +12,8 @@ SOURCE_FILE@[0; 112) | |||
12 | BLOCK@[7; 33) | 12 | BLOCK@[7; 33) |
13 | L_CURLY@[7; 8) "{" | 13 | L_CURLY@[7; 8) "{" |
14 | WHITESPACE@[8; 9) " " | 14 | WHITESPACE@[8; 9) " " |
15 | EXPR_STMT@[9; 15) | 15 | EXPR_STMT@[9; 26) |
16 | ARRAY_EXPR@[9; 15) | 16 | ARRAY_EXPR@[9; 26) |
17 | L_BRACK@[9; 10) "[" | 17 | L_BRACK@[9; 10) "[" |
18 | LITERAL@[10; 11) | 18 | LITERAL@[10; 11) |
19 | INT_NUMBER@[10; 11) "1" | 19 | INT_NUMBER@[10; 11) "1" |
@@ -22,17 +22,13 @@ SOURCE_FILE@[0; 112) | |||
22 | LITERAL@[13; 14) | 22 | LITERAL@[13; 14) |
23 | INT_NUMBER@[13; 14) "2" | 23 | INT_NUMBER@[13; 14) "2" |
24 | COMMA@[14; 15) "," | 24 | COMMA@[14; 15) "," |
25 | WHITESPACE@[15; 16) " " | 25 | WHITESPACE@[15; 16) " " |
26 | EXPR_STMT@[16; 17) | 26 | ERROR@[16; 17) |
27 | ERROR@[16; 17) | 27 | AT@[16; 17) "@" |
28 | AT@[16; 17) "@" | ||
29 | EXPR_STMT@[17; 18) | ||
30 | ERROR@[17; 18) | ||
31 | COMMA@[17; 18) "," | 28 | COMMA@[17; 18) "," |
32 | WHITESPACE@[18; 19) " " | 29 | WHITESPACE@[18; 19) " " |
33 | STRUCT_DEF@[19; 26) | 30 | ERROR@[19; 25) |
34 | STRUCT_KW@[19; 25) "struct" | 31 | STRUCT_KW@[19; 25) "struct" |
35 | ERROR@[25; 26) | ||
36 | COMMA@[25; 26) "," | 32 | COMMA@[25; 26) "," |
37 | WHITESPACE@[26; 27) " " | 33 | WHITESPACE@[26; 27) " " |
38 | LET_STMT@[27; 31) | 34 | LET_STMT@[27; 31) |
@@ -151,15 +147,12 @@ SOURCE_FILE@[0; 112) | |||
151 | WHITESPACE@[109; 110) " " | 147 | WHITESPACE@[109; 110) " " |
152 | R_CURLY@[110; 111) "}" | 148 | R_CURLY@[110; 111) "}" |
153 | WHITESPACE@[111; 112) "\n" | 149 | WHITESPACE@[111; 112) "\n" |
154 | error 15: expected expression | ||
155 | error 15: expected R_BRACK | ||
156 | error 15: expected SEMI | ||
157 | error 16: expected expression | 150 | error 16: expected expression |
158 | error 17: expected SEMI | 151 | error 19: expected expression |
159 | error 17: expected expression | 152 | error 26: expected expression |
160 | error 18: expected SEMI | 153 | error 26: expected COMMA |
161 | error 25: expected a name | 154 | error 26: expected R_BRACK |
162 | error 26: expected `;`, `{`, or `(` | 155 | error 26: expected SEMI |
163 | error 30: expected pattern | 156 | error 30: expected pattern |
164 | error 31: expected SEMI | 157 | error 31: expected SEMI |
165 | error 52: expected expression | 158 | error 52: expected expression |
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0135_first_array_member_attributes.rs b/crates/ra_syntax/test_data/parser/inline/ok/0135_first_array_member_attributes.rs deleted file mode 100644 index f59e13771..000000000 --- a/crates/ra_syntax/test_data/parser/inline/ok/0135_first_array_member_attributes.rs +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | pub const A: &[i64] = &[ | ||
2 | #[cfg(test)] | ||
3 | 1, | ||
4 | 2, | ||
5 | ]; | ||
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0135_first_array_member_attributes.txt b/crates/ra_syntax/test_data/parser/inline/ok/0135_first_array_member_attributes.txt deleted file mode 100644 index 2e3a13005..000000000 --- a/crates/ra_syntax/test_data/parser/inline/ok/0135_first_array_member_attributes.txt +++ /dev/null | |||
@@ -1,53 +0,0 @@ | |||
1 | SOURCE_FILE@[0; 56) | ||
2 | CONST_DEF@[0; 55) | ||
3 | VISIBILITY@[0; 3) | ||
4 | PUB_KW@[0; 3) "pub" | ||
5 | WHITESPACE@[3; 4) " " | ||
6 | CONST_KW@[4; 9) "const" | ||
7 | WHITESPACE@[9; 10) " " | ||
8 | NAME@[10; 11) | ||
9 | IDENT@[10; 11) "A" | ||
10 | COLON@[11; 12) ":" | ||
11 | WHITESPACE@[12; 13) " " | ||
12 | REFERENCE_TYPE@[13; 19) | ||
13 | AMP@[13; 14) "&" | ||
14 | SLICE_TYPE@[14; 19) | ||
15 | L_BRACK@[14; 15) "[" | ||
16 | PATH_TYPE@[15; 18) | ||
17 | PATH@[15; 18) | ||
18 | PATH_SEGMENT@[15; 18) | ||
19 | NAME_REF@[15; 18) | ||
20 | IDENT@[15; 18) "i64" | ||
21 | R_BRACK@[18; 19) "]" | ||
22 | WHITESPACE@[19; 20) " " | ||
23 | EQ@[20; 21) "=" | ||
24 | WHITESPACE@[21; 22) " " | ||
25 | REF_EXPR@[22; 54) | ||
26 | AMP@[22; 23) "&" | ||
27 | ARRAY_EXPR@[23; 54) | ||
28 | L_BRACK@[23; 24) "[" | ||
29 | WHITESPACE@[24; 28) "\n " | ||
30 | LITERAL@[28; 45) | ||
31 | ATTR@[28; 40) | ||
32 | POUND@[28; 29) "#" | ||
33 | L_BRACK@[29; 30) "[" | ||
34 | PATH@[30; 33) | ||
35 | PATH_SEGMENT@[30; 33) | ||
36 | NAME_REF@[30; 33) | ||
37 | IDENT@[30; 33) "cfg" | ||
38 | TOKEN_TREE@[33; 39) | ||
39 | L_PAREN@[33; 34) "(" | ||
40 | IDENT@[34; 38) "test" | ||
41 | R_PAREN@[38; 39) ")" | ||
42 | R_BRACK@[39; 40) "]" | ||
43 | WHITESPACE@[40; 44) "\n " | ||
44 | INT_NUMBER@[44; 45) "1" | ||
45 | COMMA@[45; 46) "," | ||
46 | WHITESPACE@[46; 50) "\n " | ||
47 | LITERAL@[50; 51) | ||
48 | INT_NUMBER@[50; 51) "2" | ||
49 | COMMA@[51; 52) "," | ||
50 | WHITESPACE@[52; 53) "\n" | ||
51 | R_BRACK@[53; 54) "]" | ||
52 | SEMI@[54; 55) ";" | ||
53 | WHITESPACE@[55; 56) "\n" | ||
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0136_subsequent_array_member_attributes.rs b/crates/ra_syntax/test_data/parser/inline/ok/0136_subsequent_array_member_attributes.rs deleted file mode 100644 index 1324acb3f..000000000 --- a/crates/ra_syntax/test_data/parser/inline/ok/0136_subsequent_array_member_attributes.rs +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | pub const A: &[i64] = &[ | ||
2 | 1, | ||
3 | #[cfg(test)] | ||
4 | 2, | ||
5 | ]; | ||
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0136_subsequent_array_member_attributes.txt b/crates/ra_syntax/test_data/parser/inline/ok/0136_subsequent_array_member_attributes.txt deleted file mode 100644 index 1bb8a0afc..000000000 --- a/crates/ra_syntax/test_data/parser/inline/ok/0136_subsequent_array_member_attributes.txt +++ /dev/null | |||
@@ -1,53 +0,0 @@ | |||
1 | SOURCE_FILE@[0; 56) | ||
2 | CONST_DEF@[0; 55) | ||
3 | VISIBILITY@[0; 3) | ||
4 | PUB_KW@[0; 3) "pub" | ||
5 | WHITESPACE@[3; 4) " " | ||
6 | CONST_KW@[4; 9) "const" | ||
7 | WHITESPACE@[9; 10) " " | ||
8 | NAME@[10; 11) | ||
9 | IDENT@[10; 11) "A" | ||
10 | COLON@[11; 12) ":" | ||
11 | WHITESPACE@[12; 13) " " | ||
12 | REFERENCE_TYPE@[13; 19) | ||
13 | AMP@[13; 14) "&" | ||
14 | SLICE_TYPE@[14; 19) | ||
15 | L_BRACK@[14; 15) "[" | ||
16 | PATH_TYPE@[15; 18) | ||
17 | PATH@[15; 18) | ||
18 | PATH_SEGMENT@[15; 18) | ||
19 | NAME_REF@[15; 18) | ||
20 | IDENT@[15; 18) "i64" | ||
21 | R_BRACK@[18; 19) "]" | ||
22 | WHITESPACE@[19; 20) " " | ||
23 | EQ@[20; 21) "=" | ||
24 | WHITESPACE@[21; 22) " " | ||
25 | REF_EXPR@[22; 54) | ||
26 | AMP@[22; 23) "&" | ||
27 | ARRAY_EXPR@[23; 54) | ||
28 | L_BRACK@[23; 24) "[" | ||
29 | WHITESPACE@[24; 28) "\n " | ||
30 | LITERAL@[28; 29) | ||
31 | INT_NUMBER@[28; 29) "1" | ||
32 | COMMA@[29; 30) "," | ||
33 | WHITESPACE@[30; 34) "\n " | ||
34 | LITERAL@[34; 51) | ||
35 | ATTR@[34; 46) | ||
36 | POUND@[34; 35) "#" | ||
37 | L_BRACK@[35; 36) "[" | ||
38 | PATH@[36; 39) | ||
39 | PATH_SEGMENT@[36; 39) | ||
40 | NAME_REF@[36; 39) | ||
41 | IDENT@[36; 39) "cfg" | ||
42 | TOKEN_TREE@[39; 45) | ||
43 | L_PAREN@[39; 40) "(" | ||
44 | IDENT@[40; 44) "test" | ||
45 | R_PAREN@[44; 45) ")" | ||
46 | R_BRACK@[45; 46) "]" | ||
47 | WHITESPACE@[46; 50) "\n " | ||
48 | INT_NUMBER@[50; 51) "2" | ||
49 | COMMA@[51; 52) "," | ||
50 | WHITESPACE@[52; 53) "\n" | ||
51 | R_BRACK@[53; 54) "]" | ||
52 | SEMI@[54; 55) ";" | ||
53 | WHITESPACE@[55; 56) "\n" | ||
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0150_array_attrs.rs b/crates/ra_syntax/test_data/parser/inline/ok/0150_array_attrs.rs new file mode 100644 index 000000000..2ac310924 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/inline/ok/0150_array_attrs.rs | |||
@@ -0,0 +1 @@ | |||
const A: &[i64] = &[1, #[cfg(test)] 2]; | |||
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0150_array_attrs.txt b/crates/ra_syntax/test_data/parser/inline/ok/0150_array_attrs.txt new file mode 100644 index 000000000..78e296f88 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/inline/ok/0150_array_attrs.txt | |||
@@ -0,0 +1,47 @@ | |||
1 | SOURCE_FILE@[0; 40) | ||
2 | CONST_DEF@[0; 39) | ||
3 | CONST_KW@[0; 5) "const" | ||
4 | WHITESPACE@[5; 6) " " | ||
5 | NAME@[6; 7) | ||
6 | IDENT@[6; 7) "A" | ||
7 | COLON@[7; 8) ":" | ||
8 | WHITESPACE@[8; 9) " " | ||
9 | REFERENCE_TYPE@[9; 15) | ||
10 | AMP@[9; 10) "&" | ||
11 | SLICE_TYPE@[10; 15) | ||
12 | L_BRACK@[10; 11) "[" | ||
13 | PATH_TYPE@[11; 14) | ||
14 | PATH@[11; 14) | ||
15 | PATH_SEGMENT@[11; 14) | ||
16 | NAME_REF@[11; 14) | ||
17 | IDENT@[11; 14) "i64" | ||
18 | R_BRACK@[14; 15) "]" | ||
19 | WHITESPACE@[15; 16) " " | ||
20 | EQ@[16; 17) "=" | ||
21 | WHITESPACE@[17; 18) " " | ||
22 | REF_EXPR@[18; 38) | ||
23 | AMP@[18; 19) "&" | ||
24 | ARRAY_EXPR@[19; 38) | ||
25 | L_BRACK@[19; 20) "[" | ||
26 | LITERAL@[20; 21) | ||
27 | INT_NUMBER@[20; 21) "1" | ||
28 | COMMA@[21; 22) "," | ||
29 | WHITESPACE@[22; 23) " " | ||
30 | LITERAL@[23; 37) | ||
31 | ATTR@[23; 35) | ||
32 | POUND@[23; 24) "#" | ||
33 | L_BRACK@[24; 25) "[" | ||
34 | PATH@[25; 28) | ||
35 | PATH_SEGMENT@[25; 28) | ||
36 | NAME_REF@[25; 28) | ||
37 | IDENT@[25; 28) "cfg" | ||
38 | TOKEN_TREE@[28; 34) | ||
39 | L_PAREN@[28; 29) "(" | ||
40 | IDENT@[29; 33) "test" | ||
41 | R_PAREN@[33; 34) ")" | ||
42 | R_BRACK@[34; 35) "]" | ||
43 | WHITESPACE@[35; 36) " " | ||
44 | INT_NUMBER@[36; 37) "2" | ||
45 | R_BRACK@[37; 38) "]" | ||
46 | SEMI@[38; 39) ";" | ||
47 | WHITESPACE@[39; 40) "\n" | ||