aboutsummaryrefslogtreecommitdiff
path: root/src/parser/event_parser/grammar/items/mod.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-02-02 19:21:06 +0000
committerAleksey Kladov <[email protected]>2018-02-02 19:21:06 +0000
commit7cdf990c40e932a466e8799ca3fa582467d32c91 (patch)
tree576f37f47b9cde6cc4f9ee0890f59cda58d03a14 /src/parser/event_parser/grammar/items/mod.rs
parenta1fcead680b0f52036dd48dd1781606e7a7339db (diff)
Move use item parsing to a separate file
Diffstat (limited to 'src/parser/event_parser/grammar/items/mod.rs')
-rw-r--r--src/parser/event_parser/grammar/items/mod.rs73
1 files changed, 2 insertions, 71 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 @@
1use super::*; 1use super::*;
2 2
3mod structs; 3mod structs;
4mod use_item;
4 5
5pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) { 6pub(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
182pub(super) fn is_use_tree_start(kind: SyntaxKind) -> bool {
183 kind == STAR || kind == L_CURLY
184}
185
186fn 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
252fn abi(p: &mut Parser) { 183fn 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();