diff options
Diffstat (limited to 'src/parser/event_parser/grammar/items.rs')
-rw-r--r-- | src/parser/event_parser/grammar/items.rs | 258 |
1 files changed, 0 insertions, 258 deletions
diff --git a/src/parser/event_parser/grammar/items.rs b/src/parser/event_parser/grammar/items.rs deleted file mode 100644 index 56e3208ac..000000000 --- a/src/parser/event_parser/grammar/items.rs +++ /dev/null | |||
@@ -1,258 +0,0 @@ | |||
1 | use super::*; | ||
2 | |||
3 | pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) { | ||
4 | attributes::inner_attributes(p); | ||
5 | while !p.at(EOF) && !(stop_on_r_curly && p.at(R_CURLY)) { | ||
6 | item(p); | ||
7 | } | ||
8 | } | ||
9 | |||
10 | pub(super) const ITEM_FIRST: TokenSet = | ||
11 | token_set![EXTERN_KW, MOD_KW, USE_KW, STRUCT_KW, FN_KW, PUB_KW, POUND,]; | ||
12 | |||
13 | fn item(p: &mut Parser) { | ||
14 | let item = p.start(); | ||
15 | attributes::outer_attributes(p); | ||
16 | visibility(p); | ||
17 | let la = p.nth(1); | ||
18 | let item_kind = match p.current() { | ||
19 | EXTERN_KW if la == CRATE_KW => { | ||
20 | extern_crate_item(p); | ||
21 | EXTERN_CRATE_ITEM | ||
22 | } | ||
23 | MOD_KW => { | ||
24 | mod_item(p); | ||
25 | MOD_ITEM | ||
26 | } | ||
27 | USE_KW => { | ||
28 | use_item(p); | ||
29 | USE_ITEM | ||
30 | } | ||
31 | STRUCT_KW => { | ||
32 | struct_item(p); | ||
33 | STRUCT_ITEM | ||
34 | } | ||
35 | FN_KW => { | ||
36 | fn_item(p); | ||
37 | FN_ITEM | ||
38 | } | ||
39 | L_CURLY => { | ||
40 | item.abandon(p); | ||
41 | error_block(p, "expected item"); | ||
42 | return; | ||
43 | } | ||
44 | err_token => { | ||
45 | item.abandon(p); | ||
46 | let message = if err_token == SEMI { | ||
47 | //TODO: if the item is incomplete, this message is misleading | ||
48 | "expected item, found `;`\n\ | ||
49 | consider removing this semicolon" | ||
50 | } else { | ||
51 | "expected item" | ||
52 | }; | ||
53 | p.err_and_bump(message); | ||
54 | return; | ||
55 | } | ||
56 | }; | ||
57 | item.complete(p, item_kind); | ||
58 | } | ||
59 | |||
60 | fn struct_item(p: &mut Parser) { | ||
61 | assert!(p.at(STRUCT_KW)); | ||
62 | p.bump(); | ||
63 | |||
64 | if !p.expect(IDENT) { | ||
65 | return; | ||
66 | } | ||
67 | generic_parameters(p); | ||
68 | match p.current() { | ||
69 | WHERE_KW => { | ||
70 | where_clause(p); | ||
71 | match p.current() { | ||
72 | SEMI => { | ||
73 | p.bump(); | ||
74 | return; | ||
75 | } | ||
76 | L_CURLY => named_fields(p), | ||
77 | _ => { | ||
78 | //TODO: special case `(` error message | ||
79 | p.error().message("expected `;` or `{`").emit(); | ||
80 | return; | ||
81 | } | ||
82 | } | ||
83 | } | ||
84 | SEMI => { | ||
85 | p.bump(); | ||
86 | return; | ||
87 | } | ||
88 | L_CURLY => named_fields(p), | ||
89 | L_PAREN => { | ||
90 | pos_fields(p); | ||
91 | p.expect(SEMI); | ||
92 | } | ||
93 | _ => { | ||
94 | p.error().message("expected `;`, `{`, or `(`").emit(); | ||
95 | return; | ||
96 | } | ||
97 | } | ||
98 | } | ||
99 | |||
100 | fn named_fields(p: &mut Parser) { | ||
101 | assert!(p.at(L_CURLY)); | ||
102 | p.bump(); | ||
103 | while !p.at(R_CURLY) && !p.at(EOF) { | ||
104 | named_field(p); | ||
105 | if !p.at(R_CURLY) { | ||
106 | p.expect(COMMA); | ||
107 | } | ||
108 | } | ||
109 | p.expect(R_CURLY); | ||
110 | |||
111 | fn named_field(p: &mut Parser) { | ||
112 | let field = p.start(); | ||
113 | visibility(p); | ||
114 | if p.expect(IDENT) { | ||
115 | p.expect(COLON); | ||
116 | types::type_ref(p); | ||
117 | field.complete(p, NAMED_FIELD); | ||
118 | } else { | ||
119 | field.abandon(p); | ||
120 | p.err_and_bump("expected field declaration"); | ||
121 | } | ||
122 | } | ||
123 | } | ||
124 | |||
125 | fn pos_fields(p: &mut Parser) { | ||
126 | if !p.expect(L_PAREN) { | ||
127 | return; | ||
128 | } | ||
129 | while !p.at(R_PAREN) && !p.at(EOF) { | ||
130 | let pos_field = p.start(); | ||
131 | visibility(p); | ||
132 | types::type_ref(p); | ||
133 | pos_field.complete(p, POS_FIELD); | ||
134 | |||
135 | if !p.at(R_PAREN) { | ||
136 | p.expect(COMMA); | ||
137 | } | ||
138 | } | ||
139 | p.expect(R_PAREN); | ||
140 | } | ||
141 | |||
142 | fn generic_parameters(_: &mut Parser) {} | ||
143 | |||
144 | fn where_clause(_: &mut Parser) {} | ||
145 | |||
146 | fn extern_crate_item(p: &mut Parser) { | ||
147 | assert!(p.at(EXTERN_KW)); | ||
148 | p.bump(); | ||
149 | assert!(p.at(CRATE_KW)); | ||
150 | p.bump(); | ||
151 | |||
152 | p.expect(IDENT) && alias(p) && p.expect(SEMI); | ||
153 | } | ||
154 | |||
155 | fn mod_item(p: &mut Parser) { | ||
156 | assert!(p.at(MOD_KW)); | ||
157 | p.bump(); | ||
158 | |||
159 | if p.expect(IDENT) && !p.eat(SEMI) { | ||
160 | if p.expect(L_CURLY) { | ||
161 | mod_contents(p, true); | ||
162 | p.expect(R_CURLY); | ||
163 | } | ||
164 | } | ||
165 | } | ||
166 | |||
167 | pub(super) fn is_use_tree_start(kind: SyntaxKind) -> bool { | ||
168 | kind == STAR || kind == L_CURLY | ||
169 | } | ||
170 | |||
171 | fn use_item(p: &mut Parser) { | ||
172 | assert!(p.at(USE_KW)); | ||
173 | p.bump(); | ||
174 | |||
175 | use_tree(p); | ||
176 | p.expect(SEMI); | ||
177 | |||
178 | fn use_tree(p: &mut Parser) { | ||
179 | let la = p.nth(1); | ||
180 | let m = p.start(); | ||
181 | match (p.current(), la) { | ||
182 | (STAR, _) => p.bump(), | ||
183 | (COLONCOLON, STAR) => { | ||
184 | p.bump(); | ||
185 | p.bump(); | ||
186 | } | ||
187 | (L_CURLY, _) | (COLONCOLON, L_CURLY) => { | ||
188 | if p.at(COLONCOLON) { | ||
189 | p.bump(); | ||
190 | } | ||
191 | nested_trees(p); | ||
192 | } | ||
193 | _ if paths::is_path_start(p) => { | ||
194 | paths::use_path(p); | ||
195 | match p.current() { | ||
196 | AS_KW => { | ||
197 | alias(p); | ||
198 | } | ||
199 | COLONCOLON => { | ||
200 | p.bump(); | ||
201 | match p.current() { | ||
202 | STAR => { | ||
203 | p.bump(); | ||
204 | } | ||
205 | L_CURLY => nested_trees(p), | ||
206 | _ => { | ||
207 | // is this unreachable? | ||
208 | p.error().message("expected `{` or `*`").emit(); | ||
209 | } | ||
210 | } | ||
211 | } | ||
212 | _ => (), | ||
213 | } | ||
214 | } | ||
215 | _ => { | ||
216 | m.abandon(p); | ||
217 | p.err_and_bump("expected one of `*`, `::`, `{`, `self`, `super`, `indent`"); | ||
218 | return; | ||
219 | } | ||
220 | } | ||
221 | m.complete(p, USE_TREE); | ||
222 | } | ||
223 | |||
224 | fn nested_trees(p: &mut Parser) { | ||
225 | assert!(p.at(L_CURLY)); | ||
226 | p.bump(); | ||
227 | while !p.at(EOF) && !p.at(R_CURLY) { | ||
228 | use_tree(p); | ||
229 | if !p.at(R_CURLY) { | ||
230 | p.expect(COMMA); | ||
231 | } | ||
232 | } | ||
233 | p.expect(R_CURLY); | ||
234 | } | ||
235 | } | ||
236 | |||
237 | fn fn_item(p: &mut Parser) { | ||
238 | assert!(p.at(FN_KW)); | ||
239 | p.bump(); | ||
240 | |||
241 | p.expect(IDENT); | ||
242 | if p.at(L_PAREN) { | ||
243 | fn_value_parameters(p); | ||
244 | } else { | ||
245 | p.error().message("expected function arguments").emit(); | ||
246 | } | ||
247 | |||
248 | if p.at(L_CURLY) { | ||
249 | p.expect(L_CURLY); | ||
250 | p.expect(R_CURLY); | ||
251 | } | ||
252 | |||
253 | fn fn_value_parameters(p: &mut Parser) { | ||
254 | assert!(p.at(L_PAREN)); | ||
255 | p.bump(); | ||
256 | p.expect(R_PAREN); | ||
257 | } | ||
258 | } | ||