aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src/grammar/items/nominal.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_parser/src/grammar/items/nominal.rs')
-rw-r--r--crates/ra_parser/src/grammar/items/nominal.rs66
1 files changed, 33 insertions, 33 deletions
diff --git a/crates/ra_parser/src/grammar/items/nominal.rs b/crates/ra_parser/src/grammar/items/nominal.rs
index e93bd76b8..bd4edab89 100644
--- a/crates/ra_parser/src/grammar/items/nominal.rs
+++ b/crates/ra_parser/src/grammar/items/nominal.rs
@@ -1,38 +1,38 @@
1use super::*; 1use super::*;
2 2
3pub(super) fn struct_def(p: &mut Parser, m: Marker, kind: SyntaxKind) { 3pub(super) fn struct_def(p: &mut Parser, m: Marker, kind: SyntaxKind) {
4 assert!(p.at(STRUCT_KW) || p.at_contextual_kw("union")); 4 assert!(p.at(T![struct]) || p.at_contextual_kw("union"));
5 p.bump_remap(kind); 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);
9 match p.current() { 9 match p.current() {
10 WHERE_KW => { 10 T![where] => {
11 type_params::opt_where_clause(p); 11 type_params::opt_where_clause(p);
12 match p.current() { 12 match p.current() {
13 SEMI => { 13 T![;] => {
14 p.bump(); 14 p.bump();
15 } 15 }
16 L_CURLY => named_field_def_list(p), 16 T!['{'] => named_field_def_list(p),
17 _ => { 17 _ => {
18 //FIXME: special case `(` error message 18 //FIXME: special case `(` error message
19 p.error("expected `;` or `{`"); 19 p.error("expected `;` or `{`");
20 } 20 }
21 } 21 }
22 } 22 }
23 SEMI if kind == STRUCT_KW => { 23 T![;] if kind == T![struct] => {
24 p.bump(); 24 p.bump();
25 } 25 }
26 L_CURLY => named_field_def_list(p), 26 T!['{'] => named_field_def_list(p),
27 L_PAREN if kind == STRUCT_KW => { 27 T!['('] if kind == T![struct] => {
28 pos_field_def_list(p); 28 pos_field_def_list(p);
29 // test tuple_struct_where 29 // test tuple_struct_where
30 // struct Test<T>(T) where T: Clone; 30 // struct Test<T>(T) where T: Clone;
31 // struct Test<T>(T); 31 // struct Test<T>(T);
32 type_params::opt_where_clause(p); 32 type_params::opt_where_clause(p);
33 p.expect(SEMI); 33 p.expect(T![;]);
34 } 34 }
35 _ if kind == STRUCT_KW => { 35 _ if kind == T![struct] => {
36 p.error("expected `;`, `{`, or `(`"); 36 p.error("expected `;`, `{`, or `(`");
37 } 37 }
38 _ => { 38 _ => {
@@ -43,12 +43,12 @@ pub(super) fn struct_def(p: &mut Parser, m: Marker, kind: SyntaxKind) {
43} 43}
44 44
45pub(super) fn enum_def(p: &mut Parser, m: Marker) { 45pub(super) fn enum_def(p: &mut Parser, m: Marker) {
46 assert!(p.at(ENUM_KW)); 46 assert!(p.at(T![enum]));
47 p.bump(); 47 p.bump();
48 name_r(p, ITEM_RECOVERY_SET); 48 name_r(p, ITEM_RECOVERY_SET);
49 type_params::opt_type_param_list(p); 49 type_params::opt_type_param_list(p);
50 type_params::opt_where_clause(p); 50 type_params::opt_where_clause(p);
51 if p.at(L_CURLY) { 51 if p.at(T!['{']) {
52 enum_variant_list(p); 52 enum_variant_list(p);
53 } else { 53 } else {
54 p.error("expected `{`") 54 p.error("expected `{`")
@@ -57,11 +57,11 @@ pub(super) fn enum_def(p: &mut Parser, m: Marker) {
57} 57}
58 58
59pub(crate) fn enum_variant_list(p: &mut Parser) { 59pub(crate) fn enum_variant_list(p: &mut Parser) {
60 assert!(p.at(L_CURLY)); 60 assert!(p.at(T!['{']));
61 let m = p.start(); 61 let m = p.start();
62 p.bump(); 62 p.bump();
63 while !p.at(EOF) && !p.at(R_CURLY) { 63 while !p.at(EOF) && !p.at(T!['}']) {
64 if p.at(L_CURLY) { 64 if p.at(T!['{']) {
65 error_block(p, "expected enum variant"); 65 error_block(p, "expected enum variant");
66 continue; 66 continue;
67 } 67 }
@@ -70,9 +70,9 @@ pub(crate) fn enum_variant_list(p: &mut Parser) {
70 if p.at(IDENT) { 70 if p.at(IDENT) {
71 name(p); 71 name(p);
72 match p.current() { 72 match p.current() {
73 L_CURLY => named_field_def_list(p), 73 T!['{'] => named_field_def_list(p),
74 L_PAREN => pos_field_def_list(p), 74 T!['('] => pos_field_def_list(p),
75 EQ => { 75 T![=] => {
76 p.bump(); 76 p.bump();
77 expressions::expr(p); 77 expressions::expr(p);
78 } 78 }
@@ -83,29 +83,29 @@ pub(crate) fn enum_variant_list(p: &mut Parser) {
83 var.abandon(p); 83 var.abandon(p);
84 p.err_and_bump("expected enum variant"); 84 p.err_and_bump("expected enum variant");
85 } 85 }
86 if !p.at(R_CURLY) { 86 if !p.at(T!['}']) {
87 p.expect(COMMA); 87 p.expect(T![,]);
88 } 88 }
89 } 89 }
90 p.expect(R_CURLY); 90 p.expect(T!['}']);
91 m.complete(p, ENUM_VARIANT_LIST); 91 m.complete(p, ENUM_VARIANT_LIST);
92} 92}
93 93
94pub(crate) fn named_field_def_list(p: &mut Parser) { 94pub(crate) fn named_field_def_list(p: &mut Parser) {
95 assert!(p.at(L_CURLY)); 95 assert!(p.at(T!['{']));
96 let m = p.start(); 96 let m = p.start();
97 p.bump(); 97 p.bump();
98 while !p.at(R_CURLY) && !p.at(EOF) { 98 while !p.at(T!['}']) && !p.at(EOF) {
99 if p.at(L_CURLY) { 99 if p.at(T!['{']) {
100 error_block(p, "expected field"); 100 error_block(p, "expected field");
101 continue; 101 continue;
102 } 102 }
103 named_field_def(p); 103 named_field_def(p);
104 if !p.at(R_CURLY) { 104 if !p.at(T!['}']) {
105 p.expect(COMMA); 105 p.expect(T![,]);
106 } 106 }
107 } 107 }
108 p.expect(R_CURLY); 108 p.expect(T!['}']);
109 m.complete(p, NAMED_FIELD_DEF_LIST); 109 m.complete(p, NAMED_FIELD_DEF_LIST);
110 110
111 fn named_field_def(p: &mut Parser) { 111 fn named_field_def(p: &mut Parser) {
@@ -119,7 +119,7 @@ pub(crate) fn named_field_def_list(p: &mut Parser) {
119 opt_visibility(p); 119 opt_visibility(p);
120 if p.at(IDENT) { 120 if p.at(IDENT) {
121 name(p); 121 name(p);
122 p.expect(COLON); 122 p.expect(T![:]);
123 types::type_(p); 123 types::type_(p);
124 m.complete(p, NAMED_FIELD_DEF); 124 m.complete(p, NAMED_FIELD_DEF);
125 } else { 125 } else {
@@ -130,12 +130,12 @@ pub(crate) fn named_field_def_list(p: &mut Parser) {
130} 130}
131 131
132fn pos_field_def_list(p: &mut Parser) { 132fn pos_field_def_list(p: &mut Parser) {
133 assert!(p.at(L_PAREN)); 133 assert!(p.at(T!['(']));
134 let m = p.start(); 134 let m = p.start();
135 if !p.expect(L_PAREN) { 135 if !p.expect(T!['(']) {
136 return; 136 return;
137 } 137 }
138 while !p.at(R_PAREN) && !p.at(EOF) { 138 while !p.at(T![')']) && !p.at(EOF) {
139 let m = p.start(); 139 let m = p.start();
140 // test pos_field_attrs 140 // test pos_field_attrs
141 // struct S ( 141 // struct S (
@@ -156,10 +156,10 @@ fn pos_field_def_list(p: &mut Parser) {
156 types::type_(p); 156 types::type_(p);
157 m.complete(p, POS_FIELD_DEF); 157 m.complete(p, POS_FIELD_DEF);
158 158
159 if !p.at(R_PAREN) { 159 if !p.at(T![')']) {
160 p.expect(COMMA); 160 p.expect(T![,]);
161 } 161 }
162 } 162 }
163 p.expect(R_PAREN); 163 p.expect(T![')']);
164 m.complete(p, POS_FIELD_DEF_LIST); 164 m.complete(p, POS_FIELD_DEF_LIST);
165} 165}