aboutsummaryrefslogtreecommitdiff
path: root/src/parser/event_parser
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-01-13 10:42:19 +0000
committerAleksey Kladov <[email protected]>2018-01-13 10:42:19 +0000
commit55891be06a1f0a051638cb59f1d15167faf5ab82 (patch)
tree2816530bc237e66b6d7b40f29838d7bbed085f7f /src/parser/event_parser
parent29b2e0adcc35834dda2884222624bfcc268a3eff (diff)
G: use trees
Diffstat (limited to 'src/parser/event_parser')
-rw-r--r--src/parser/event_parser/grammar/items.rs56
-rw-r--r--src/parser/event_parser/grammar/paths.rs22
2 files changed, 71 insertions, 7 deletions
diff --git a/src/parser/event_parser/grammar/items.rs b/src/parser/event_parser/grammar/items.rs
index f7310c09a..2f64111ab 100644
--- a/src/parser/event_parser/grammar/items.rs
+++ b/src/parser/event_parser/grammar/items.rs
@@ -74,9 +74,63 @@ fn mod_item(p: &mut Parser) {
74 p.curly_block(mod_contents); 74 p.curly_block(mod_contents);
75} 75}
76 76
77pub(super) fn is_use_tree_start(kind: SyntaxKind) -> bool {
78 kind == STAR || kind == L_CURLY
79}
80
77fn use_item(p: &mut Parser) { 81fn use_item(p: &mut Parser) {
78 paths::use_path(p); 82 use_tree(p);
79 p.expect(SEMI); 83 p.expect(SEMI);
84
85 fn use_tree(p: &mut Parser) -> bool{
86 if node_if(p, STAR, USE_TREE, |_| ()) {
87 return true
88 }
89 if node_if(p, [COLONCOLON, STAR], USE_TREE, |_| ()) {
90 return true
91 }
92 if [COLONCOLON, L_CURLY].is_ahead(p) || L_CURLY.is_ahead(p) {
93 node(p, USE_TREE, |p| {
94 p.eat(COLONCOLON);
95 p.curly_block(|p| {
96 comma_list(p, EOF, use_tree);
97 });
98 });
99 return true;
100 }
101 if paths::is_path_start(p) {
102 node(p, USE_TREE, |p| {
103 paths::use_path(p);
104 match p.current() {
105 AS_KW => {
106 alias(p);
107 }
108 COLONCOLON => {
109 p.bump();
110 match p.current() {
111 STAR => {
112 p.bump();
113 }
114 L_CURLY => {
115 p.curly_block(|p| {
116 comma_list(p, EOF, use_tree);
117 });
118 }
119 _ => {
120 // is this unreachable?
121 p.error()
122 .message("expected `{` or `*`")
123 .emit();
124 }
125 }
126 }
127 _ => (),
128 }
129 });
130 return true;
131 }
132 false
133 }
80} 134}
81 135
82fn struct_field(p: &mut Parser) -> bool { 136fn struct_field(p: &mut Parser) -> bool {
diff --git a/src/parser/event_parser/grammar/paths.rs b/src/parser/event_parser/grammar/paths.rs
index d6887a9ba..62d1a3bb2 100644
--- a/src/parser/event_parser/grammar/paths.rs
+++ b/src/parser/event_parser/grammar/paths.rs
@@ -1,7 +1,11 @@
1use super::*; 1use super::*;
2 2
3pub (crate) fn is_path_start(p: &Parser) -> bool {
4 AnyOf(&[IDENT, SELF_KW, SUPER_KW, COLONCOLON]).is_ahead(p)
5}
6
3pub(crate) fn use_path(p: &mut Parser) { 7pub(crate) fn use_path(p: &mut Parser) {
4 if !AnyOf(&[IDENT, SELF_KW, SUPER_KW, COLONCOLON]).is_ahead(p) { 8 if !is_path_start(p) {
5 return; 9 return;
6 } 10 }
7 let mut prev = p.mark(); 11 let mut prev = p.mark();
@@ -10,11 +14,17 @@ pub(crate) fn use_path(p: &mut Parser) {
10 }); 14 });
11 many(p, |p| { 15 many(p, |p| {
12 let curr = p.mark(); 16 let curr = p.mark();
13 node_if(p, COLONCOLON, PATH, |p| { 17 if p.current() == COLONCOLON && !items::is_use_tree_start(p.raw_lookahead(1)) {
14 path_segment(p, false); 18 node(p, PATH, |p| {
15 p.forward_parent(prev, curr); 19 p.bump();
16 prev = curr; 20 path_segment(p, false);
17 }) 21 p.forward_parent(prev, curr);
22 prev = curr;
23 });
24 true
25 } else {
26 false
27 }
18 }); 28 });
19} 29}
20 30