aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libsyntax2/src')
-rw-r--r--crates/libsyntax2/src/grammar/items/mod.rs21
-rw-r--r--crates/libsyntax2/src/grammar/items/nominal.rs16
2 files changed, 30 insertions, 7 deletions
diff --git a/crates/libsyntax2/src/grammar/items/mod.rs b/crates/libsyntax2/src/grammar/items/mod.rs
index 8c19aa179..2567313ab 100644
--- a/crates/libsyntax2/src/grammar/items/mod.rs
+++ b/crates/libsyntax2/src/grammar/items/mod.rs
@@ -181,7 +181,16 @@ fn items_without_modifiers(p: &mut Parser) -> Option<SyntaxKind> {
181 MODULE 181 MODULE
182 } 182 }
183 STRUCT_KW => { 183 STRUCT_KW => {
184 nominal::struct_def(p); 184 // test struct_items
185 // struct Foo;
186 // struct Foo {}
187 // struct Foo();
188 // struct Foo(String, usize);
189 // struct Foo {
190 // a: i32,
191 // b: f32,
192 // }
193 nominal::struct_def(p, STRUCT_KW);
185 if p.at(SEMI) { 194 if p.at(SEMI) {
186 p.err_and_bump( 195 p.err_and_bump(
187 "expected item, found `;`\n\ 196 "expected item, found `;`\n\
@@ -190,6 +199,16 @@ fn items_without_modifiers(p: &mut Parser) -> Option<SyntaxKind> {
190 } 199 }
191 STRUCT_DEF 200 STRUCT_DEF
192 } 201 }
202 IDENT if p.at_contextual_kw("union") => {
203 // test union_items
204 // union Foo {}
205 // union Foo {
206 // a: i32,
207 // b: f32,
208 // }
209 nominal::struct_def(p, UNION_KW);
210 STRUCT_DEF
211 }
193 ENUM_KW => { 212 ENUM_KW => {
194 nominal::enum_def(p); 213 nominal::enum_def(p);
195 ENUM_DEF 214 ENUM_DEF
diff --git a/crates/libsyntax2/src/grammar/items/nominal.rs b/crates/libsyntax2/src/grammar/items/nominal.rs
index 11c43e371..8d02ad555 100644
--- a/crates/libsyntax2/src/grammar/items/nominal.rs
+++ b/crates/libsyntax2/src/grammar/items/nominal.rs
@@ -1,8 +1,8 @@
1use super::*; 1use super::*;
2 2
3pub(super) fn struct_def(p: &mut Parser) { 3pub(super) fn struct_def(p: &mut Parser, kind: SyntaxKind) {
4 assert!(p.at(STRUCT_KW)); 4 assert!(p.at(STRUCT_KW) || p.at_contextual_kw("union"));
5 p.bump(); 5 p.bump_remap(kind);
6 6
7 name_r(p, ITEM_RECOVERY_SET); 7 name_r(p, ITEM_RECOVERY_SET);
8 type_params::opt_type_param_list(p); 8 type_params::opt_type_param_list(p);
@@ -22,19 +22,23 @@ pub(super) fn struct_def(p: &mut Parser) {
22 } 22 }
23 } 23 }
24 } 24 }
25 SEMI => { 25 SEMI if kind == STRUCT_KW => {
26 p.bump(); 26 p.bump();
27 return; 27 return;
28 } 28 }
29 L_CURLY => named_field_def_list(p), 29 L_CURLY => named_field_def_list(p),
30 L_PAREN => { 30 L_PAREN if kind == STRUCT_KW => {
31 pos_field_list(p); 31 pos_field_list(p);
32 p.expect(SEMI); 32 p.expect(SEMI);
33 } 33 }
34 _ => { 34 _ if kind == STRUCT_KW => {
35 p.error("expected `;`, `{`, or `(`"); 35 p.error("expected `;`, `{`, or `(`");
36 return; 36 return;
37 } 37 }
38 _ => {
39 p.error("expected `{`");
40 return;
41 }
38 } 42 }
39} 43}
40 44