diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-02-04 11:04:02 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-02-04 11:04:02 +0000 |
commit | aa36ad008eae28d1251a4bf276b1d13398fcf89f (patch) | |
tree | 838d2875f00d1d0c4b3d747dfd7c314abf9ac404 /src/parser/grammar/items/use_item.rs | |
parent | 5e5313a7c71d8aa873b418575f56d23b2eac6e7f (diff) | |
parent | d4179550cd69a23a79ed27a96b93f9f760c02b69 (diff) |
Merge #41
41: G: unsafe impl & trait r=matklad a=matklad
bors r+
Diffstat (limited to 'src/parser/grammar/items/use_item.rs')
-rw-r--r-- | src/parser/grammar/items/use_item.rs | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/parser/grammar/items/use_item.rs b/src/parser/grammar/items/use_item.rs new file mode 100644 index 000000000..38e7b3f8a --- /dev/null +++ b/src/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 | } | ||