diff options
Diffstat (limited to 'src/parser/event_parser/grammar/items/mod.rs')
-rw-r--r-- | src/parser/event_parser/grammar/items/mod.rs | 143 |
1 files changed, 2 insertions, 141 deletions
diff --git a/src/parser/event_parser/grammar/items/mod.rs b/src/parser/event_parser/grammar/items/mod.rs index a6d8f375c..35825e7c4 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 => { |
@@ -82,76 +83,6 @@ fn item(p: &mut Parser) { | |||
82 | item.complete(p, item_kind); | 83 | item.complete(p, item_kind); |
83 | } | 84 | } |
84 | 85 | ||
85 | fn type_param_list(p: &mut Parser) { | ||
86 | if !p.at(L_ANGLE) { | ||
87 | return; | ||
88 | } | ||
89 | let m = p.start(); | ||
90 | p.bump(); | ||
91 | |||
92 | while !p.at(EOF) && !p.at(R_ANGLE) { | ||
93 | match p.current() { | ||
94 | LIFETIME => lifetime_param(p), | ||
95 | IDENT => type_param(p), | ||
96 | _ => p.err_and_bump("expected type parameter"), | ||
97 | } | ||
98 | if !p.at(R_ANGLE) && !p.expect(COMMA) { | ||
99 | break; | ||
100 | } | ||
101 | } | ||
102 | p.expect(R_ANGLE); | ||
103 | m.complete(p, TYPE_PARAM_LIST); | ||
104 | |||
105 | fn lifetime_param(p: &mut Parser) { | ||
106 | assert!(p.at(LIFETIME)); | ||
107 | let m = p.start(); | ||
108 | p.bump(); | ||
109 | if p.eat(COLON) { | ||
110 | while p.at(LIFETIME) { | ||
111 | p.bump(); | ||
112 | if !p.eat(PLUS) { | ||
113 | break; | ||
114 | } | ||
115 | } | ||
116 | } | ||
117 | m.complete(p, LIFETIME_PARAM); | ||
118 | } | ||
119 | |||
120 | fn type_param(p: &mut Parser) { | ||
121 | assert!(p.at(IDENT)); | ||
122 | let m = p.start(); | ||
123 | p.bump(); | ||
124 | if p.eat(COLON) { | ||
125 | loop { | ||
126 | let has_paren = p.eat(L_PAREN); | ||
127 | p.eat(QUESTION); | ||
128 | if p.at(FOR_KW) { | ||
129 | //TODO | ||
130 | } | ||
131 | if p.at(LIFETIME) { | ||
132 | p.bump(); | ||
133 | } else if paths::is_path_start(p) { | ||
134 | paths::type_path(p); | ||
135 | } else { | ||
136 | break; | ||
137 | } | ||
138 | if has_paren { | ||
139 | p.expect(R_PAREN); | ||
140 | } | ||
141 | if !p.eat(PLUS) { | ||
142 | break; | ||
143 | } | ||
144 | } | ||
145 | } | ||
146 | if p.at(EQ) { | ||
147 | types::type_ref(p) | ||
148 | } | ||
149 | m.complete(p, TYPE_PARAM); | ||
150 | } | ||
151 | } | ||
152 | |||
153 | fn where_clause(_: &mut Parser) {} | ||
154 | |||
155 | fn extern_crate_item(p: &mut Parser) { | 86 | fn extern_crate_item(p: &mut Parser) { |
156 | assert!(p.at(EXTERN_KW)); | 87 | assert!(p.at(EXTERN_KW)); |
157 | p.bump(); | 88 | p.bump(); |
@@ -179,76 +110,6 @@ fn extern_block(p: &mut Parser) { | |||
179 | p.expect(R_CURLY); | 110 | p.expect(R_CURLY); |
180 | } | 111 | } |
181 | 112 | ||
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) { | 113 | fn abi(p: &mut Parser) { |
253 | assert!(p.at(EXTERN_KW)); | 114 | assert!(p.at(EXTERN_KW)); |
254 | let abi = p.start(); | 115 | let abi = p.start(); |