diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/libsyntax2/src/grammar/items/mod.rs | 8 | ||||
-rw-r--r-- | crates/libsyntax2/src/grammar/items/nominal.rs (renamed from crates/libsyntax2/src/grammar/items/structs.rs) | 13 | ||||
-rw-r--r-- | crates/libsyntax2/tests/data/parser/err/0013_invalid_type.txt | 44 | ||||
-rw-r--r-- | crates/libsyntax2/tests/data/parser/err/0025_nope.rs | 31 | ||||
-rw-r--r-- | crates/libsyntax2/tests/data/parser/err/0025_nope.txt | 203 |
5 files changed, 274 insertions, 25 deletions
diff --git a/crates/libsyntax2/src/grammar/items/mod.rs b/crates/libsyntax2/src/grammar/items/mod.rs index 57742ecb9..85d7fe770 100644 --- a/crates/libsyntax2/src/grammar/items/mod.rs +++ b/crates/libsyntax2/src/grammar/items/mod.rs | |||
@@ -1,11 +1,11 @@ | |||
1 | 1 | ||
2 | mod consts; | 2 | mod consts; |
3 | mod structs; | 3 | mod nominal; |
4 | mod traits; | 4 | mod traits; |
5 | mod use_item; | 5 | mod use_item; |
6 | 6 | ||
7 | use super::*; | 7 | use super::*; |
8 | pub(crate) use self::structs::named_field_def_list; | 8 | pub(crate) use self::nominal::named_field_def_list; |
9 | 9 | ||
10 | // test mod_contents | 10 | // test mod_contents |
11 | // fn foo() {} | 11 | // fn foo() {} |
@@ -176,7 +176,7 @@ fn items_without_modifiers(p: &mut Parser) -> Option<SyntaxKind> { | |||
176 | MODULE | 176 | MODULE |
177 | } | 177 | } |
178 | STRUCT_KW => { | 178 | STRUCT_KW => { |
179 | structs::struct_def(p); | 179 | nominal::struct_def(p); |
180 | if p.at(SEMI) { | 180 | if p.at(SEMI) { |
181 | p.err_and_bump( | 181 | p.err_and_bump( |
182 | "expected item, found `;`\n\ | 182 | "expected item, found `;`\n\ |
@@ -186,7 +186,7 @@ fn items_without_modifiers(p: &mut Parser) -> Option<SyntaxKind> { | |||
186 | STRUCT_DEF | 186 | STRUCT_DEF |
187 | } | 187 | } |
188 | ENUM_KW => { | 188 | ENUM_KW => { |
189 | structs::enum_def(p); | 189 | nominal::enum_def(p); |
190 | ENUM_DEF | 190 | ENUM_DEF |
191 | } | 191 | } |
192 | USE_KW => { | 192 | USE_KW => { |
diff --git a/crates/libsyntax2/src/grammar/items/structs.rs b/crates/libsyntax2/src/grammar/items/nominal.rs index f1e78865c..3db5b24af 100644 --- a/crates/libsyntax2/src/grammar/items/structs.rs +++ b/crates/libsyntax2/src/grammar/items/nominal.rs | |||
@@ -91,6 +91,10 @@ pub(crate) fn named_field_def_list(p: &mut Parser) { | |||
91 | let m = p.start(); | 91 | let m = p.start(); |
92 | p.bump(); | 92 | p.bump(); |
93 | while !p.at(R_CURLY) && !p.at(EOF) { | 93 | while !p.at(R_CURLY) && !p.at(EOF) { |
94 | if p.at(L_CURLY) { | ||
95 | error_block(p, "expected field"); | ||
96 | continue; | ||
97 | } | ||
94 | named_field_def(p); | 98 | named_field_def(p); |
95 | if !p.at(R_CURLY) { | 99 | if !p.at(R_CURLY) { |
96 | p.expect(COMMA); | 100 | p.expect(COMMA); |
@@ -127,10 +131,15 @@ fn pos_field_list(p: &mut Parser) { | |||
127 | return; | 131 | return; |
128 | } | 132 | } |
129 | while !p.at(R_PAREN) && !p.at(EOF) { | 133 | while !p.at(R_PAREN) && !p.at(EOF) { |
130 | let pos_field = p.start(); | 134 | let m = p.start(); |
131 | opt_visibility(p); | 135 | opt_visibility(p); |
136 | if !p.at_ts(types::TYPE_FIRST) { | ||
137 | p.error("expected a type"); | ||
138 | m.complete(p, ERROR); | ||
139 | break; | ||
140 | } | ||
132 | types::type_(p); | 141 | types::type_(p); |
133 | pos_field.complete(p, POS_FIELD); | 142 | m.complete(p, POS_FIELD); |
134 | 143 | ||
135 | if !p.at(R_PAREN) { | 144 | if !p.at(R_PAREN) { |
136 | p.expect(COMMA); | 145 | p.expect(COMMA); |
diff --git a/crates/libsyntax2/tests/data/parser/err/0013_invalid_type.txt b/crates/libsyntax2/tests/data/parser/err/0013_invalid_type.txt index f7f6c6bce..e1a6b6432 100644 --- a/crates/libsyntax2/tests/data/parser/err/0013_invalid_type.txt +++ b/crates/libsyntax2/tests/data/parser/err/0013_invalid_type.txt | |||
@@ -1,5 +1,5 @@ | |||
1 | ROOT@[0; 86) | 1 | ROOT@[0; 86) |
2 | STRUCT_DEF@[0; 84) | 2 | STRUCT_DEF@[0; 72) |
3 | VISIBILITY@[0; 3) | 3 | VISIBILITY@[0; 3) |
4 | PUB_KW@[0; 3) | 4 | PUB_KW@[0; 3) |
5 | WHITESPACE@[3; 4) | 5 | WHITESPACE@[3; 4) |
@@ -7,7 +7,7 @@ ROOT@[0; 86) | |||
7 | WHITESPACE@[10; 11) | 7 | WHITESPACE@[10; 11) |
8 | NAME@[11; 16) | 8 | NAME@[11; 16) |
9 | IDENT@[11; 16) "Cache" | 9 | IDENT@[11; 16) "Cache" |
10 | POS_FIELD_LIST@[16; 83) | 10 | POS_FIELD_LIST@[16; 72) |
11 | L_PAREN@[16; 17) | 11 | L_PAREN@[16; 17) |
12 | WHITESPACE@[17; 22) | 12 | WHITESPACE@[17; 22) |
13 | POS_FIELD@[22; 68) | 13 | POS_FIELD@[22; 68) |
@@ -62,22 +62,28 @@ ROOT@[0; 86) | |||
62 | NAME_REF@[69; 72) | 62 | NAME_REF@[69; 72) |
63 | IDENT@[69; 72) "Any" | 63 | IDENT@[69; 72) "Any" |
64 | err: `expected COMMA` | 64 | err: `expected COMMA` |
65 | err: `expected type` | 65 | err: `expected a type` |
66 | POS_FIELD@[72; 73) | 66 | err: `expected R_PAREN` |
67 | ERROR@[72; 73) | 67 | err: `expected SEMI` |
68 | R_ANGLE@[72; 73) | 68 | err: `expected an item` |
69 | COMMA@[73; 74) | 69 | ERROR@[72; 72) |
70 | WHITESPACE@[74; 79) | 70 | ERROR@[72; 73) |
71 | err: `expected type` | 71 | R_ANGLE@[72; 73) |
72 | POS_FIELD@[79; 80) | 72 | err: `expected an item` |
73 | ERROR@[79; 80) | 73 | ERROR@[73; 74) |
74 | R_ANGLE@[79; 80) | 74 | COMMA@[73; 74) |
75 | err: `expected COMMA` | 75 | WHITESPACE@[74; 79) |
76 | err: `expected type` | 76 | err: `expected an item` |
77 | POS_FIELD@[80; 81) | 77 | ERROR@[79; 80) |
78 | ERROR@[80; 81) | 78 | R_ANGLE@[79; 80) |
79 | R_ANGLE@[80; 81) | 79 | err: `expected an item` |
80 | WHITESPACE@[81; 82) | 80 | ERROR@[80; 81) |
81 | R_PAREN@[82; 83) | 81 | R_ANGLE@[80; 81) |
82 | WHITESPACE@[81; 82) | ||
83 | err: `expected an item` | ||
84 | ERROR@[82; 83) | ||
85 | R_PAREN@[82; 83) | ||
86 | err: `expected an item` | ||
87 | ERROR@[83; 84) | ||
82 | SEMI@[83; 84) | 88 | SEMI@[83; 84) |
83 | WHITESPACE@[84; 86) | 89 | WHITESPACE@[84; 86) |
diff --git a/crates/libsyntax2/tests/data/parser/err/0025_nope.rs b/crates/libsyntax2/tests/data/parser/err/0025_nope.rs new file mode 100644 index 000000000..28726ed51 --- /dev/null +++ b/crates/libsyntax2/tests/data/parser/err/0025_nope.rs | |||
@@ -0,0 +1,31 @@ | |||
1 | fn main() { | ||
2 | enum Test { | ||
3 | Var1, | ||
4 | Var2(String), | ||
5 | Var3 { | ||
6 | abc: {}, //~ ERROR: expected type, found `{` | ||
7 | }, | ||
8 | } | ||
9 | |||
10 | // recover... | ||
11 | let a = 1; | ||
12 | enum Test2 { | ||
13 | Fine, | ||
14 | } | ||
15 | |||
16 | enum Test3 { | ||
17 | StillFine { | ||
18 | def: i32, | ||
19 | }, | ||
20 | } | ||
21 | |||
22 | { | ||
23 | // fail again | ||
24 | enum Test4 { | ||
25 | Nope(i32 {}) //~ ERROR: found `{` | ||
26 | //~^ ERROR: found `{` | ||
27 | } | ||
28 | } | ||
29 | // still recover later | ||
30 | let bad_syntax = _; //~ ERROR: expected expression, found reserved identifier `_` | ||
31 | } | ||
diff --git a/crates/libsyntax2/tests/data/parser/err/0025_nope.txt b/crates/libsyntax2/tests/data/parser/err/0025_nope.txt new file mode 100644 index 000000000..c30b8585f --- /dev/null +++ b/crates/libsyntax2/tests/data/parser/err/0025_nope.txt | |||
@@ -0,0 +1,203 @@ | |||
1 | ROOT@[0; 575) | ||
2 | FN_DEF@[0; 574) | ||
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; 574) | ||
12 | L_CURLY@[10; 11) | ||
13 | WHITESPACE@[11; 16) | ||
14 | ENUM_DEF@[16; 152) | ||
15 | ENUM_KW@[16; 20) | ||
16 | WHITESPACE@[20; 21) | ||
17 | NAME@[21; 25) | ||
18 | IDENT@[21; 25) "Test" | ||
19 | WHITESPACE@[25; 26) | ||
20 | ENUM_VARIANT_LIST@[26; 152) | ||
21 | L_CURLY@[26; 27) | ||
22 | WHITESPACE@[27; 36) | ||
23 | ENUM_VARIANT@[36; 40) | ||
24 | NAME@[36; 40) | ||
25 | IDENT@[36; 40) "Var1" | ||
26 | COMMA@[40; 41) | ||
27 | WHITESPACE@[41; 50) | ||
28 | ENUM_VARIANT@[50; 62) | ||
29 | NAME@[50; 54) | ||
30 | IDENT@[50; 54) "Var2" | ||
31 | POS_FIELD_LIST@[54; 62) | ||
32 | L_PAREN@[54; 55) | ||
33 | POS_FIELD@[55; 61) | ||
34 | PATH_TYPE@[55; 61) | ||
35 | PATH@[55; 61) | ||
36 | PATH_SEGMENT@[55; 61) | ||
37 | NAME_REF@[55; 61) | ||
38 | IDENT@[55; 61) "String" | ||
39 | R_PAREN@[61; 62) | ||
40 | COMMA@[62; 63) | ||
41 | WHITESPACE@[63; 72) | ||
42 | ENUM_VARIANT@[72; 145) | ||
43 | NAME@[72; 76) | ||
44 | IDENT@[72; 76) "Var3" | ||
45 | WHITESPACE@[76; 77) | ||
46 | NAMED_FIELD_DEF_LIST@[77; 145) | ||
47 | L_CURLY@[77; 78) | ||
48 | WHITESPACE@[78; 91) | ||
49 | NAMED_FIELD_DEF@[91; 95) | ||
50 | NAME@[91; 94) | ||
51 | IDENT@[91; 94) "abc" | ||
52 | COLON@[94; 95) | ||
53 | err: `expected type` | ||
54 | err: `expected COMMA` | ||
55 | WHITESPACE@[95; 96) | ||
56 | err: `expected field` | ||
57 | ERROR@[96; 98) | ||
58 | L_CURLY@[96; 97) | ||
59 | R_CURLY@[97; 98) | ||
60 | err: `expected field declaration` | ||
61 | ERROR@[98; 99) | ||
62 | COMMA@[98; 99) | ||
63 | WHITESPACE@[99; 100) | ||
64 | COMMENT@[100; 135) | ||
65 | WHITESPACE@[135; 144) | ||
66 | R_CURLY@[144; 145) | ||
67 | COMMA@[145; 146) | ||
68 | WHITESPACE@[146; 151) | ||
69 | R_CURLY@[151; 152) | ||
70 | WHITESPACE@[152; 158) | ||
71 | COMMENT@[158; 171) | ||
72 | WHITESPACE@[171; 176) | ||
73 | LET_STMT@[176; 186) | ||
74 | LET_KW@[176; 179) | ||
75 | WHITESPACE@[179; 180) | ||
76 | BIND_PAT@[180; 181) | ||
77 | NAME@[180; 181) | ||
78 | IDENT@[180; 181) "a" | ||
79 | WHITESPACE@[181; 182) | ||
80 | EQ@[182; 183) | ||
81 | WHITESPACE@[183; 184) | ||
82 | LITERAL@[184; 185) | ||
83 | INT_NUMBER@[184; 185) "1" | ||
84 | SEMI@[185; 186) | ||
85 | WHITESPACE@[186; 191) | ||
86 | ENUM_DEF@[191; 223) | ||
87 | ENUM_KW@[191; 195) | ||
88 | WHITESPACE@[195; 196) | ||
89 | NAME@[196; 201) | ||
90 | IDENT@[196; 201) "Test2" | ||
91 | WHITESPACE@[201; 202) | ||
92 | ENUM_VARIANT_LIST@[202; 223) | ||
93 | L_CURLY@[202; 203) | ||
94 | WHITESPACE@[203; 212) | ||
95 | ENUM_VARIANT@[212; 216) | ||
96 | NAME@[212; 216) | ||
97 | IDENT@[212; 216) "Fine" | ||
98 | COMMA@[216; 217) | ||
99 | WHITESPACE@[217; 222) | ||
100 | R_CURLY@[222; 223) | ||
101 | WHITESPACE@[223; 229) | ||
102 | ENUM_DEF@[229; 300) | ||
103 | ENUM_KW@[229; 233) | ||
104 | WHITESPACE@[233; 234) | ||
105 | NAME@[234; 239) | ||
106 | IDENT@[234; 239) "Test3" | ||
107 | WHITESPACE@[239; 240) | ||
108 | ENUM_VARIANT_LIST@[240; 300) | ||
109 | L_CURLY@[240; 241) | ||
110 | WHITESPACE@[241; 250) | ||
111 | ENUM_VARIANT@[250; 293) | ||
112 | NAME@[250; 259) | ||
113 | IDENT@[250; 259) "StillFine" | ||
114 | WHITESPACE@[259; 260) | ||
115 | NAMED_FIELD_DEF_LIST@[260; 293) | ||
116 | L_CURLY@[260; 261) | ||
117 | WHITESPACE@[261; 274) | ||
118 | NAMED_FIELD_DEF@[274; 282) | ||
119 | NAME@[274; 277) | ||
120 | IDENT@[274; 277) "def" | ||
121 | COLON@[277; 278) | ||
122 | WHITESPACE@[278; 279) | ||
123 | PATH_TYPE@[279; 282) | ||
124 | PATH@[279; 282) | ||
125 | PATH_SEGMENT@[279; 282) | ||
126 | NAME_REF@[279; 282) | ||
127 | IDENT@[279; 282) "i32" | ||
128 | COMMA@[282; 283) | ||
129 | WHITESPACE@[283; 292) | ||
130 | R_CURLY@[292; 293) | ||
131 | COMMA@[293; 294) | ||
132 | WHITESPACE@[294; 299) | ||
133 | R_CURLY@[299; 300) | ||
134 | WHITESPACE@[300; 306) | ||
135 | EXPR_STMT@[306; 459) | ||
136 | BLOCK_EXPR@[306; 459) | ||
137 | BLOCK@[306; 459) | ||
138 | L_CURLY@[306; 307) | ||
139 | WHITESPACE@[307; 316) | ||
140 | COMMENT@[316; 329) | ||
141 | WHITESPACE@[329; 338) | ||
142 | ENUM_DEF@[338; 453) | ||
143 | ENUM_KW@[338; 342) | ||
144 | WHITESPACE@[342; 343) | ||
145 | NAME@[343; 348) | ||
146 | IDENT@[343; 348) "Test4" | ||
147 | WHITESPACE@[348; 349) | ||
148 | ENUM_VARIANT_LIST@[349; 453) | ||
149 | L_CURLY@[349; 350) | ||
150 | WHITESPACE@[350; 363) | ||
151 | ENUM_VARIANT@[363; 372) | ||
152 | NAME@[363; 367) | ||
153 | IDENT@[363; 367) "Nope" | ||
154 | POS_FIELD_LIST@[367; 372) | ||
155 | L_PAREN@[367; 368) | ||
156 | POS_FIELD@[368; 371) | ||
157 | PATH_TYPE@[368; 371) | ||
158 | PATH@[368; 371) | ||
159 | PATH_SEGMENT@[368; 371) | ||
160 | NAME_REF@[368; 371) | ||
161 | IDENT@[368; 371) "i32" | ||
162 | err: `expected COMMA` | ||
163 | WHITESPACE@[371; 372) | ||
164 | err: `expected a type` | ||
165 | err: `expected R_PAREN` | ||
166 | err: `expected COMMA` | ||
167 | err: `expected enum variant` | ||
168 | ERROR@[372; 372) | ||
169 | ERROR@[372; 374) | ||
170 | L_CURLY@[372; 373) | ||
171 | R_CURLY@[373; 374) | ||
172 | err: `expected enum variant` | ||
173 | ERROR@[374; 375) | ||
174 | R_PAREN@[374; 375) | ||
175 | WHITESPACE@[375; 376) | ||
176 | COMMENT@[376; 396) | ||
177 | WHITESPACE@[396; 422) | ||
178 | COMMENT@[422; 443) | ||
179 | WHITESPACE@[443; 452) | ||
180 | R_CURLY@[452; 453) | ||
181 | WHITESPACE@[453; 458) | ||
182 | R_CURLY@[458; 459) | ||
183 | WHITESPACE@[459; 464) | ||
184 | COMMENT@[464; 486) | ||
185 | WHITESPACE@[486; 491) | ||
186 | LET_STMT@[491; 510) | ||
187 | LET_KW@[491; 494) | ||
188 | WHITESPACE@[494; 495) | ||
189 | BIND_PAT@[495; 505) | ||
190 | NAME@[495; 505) | ||
191 | IDENT@[495; 505) "bad_syntax" | ||
192 | WHITESPACE@[505; 506) | ||
193 | EQ@[506; 507) | ||
194 | WHITESPACE@[507; 508) | ||
195 | err: `expected expression` | ||
196 | ERROR@[508; 509) | ||
197 | UNDERSCORE@[508; 509) | ||
198 | SEMI@[509; 510) | ||
199 | WHITESPACE@[510; 511) | ||
200 | COMMENT@[511; 572) | ||
201 | WHITESPACE@[572; 573) | ||
202 | R_CURLY@[573; 574) | ||
203 | WHITESPACE@[574; 575) | ||