diff options
Diffstat (limited to 'crates/ra_syntax')
8 files changed, 171 insertions, 125 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index 81c709bfb..d8c2cb063 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs | |||
@@ -114,6 +114,9 @@ pub trait AttrsOwner: AstNode { | |||
114 | fn attrs(&self) -> AstChildren<Attr> { | 114 | fn attrs(&self) -> AstChildren<Attr> { |
115 | children(self) | 115 | children(self) |
116 | } | 116 | } |
117 | fn has_atom_attr(&self, atom: &str) -> bool { | ||
118 | self.attrs().filter_map(|x| x.as_atom()).any(|x| x == atom) | ||
119 | } | ||
117 | } | 120 | } |
118 | 121 | ||
119 | pub trait DocCommentsOwner: AstNode { | 122 | pub trait DocCommentsOwner: AstNode { |
@@ -153,12 +156,6 @@ pub trait DocCommentsOwner: AstNode { | |||
153 | } | 156 | } |
154 | } | 157 | } |
155 | 158 | ||
156 | impl FnDef { | ||
157 | pub fn has_atom_attr(&self, atom: &str) -> bool { | ||
158 | self.attrs().filter_map(|x| x.as_atom()).any(|x| x == atom) | ||
159 | } | ||
160 | } | ||
161 | |||
162 | impl Attr { | 159 | impl Attr { |
163 | pub fn is_inner(&self) -> bool { | 160 | pub fn is_inner(&self) -> bool { |
164 | let tt = match self.value() { | 161 | let tt = match self.value() { |
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 7572225b8..54b72f8c5 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -2108,6 +2108,7 @@ impl ToOwned for MacroCall { | |||
2108 | 2108 | ||
2109 | 2109 | ||
2110 | impl ast::NameOwner for MacroCall {} | 2110 | impl ast::NameOwner for MacroCall {} |
2111 | impl ast::AttrsOwner for MacroCall {} | ||
2111 | impl MacroCall { | 2112 | impl MacroCall { |
2112 | pub fn token_tree(&self) -> Option<&TokenTree> { | 2113 | pub fn token_tree(&self) -> Option<&TokenTree> { |
2113 | super::child_opt(self) | 2114 | super::child_opt(self) |
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index 66f1339c1..4f8e19bd0 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron | |||
@@ -557,7 +557,7 @@ Grammar( | |||
557 | "Name": (), | 557 | "Name": (), |
558 | "NameRef": (), | 558 | "NameRef": (), |
559 | "MacroCall": ( | 559 | "MacroCall": ( |
560 | traits: [ "NameOwner" ], | 560 | traits: [ "NameOwner", "AttrsOwner" ], |
561 | options: [ "TokenTree", "Path" ], | 561 | options: [ "TokenTree", "Path" ], |
562 | ), | 562 | ), |
563 | "Attr": ( options: [ ["value", "TokenTree"] ] ), | 563 | "Attr": ( options: [ ["value", "TokenTree"] ] ), |
diff --git a/crates/ra_syntax/tests/data/parser/err/0032_match_arms_inner_attrs.txt b/crates/ra_syntax/tests/data/parser/err/0032_match_arms_inner_attrs.txt index b7543abc9..ed5735a63 100644 --- a/crates/ra_syntax/tests/data/parser/err/0032_match_arms_inner_attrs.txt +++ b/crates/ra_syntax/tests/data/parser/err/0032_match_arms_inner_attrs.txt | |||
@@ -33,11 +33,11 @@ SOURCE_FILE@[0; 293) | |||
33 | R_PAREN@[40; 41) | 33 | R_PAREN@[40; 41) |
34 | COMMA@[41; 42) | 34 | COMMA@[41; 42) |
35 | WHITESPACE@[42; 51) | 35 | WHITESPACE@[42; 51) |
36 | ATTR@[51; 52) | 36 | MATCH_ARM@[51; 78) |
37 | POUND@[51; 52) | 37 | ATTR@[51; 52) |
38 | err: `expected `[`` | 38 | POUND@[51; 52) |
39 | err: `expected pattern` | 39 | err: `expected `[`` |
40 | MATCH_ARM@[52; 78) | 40 | err: `expected pattern` |
41 | ERROR@[52; 53) | 41 | ERROR@[52; 53) |
42 | EXCL@[52; 53) | 42 | EXCL@[52; 53) |
43 | err: `expected FAT_ARROW` | 43 | err: `expected FAT_ARROW` |
@@ -103,11 +103,11 @@ SOURCE_FILE@[0; 293) | |||
103 | R_PAREN@[149; 150) | 103 | R_PAREN@[149; 150) |
104 | COMMA@[150; 151) | 104 | COMMA@[150; 151) |
105 | WHITESPACE@[151; 160) | 105 | WHITESPACE@[151; 160) |
106 | ATTR@[160; 161) | 106 | MATCH_ARM@[160; 179) |
107 | POUND@[160; 161) | 107 | ATTR@[160; 161) |
108 | err: `expected `[`` | 108 | POUND@[160; 161) |
109 | err: `expected pattern` | 109 | err: `expected `[`` |
110 | MATCH_ARM@[161; 179) | 110 | err: `expected pattern` |
111 | ERROR@[161; 162) | 111 | ERROR@[161; 162) |
112 | EXCL@[161; 162) | 112 | EXCL@[161; 162) |
113 | err: `expected FAT_ARROW` | 113 | err: `expected FAT_ARROW` |
@@ -138,22 +138,22 @@ SOURCE_FILE@[0; 293) | |||
138 | MATCH_ARM_LIST@[200; 290) | 138 | MATCH_ARM_LIST@[200; 290) |
139 | L_CURLY@[200; 201) | 139 | L_CURLY@[200; 201) |
140 | WHITESPACE@[201; 210) | 140 | WHITESPACE@[201; 210) |
141 | ATTR@[210; 222) | 141 | MATCH_ARM@[210; 250) |
142 | POUND@[210; 211) | 142 | ATTR@[210; 222) |
143 | TOKEN_TREE@[211; 222) | 143 | POUND@[210; 211) |
144 | L_BRACK@[211; 212) | 144 | TOKEN_TREE@[211; 222) |
145 | IDENT@[212; 215) "cfg" | 145 | L_BRACK@[211; 212) |
146 | TOKEN_TREE@[215; 221) | 146 | IDENT@[212; 215) "cfg" |
147 | L_PAREN@[215; 216) | 147 | TOKEN_TREE@[215; 221) |
148 | IDENT@[216; 220) "test" | 148 | L_PAREN@[215; 216) |
149 | R_PAREN@[220; 221) | 149 | IDENT@[216; 220) "test" |
150 | R_BRACK@[221; 222) | 150 | R_PAREN@[220; 221) |
151 | WHITESPACE@[222; 231) | 151 | R_BRACK@[221; 222) |
152 | ATTR@[231; 232) | 152 | WHITESPACE@[222; 231) |
153 | POUND@[231; 232) | 153 | ATTR@[231; 232) |
154 | err: `expected `[`` | 154 | POUND@[231; 232) |
155 | err: `expected pattern` | 155 | err: `expected `[`` |
156 | MATCH_ARM@[232; 250) | 156 | err: `expected pattern` |
157 | ERROR@[232; 233) | 157 | ERROR@[232; 233) |
158 | EXCL@[232; 233) | 158 | EXCL@[232; 233) |
159 | err: `expected FAT_ARROW` | 159 | err: `expected FAT_ARROW` |
diff --git a/crates/ra_syntax/tests/data/parser/err/0033_match_arms_outer_attrs.txt b/crates/ra_syntax/tests/data/parser/err/0033_match_arms_outer_attrs.txt index 7f8767001..f540409bc 100644 --- a/crates/ra_syntax/tests/data/parser/err/0033_match_arms_outer_attrs.txt +++ b/crates/ra_syntax/tests/data/parser/err/0033_match_arms_outer_attrs.txt | |||
@@ -43,21 +43,21 @@ SOURCE_FILE@[0; 89) | |||
43 | R_PAREN@[57; 58) | 43 | R_PAREN@[57; 58) |
44 | COMMA@[58; 59) | 44 | COMMA@[58; 59) |
45 | WHITESPACE@[59; 68) | 45 | WHITESPACE@[59; 68) |
46 | ATTR@[68; 80) | 46 | MATCH_ARM@[68; 80) |
47 | POUND@[68; 69) | 47 | ATTR@[68; 80) |
48 | TOKEN_TREE@[69; 80) | 48 | POUND@[68; 69) |
49 | L_BRACK@[69; 70) | 49 | TOKEN_TREE@[69; 80) |
50 | IDENT@[70; 73) "cfg" | 50 | L_BRACK@[69; 70) |
51 | TOKEN_TREE@[73; 79) | 51 | IDENT@[70; 73) "cfg" |
52 | L_PAREN@[73; 74) | 52 | TOKEN_TREE@[73; 79) |
53 | IDENT@[74; 78) "test" | 53 | L_PAREN@[73; 74) |
54 | R_PAREN@[78; 79) | 54 | IDENT@[74; 78) "test" |
55 | R_BRACK@[79; 80) | 55 | R_PAREN@[78; 79) |
56 | R_BRACK@[79; 80) | ||
57 | err: `expected pattern` | ||
58 | err: `expected FAT_ARROW` | ||
59 | err: `expected expression` | ||
56 | WHITESPACE@[80; 85) | 60 | WHITESPACE@[80; 85) |
57 | err: `expected pattern` | ||
58 | err: `expected FAT_ARROW` | ||
59 | err: `expected expression` | ||
60 | MATCH_ARM@[85; 85) | ||
61 | R_CURLY@[85; 86) | 61 | R_CURLY@[85; 86) |
62 | WHITESPACE@[86; 87) | 62 | WHITESPACE@[86; 87) |
63 | R_CURLY@[87; 88) | 63 | R_CURLY@[87; 88) |
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0121_match_arms_outer_attributes.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0121_match_arms_outer_attributes.txt index c888fb8f0..e52a290bf 100644 --- a/crates/ra_syntax/tests/data/parser/inline/ok/0121_match_arms_outer_attributes.txt +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0121_match_arms_outer_attributes.txt | |||
@@ -21,22 +21,22 @@ SOURCE_FILE@[0; 259) | |||
21 | MATCH_ARM_LIST@[24; 256) | 21 | MATCH_ARM_LIST@[24; 256) |
22 | L_CURLY@[24; 25) | 22 | L_CURLY@[24; 25) |
23 | WHITESPACE@[25; 34) | 23 | WHITESPACE@[25; 34) |
24 | ATTR@[34; 58) | 24 | MATCH_ARM@[34; 74) |
25 | POUND@[34; 35) | 25 | ATTR@[34; 58) |
26 | TOKEN_TREE@[35; 58) | 26 | POUND@[34; 35) |
27 | L_BRACK@[35; 36) | 27 | TOKEN_TREE@[35; 58) |
28 | IDENT@[36; 39) "cfg" | 28 | L_BRACK@[35; 36) |
29 | TOKEN_TREE@[39; 57) | 29 | IDENT@[36; 39) "cfg" |
30 | L_PAREN@[39; 40) | 30 | TOKEN_TREE@[39; 57) |
31 | IDENT@[40; 47) "feature" | 31 | L_PAREN@[39; 40) |
32 | WHITESPACE@[47; 48) | 32 | IDENT@[40; 47) "feature" |
33 | EQ@[48; 49) | 33 | WHITESPACE@[47; 48) |
34 | WHITESPACE@[49; 50) | 34 | EQ@[48; 49) |
35 | STRING@[50; 56) | 35 | WHITESPACE@[49; 50) |
36 | R_PAREN@[56; 57) | 36 | STRING@[50; 56) |
37 | R_BRACK@[57; 58) | 37 | R_PAREN@[56; 57) |
38 | WHITESPACE@[58; 67) | 38 | R_BRACK@[57; 58) |
39 | MATCH_ARM@[67; 74) | 39 | WHITESPACE@[58; 67) |
40 | PLACEHOLDER_PAT@[67; 68) | 40 | PLACEHOLDER_PAT@[67; 68) |
41 | UNDERSCORE@[67; 68) | 41 | UNDERSCORE@[67; 68) |
42 | WHITESPACE@[68; 69) | 42 | WHITESPACE@[68; 69) |
@@ -47,22 +47,22 @@ SOURCE_FILE@[0; 259) | |||
47 | R_PAREN@[73; 74) | 47 | R_PAREN@[73; 74) |
48 | COMMA@[74; 75) | 48 | COMMA@[74; 75) |
49 | WHITESPACE@[75; 84) | 49 | WHITESPACE@[75; 84) |
50 | ATTR@[84; 109) | 50 | MATCH_ARM@[84; 125) |
51 | POUND@[84; 85) | 51 | ATTR@[84; 109) |
52 | TOKEN_TREE@[85; 109) | 52 | POUND@[84; 85) |
53 | L_BRACK@[85; 86) | 53 | TOKEN_TREE@[85; 109) |
54 | IDENT@[86; 89) "cfg" | 54 | L_BRACK@[85; 86) |
55 | TOKEN_TREE@[89; 108) | 55 | IDENT@[86; 89) "cfg" |
56 | L_PAREN@[89; 90) | 56 | TOKEN_TREE@[89; 108) |
57 | IDENT@[90; 97) "feature" | 57 | L_PAREN@[89; 90) |
58 | WHITESPACE@[97; 98) | 58 | IDENT@[90; 97) "feature" |
59 | EQ@[98; 99) | 59 | WHITESPACE@[97; 98) |
60 | WHITESPACE@[99; 100) | 60 | EQ@[98; 99) |
61 | STRING@[100; 107) | 61 | WHITESPACE@[99; 100) |
62 | R_PAREN@[107; 108) | 62 | STRING@[100; 107) |
63 | R_BRACK@[108; 109) | 63 | R_PAREN@[107; 108) |
64 | WHITESPACE@[109; 118) | 64 | R_BRACK@[108; 109) |
65 | MATCH_ARM@[118; 125) | 65 | WHITESPACE@[109; 118) |
66 | PLACEHOLDER_PAT@[118; 119) | 66 | PLACEHOLDER_PAT@[118; 119) |
67 | UNDERSCORE@[118; 119) | 67 | UNDERSCORE@[118; 119) |
68 | WHITESPACE@[119; 120) | 68 | WHITESPACE@[119; 120) |
@@ -73,52 +73,52 @@ SOURCE_FILE@[0; 259) | |||
73 | R_PAREN@[124; 125) | 73 | R_PAREN@[124; 125) |
74 | COMMA@[125; 126) | 74 | COMMA@[125; 126) |
75 | WHITESPACE@[126; 135) | 75 | WHITESPACE@[126; 135) |
76 | ATTR@[135; 159) | 76 | MATCH_ARM@[135; 249) |
77 | POUND@[135; 136) | 77 | ATTR@[135; 159) |
78 | TOKEN_TREE@[136; 159) | 78 | POUND@[135; 136) |
79 | L_BRACK@[136; 137) | 79 | TOKEN_TREE@[136; 159) |
80 | IDENT@[137; 140) "cfg" | 80 | L_BRACK@[136; 137) |
81 | TOKEN_TREE@[140; 158) | 81 | IDENT@[137; 140) "cfg" |
82 | L_PAREN@[140; 141) | 82 | TOKEN_TREE@[140; 158) |
83 | IDENT@[141; 148) "feature" | 83 | L_PAREN@[140; 141) |
84 | WHITESPACE@[148; 149) | 84 | IDENT@[141; 148) "feature" |
85 | EQ@[149; 150) | 85 | WHITESPACE@[148; 149) |
86 | WHITESPACE@[150; 151) | 86 | EQ@[149; 150) |
87 | STRING@[151; 157) | 87 | WHITESPACE@[150; 151) |
88 | R_PAREN@[157; 158) | 88 | STRING@[151; 157) |
89 | R_BRACK@[158; 159) | 89 | R_PAREN@[157; 158) |
90 | WHITESPACE@[159; 168) | 90 | R_BRACK@[158; 159) |
91 | ATTR@[168; 198) | 91 | WHITESPACE@[159; 168) |
92 | POUND@[168; 169) | 92 | ATTR@[168; 198) |
93 | TOKEN_TREE@[169; 198) | 93 | POUND@[168; 169) |
94 | L_BRACK@[169; 170) | 94 | TOKEN_TREE@[169; 198) |
95 | IDENT@[170; 173) "cfg" | 95 | L_BRACK@[169; 170) |
96 | TOKEN_TREE@[173; 197) | 96 | IDENT@[170; 173) "cfg" |
97 | L_PAREN@[173; 174) | 97 | TOKEN_TREE@[173; 197) |
98 | IDENT@[174; 181) "feature" | 98 | L_PAREN@[173; 174) |
99 | WHITESPACE@[181; 182) | 99 | IDENT@[174; 181) "feature" |
100 | EQ@[182; 183) | 100 | WHITESPACE@[181; 182) |
101 | WHITESPACE@[183; 184) | 101 | EQ@[182; 183) |
102 | STRING@[184; 196) | 102 | WHITESPACE@[183; 184) |
103 | R_PAREN@[196; 197) | 103 | STRING@[184; 196) |
104 | R_BRACK@[197; 198) | 104 | R_PAREN@[196; 197) |
105 | WHITESPACE@[198; 207) | 105 | R_BRACK@[197; 198) |
106 | ATTR@[207; 233) | 106 | WHITESPACE@[198; 207) |
107 | POUND@[207; 208) | 107 | ATTR@[207; 233) |
108 | TOKEN_TREE@[208; 233) | 108 | POUND@[207; 208) |
109 | L_BRACK@[208; 209) | 109 | TOKEN_TREE@[208; 233) |
110 | IDENT@[209; 212) "cfg" | 110 | L_BRACK@[208; 209) |
111 | TOKEN_TREE@[212; 232) | 111 | IDENT@[209; 212) "cfg" |
112 | L_PAREN@[212; 213) | 112 | TOKEN_TREE@[212; 232) |
113 | IDENT@[213; 220) "feature" | 113 | L_PAREN@[212; 213) |
114 | WHITESPACE@[220; 221) | 114 | IDENT@[213; 220) "feature" |
115 | EQ@[221; 222) | 115 | WHITESPACE@[220; 221) |
116 | WHITESPACE@[222; 223) | 116 | EQ@[221; 222) |
117 | STRING@[223; 231) | 117 | WHITESPACE@[222; 223) |
118 | R_PAREN@[231; 232) | 118 | STRING@[223; 231) |
119 | R_BRACK@[232; 233) | 119 | R_PAREN@[231; 232) |
120 | WHITESPACE@[233; 242) | 120 | R_BRACK@[232; 233) |
121 | MATCH_ARM@[242; 249) | 121 | WHITESPACE@[233; 242) |
122 | PLACEHOLDER_PAT@[242; 243) | 122 | PLACEHOLDER_PAT@[242; 243) |
123 | UNDERSCORE@[242; 243) | 123 | UNDERSCORE@[242; 243) |
124 | WHITESPACE@[243; 244) | 124 | WHITESPACE@[243; 244) |
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0125_struct_literal_field_with_attr.rs b/crates/ra_syntax/tests/data/parser/inline/ok/0125_struct_literal_field_with_attr.rs new file mode 100644 index 000000000..a6c7760c7 --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0125_struct_literal_field_with_attr.rs | |||
@@ -0,0 +1,3 @@ | |||
1 | fn main() { | ||
2 | S { #[cfg(test)] field: 1 } | ||
3 | } | ||
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0125_struct_literal_field_with_attr.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0125_struct_literal_field_with_attr.txt new file mode 100644 index 000000000..34c80500a --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0125_struct_literal_field_with_attr.txt | |||
@@ -0,0 +1,45 @@ | |||
1 | SOURCE_FILE@[0; 46) | ||
2 | FN_DEF@[0; 45) | ||
3 | FN_KW@[0; 2) | ||
4 | WHITESPACE@[2; 3) | ||
5 | NAME@[3; 7) | ||
6 | IDENT@[3; 7) "main" | ||
7 | PARAM_LIST@[7; 9) | ||
8 | L_PAREN@[7; 8) | ||
9 | R_PAREN@[8; 9) | ||
10 | WHITESPACE@[9; 10) | ||
11 | BLOCK@[10; 45) | ||
12 | L_CURLY@[10; 11) | ||
13 | WHITESPACE@[11; 16) | ||
14 | STRUCT_LIT@[16; 43) | ||
15 | PATH@[16; 17) | ||
16 | PATH_SEGMENT@[16; 17) | ||
17 | NAME_REF@[16; 17) | ||
18 | IDENT@[16; 17) "S" | ||
19 | WHITESPACE@[17; 18) | ||
20 | NAMED_FIELD_LIST@[18; 43) | ||
21 | L_CURLY@[18; 19) | ||
22 | WHITESPACE@[19; 20) | ||
23 | NAMED_FIELD@[20; 41) | ||
24 | ATTR@[20; 32) | ||
25 | POUND@[20; 21) | ||
26 | TOKEN_TREE@[21; 32) | ||
27 | L_BRACK@[21; 22) | ||
28 | IDENT@[22; 25) "cfg" | ||
29 | TOKEN_TREE@[25; 31) | ||
30 | L_PAREN@[25; 26) | ||
31 | IDENT@[26; 30) "test" | ||
32 | R_PAREN@[30; 31) | ||
33 | R_BRACK@[31; 32) | ||
34 | WHITESPACE@[32; 33) | ||
35 | NAME_REF@[33; 38) | ||
36 | IDENT@[33; 38) "field" | ||
37 | COLON@[38; 39) | ||
38 | WHITESPACE@[39; 40) | ||
39 | LITERAL@[40; 41) | ||
40 | INT_NUMBER@[40; 41) "1" | ||
41 | WHITESPACE@[41; 42) | ||
42 | R_CURLY@[42; 43) | ||
43 | WHITESPACE@[43; 44) | ||
44 | R_CURLY@[44; 45) | ||
45 | WHITESPACE@[45; 46) | ||