aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src/grammar
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_parser/src/grammar')
-rw-r--r--crates/ra_parser/src/grammar/items.rs10
-rw-r--r--crates/ra_parser/src/grammar/items/adt.rs (renamed from crates/ra_parser/src/grammar/items/nominal.rs)23
2 files changed, 21 insertions, 12 deletions
diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs
index 85f7eeb00..370990e21 100644
--- a/crates/ra_parser/src/grammar/items.rs
+++ b/crates/ra_parser/src/grammar/items.rs
@@ -1,13 +1,13 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3mod consts; 3mod consts;
4mod nominal; 4mod adt;
5mod traits; 5mod traits;
6mod use_item; 6mod use_item;
7 7
8pub(crate) use self::{ 8pub(crate) use self::{
9 adt::{enum_variant_list, record_field_def_list},
9 expressions::{match_arm_list, record_field_list}, 10 expressions::{match_arm_list, record_field_list},
10 nominal::{enum_variant_list, record_field_def_list},
11 traits::{impl_item_list, trait_item_list}, 11 traits::{impl_item_list, trait_item_list},
12 use_item::use_tree_list, 12 use_item::use_tree_list,
13}; 13};
@@ -247,7 +247,7 @@ fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> {
247 // a: i32, 247 // a: i32,
248 // b: f32, 248 // b: f32,
249 // } 249 // }
250 nominal::struct_def(p, m, T![struct]); 250 adt::struct_def(p, m);
251 } 251 }
252 IDENT if p.at_contextual_kw("union") && p.nth(1) == IDENT => { 252 IDENT if p.at_contextual_kw("union") && p.nth(1) == IDENT => {
253 // test union_items 253 // test union_items
@@ -256,9 +256,9 @@ fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> {
256 // a: i32, 256 // a: i32,
257 // b: f32, 257 // b: f32,
258 // } 258 // }
259 nominal::struct_def(p, m, T![union]); 259 adt::union_def(p, m);
260 } 260 }
261 T![enum] => nominal::enum_def(p, m), 261 T![enum] => adt::enum_def(p, m),
262 T![use] => use_item::use_item(p, m), 262 T![use] => use_item::use_item(p, m),
263 T![const] if (la == IDENT || la == T![_] || la == T![mut]) => consts::const_def(p, m), 263 T![const] if (la == IDENT || la == T![_] || la == T![mut]) => consts::const_def(p, m),
264 T![static] => consts::static_def(p, m), 264 T![static] => consts::static_def(p, m),
diff --git a/crates/ra_parser/src/grammar/items/nominal.rs b/crates/ra_parser/src/grammar/items/adt.rs
index 9d8fb8486..c777bc9d0 100644
--- a/crates/ra_parser/src/grammar/items/nominal.rs
+++ b/crates/ra_parser/src/grammar/items/adt.rs
@@ -2,10 +2,19 @@
2 2
3use super::*; 3use super::*;
4 4
5pub(super) fn struct_def(p: &mut Parser, m: Marker, kind: SyntaxKind) { 5pub(super) fn struct_def(p: &mut Parser, m: Marker) {
6 assert!(p.at(T![struct]) || p.at_contextual_kw("union")); 6 assert!(p.at(T![struct]));
7 p.bump_remap(kind); 7 p.bump(T![struct]);
8 struct_or_union(p, m, T![struct], STRUCT_DEF);
9}
10
11pub(super) fn union_def(p: &mut Parser, m: Marker) {
12 assert!(p.at_contextual_kw("union"));
13 p.bump_remap(T![union]);
14 struct_or_union(p, m, T![union], UNION_DEF);
15}
8 16
17fn struct_or_union(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) {
9 name_r(p, ITEM_RECOVERY_SET); 18 name_r(p, ITEM_RECOVERY_SET);
10 type_params::opt_type_param_list(p); 19 type_params::opt_type_param_list(p);
11 match p.current() { 20 match p.current() {
@@ -22,11 +31,11 @@ pub(super) fn struct_def(p: &mut Parser, m: Marker, kind: SyntaxKind) {
22 } 31 }
23 } 32 }
24 } 33 }
25 T![;] if kind == T![struct] => { 34 T![;] if kw == T![struct] => {
26 p.bump(T![;]); 35 p.bump(T![;]);
27 } 36 }
28 T!['{'] => record_field_def_list(p), 37 T!['{'] => record_field_def_list(p),
29 T!['('] if kind == T![struct] => { 38 T!['('] if kw == T![struct] => {
30 tuple_field_def_list(p); 39 tuple_field_def_list(p);
31 // test tuple_struct_where 40 // test tuple_struct_where
32 // struct Test<T>(T) where T: Clone; 41 // struct Test<T>(T) where T: Clone;
@@ -34,14 +43,14 @@ pub(super) fn struct_def(p: &mut Parser, m: Marker, kind: SyntaxKind) {
34 type_params::opt_where_clause(p); 43 type_params::opt_where_clause(p);
35 p.expect(T![;]); 44 p.expect(T![;]);
36 } 45 }
37 _ if kind == T![struct] => { 46 _ if kw == T![struct] => {
38 p.error("expected `;`, `{`, or `(`"); 47 p.error("expected `;`, `{`, or `(`");
39 } 48 }
40 _ => { 49 _ => {
41 p.error("expected `{`"); 50 p.error("expected `{`");
42 } 51 }
43 } 52 }
44 m.complete(p, STRUCT_DEF); 53 m.complete(p, def);
45} 54}
46 55
47pub(super) fn enum_def(p: &mut Parser, m: Marker) { 56pub(super) fn enum_def(p: &mut Parser, m: Marker) {