diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/parser/event_parser/grammar/items/mod.rs | 73 | ||||
-rw-r--r-- | src/parser/event_parser/grammar/items/use_item.rs | 66 | ||||
-rw-r--r-- | src/parser/event_parser/grammar/paths.rs | 6 |
3 files changed, 73 insertions, 72 deletions
diff --git a/src/parser/event_parser/grammar/items/mod.rs b/src/parser/event_parser/grammar/items/mod.rs index a6d8f375c..1c092779b 100644 --- a/src/parser/event_parser/grammar/items/mod.rs +++ b/src/parser/event_parser/grammar/items/mod.rs | |||
@@ -1,6 +1,7 @@ | |||
1 | use super::*; | 1 | use super::*; |
2 | 2 | ||
3 | mod structs; | 3 | mod structs; |
4 | mod use_item; | ||
4 | 5 | ||
5 | pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) { | 6 | pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) { |
6 | attributes::inner_attributes(p); | 7 | attributes::inner_attributes(p); |
@@ -20,7 +21,7 @@ fn item(p: &mut Parser) { | |||
20 | let la = p.nth(1); | 21 | let la = p.nth(1); |
21 | let item_kind = match p.current() { | 22 | let item_kind = match p.current() { |
22 | USE_KW => { | 23 | USE_KW => { |
23 | use_item(p); | 24 | use_item::use_item(p); |
24 | USE_ITEM | 25 | USE_ITEM |
25 | } | 26 | } |
26 | EXTERN_KW if la == CRATE_KW => { | 27 | EXTERN_KW if la == CRATE_KW => { |
@@ -179,76 +180,6 @@ fn extern_block(p: &mut Parser) { | |||
179 | p.expect(R_CURLY); | 180 | p.expect(R_CURLY); |
180 | } | 181 | } |
181 | 182 | ||
182 | pub(super) fn is_use_tree_start(kind: SyntaxKind) -> bool { | ||
183 | kind == STAR || kind == L_CURLY | ||
184 | } | ||
185 | |||
186 | fn use_item(p: &mut Parser) { | ||
187 | assert!(p.at(USE_KW)); | ||
188 | p.bump(); | ||
189 | |||
190 | use_tree(p); | ||
191 | p.expect(SEMI); | ||
192 | |||
193 | fn use_tree(p: &mut Parser) { | ||
194 | let la = p.nth(1); | ||
195 | let m = p.start(); | ||
196 | match (p.current(), la) { | ||
197 | (STAR, _) => p.bump(), | ||
198 | (COLONCOLON, STAR) => { | ||
199 | p.bump(); | ||
200 | p.bump(); | ||
201 | } | ||
202 | (L_CURLY, _) | (COLONCOLON, L_CURLY) => { | ||
203 | if p.at(COLONCOLON) { | ||
204 | p.bump(); | ||
205 | } | ||
206 | nested_trees(p); | ||
207 | } | ||
208 | _ if paths::is_path_start(p) => { | ||
209 | paths::use_path(p); | ||
210 | match p.current() { | ||
211 | AS_KW => { | ||
212 | alias(p); | ||
213 | } | ||
214 | COLONCOLON => { | ||
215 | p.bump(); | ||
216 | match p.current() { | ||
217 | STAR => { | ||
218 | p.bump(); | ||
219 | } | ||
220 | L_CURLY => nested_trees(p), | ||
221 | _ => { | ||
222 | // is this unreachable? | ||
223 | p.error().message("expected `{` or `*`").emit(); | ||
224 | } | ||
225 | } | ||
226 | } | ||
227 | _ => (), | ||
228 | } | ||
229 | } | ||
230 | _ => { | ||
231 | m.abandon(p); | ||
232 | p.err_and_bump("expected one of `*`, `::`, `{`, `self`, `super`, `indent`"); | ||
233 | return; | ||
234 | } | ||
235 | } | ||
236 | m.complete(p, USE_TREE); | ||
237 | } | ||
238 | |||
239 | fn nested_trees(p: &mut Parser) { | ||
240 | assert!(p.at(L_CURLY)); | ||
241 | p.bump(); | ||
242 | while !p.at(EOF) && !p.at(R_CURLY) { | ||
243 | use_tree(p); | ||
244 | if !p.at(R_CURLY) { | ||
245 | p.expect(COMMA); | ||
246 | } | ||
247 | } | ||
248 | p.expect(R_CURLY); | ||
249 | } | ||
250 | } | ||
251 | |||
252 | fn abi(p: &mut Parser) { | 183 | fn abi(p: &mut Parser) { |
253 | assert!(p.at(EXTERN_KW)); | 184 | assert!(p.at(EXTERN_KW)); |
254 | let abi = p.start(); | 185 | let abi = p.start(); |
diff --git a/src/parser/event_parser/grammar/items/use_item.rs b/src/parser/event_parser/grammar/items/use_item.rs new file mode 100644 index 000000000..38e7b3f8a --- /dev/null +++ b/src/parser/event_parser/grammar/items/use_item.rs | |||
@@ -0,0 +1,66 @@ | |||
1 | use super::*; | ||
2 | |||
3 | pub(super) fn use_item(p: &mut Parser) { | ||
4 | assert!(p.at(USE_KW)); | ||
5 | p.bump(); | ||
6 | use_tree(p); | ||
7 | p.expect(SEMI); | ||
8 | } | ||
9 | |||
10 | fn use_tree(p: &mut Parser) { | ||
11 | let la = p.nth(1); | ||
12 | let m = p.start(); | ||
13 | match (p.current(), la) { | ||
14 | (STAR, _) => p.bump(), | ||
15 | (COLONCOLON, STAR) => { | ||
16 | p.bump(); | ||
17 | p.bump(); | ||
18 | } | ||
19 | (L_CURLY, _) | (COLONCOLON, L_CURLY) => { | ||
20 | if p.at(COLONCOLON) { | ||
21 | p.bump(); | ||
22 | } | ||
23 | nested_trees(p); | ||
24 | } | ||
25 | _ if paths::is_path_start(p) => { | ||
26 | paths::use_path(p); | ||
27 | match p.current() { | ||
28 | AS_KW => { | ||
29 | alias(p); | ||
30 | } | ||
31 | COLONCOLON => { | ||
32 | p.bump(); | ||
33 | match p.current() { | ||
34 | STAR => { | ||
35 | p.bump(); | ||
36 | } | ||
37 | L_CURLY => nested_trees(p), | ||
38 | _ => { | ||
39 | // is this unreachable? | ||
40 | p.error().message("expected `{` or `*`").emit(); | ||
41 | } | ||
42 | } | ||
43 | } | ||
44 | _ => (), | ||
45 | } | ||
46 | } | ||
47 | _ => { | ||
48 | m.abandon(p); | ||
49 | p.err_and_bump("expected one of `*`, `::`, `{`, `self`, `super`, `indent`"); | ||
50 | return; | ||
51 | } | ||
52 | } | ||
53 | m.complete(p, USE_TREE); | ||
54 | } | ||
55 | |||
56 | fn nested_trees(p: &mut Parser) { | ||
57 | assert!(p.at(L_CURLY)); | ||
58 | p.bump(); | ||
59 | while !p.at(EOF) && !p.at(R_CURLY) { | ||
60 | use_tree(p); | ||
61 | if !p.at(R_CURLY) { | ||
62 | p.expect(COMMA); | ||
63 | } | ||
64 | } | ||
65 | p.expect(R_CURLY); | ||
66 | } | ||
diff --git a/src/parser/event_parser/grammar/paths.rs b/src/parser/event_parser/grammar/paths.rs index 4c0d2c8b4..6efac2610 100644 --- a/src/parser/event_parser/grammar/paths.rs +++ b/src/parser/event_parser/grammar/paths.rs | |||
@@ -20,7 +20,11 @@ fn path(p: &mut Parser) { | |||
20 | path_segment(p, true); | 20 | path_segment(p, true); |
21 | let mut qual = path.complete(p, PATH); | 21 | let mut qual = path.complete(p, PATH); |
22 | loop { | 22 | loop { |
23 | if p.at(COLONCOLON) && !items::is_use_tree_start(p.nth(1)) { | 23 | let use_tree = match p.nth(1) { |
24 | STAR | L_CURLY => true, | ||
25 | _ => false, | ||
26 | }; | ||
27 | if p.at(COLONCOLON) && !use_tree { | ||
24 | let path = qual.precede(p); | 28 | let path = qual.precede(p); |
25 | p.bump(); | 29 | p.bump(); |
26 | path_segment(p, false); | 30 | path_segment(p, false); |