2018-02-02 13:21:06 -06:00
|
|
|
use super::*;
|
|
|
|
|
|
|
|
pub(super) fn use_item(p: &mut Parser) {
|
|
|
|
assert!(p.at(USE_KW));
|
|
|
|
p.bump();
|
|
|
|
use_tree(p);
|
|
|
|
p.expect(SEMI);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn use_tree(p: &mut Parser) {
|
|
|
|
let la = p.nth(1);
|
|
|
|
let m = p.start();
|
|
|
|
match (p.current(), la) {
|
|
|
|
(STAR, _) => p.bump(),
|
|
|
|
(COLONCOLON, STAR) => {
|
|
|
|
p.bump();
|
|
|
|
p.bump();
|
|
|
|
}
|
|
|
|
(L_CURLY, _) | (COLONCOLON, L_CURLY) => {
|
|
|
|
if p.at(COLONCOLON) {
|
|
|
|
p.bump();
|
|
|
|
}
|
2018-08-24 11:27:30 -05:00
|
|
|
use_tree_list(p);
|
2018-02-02 13:21:06 -06:00
|
|
|
}
|
|
|
|
_ if paths::is_path_start(p) => {
|
|
|
|
paths::use_path(p);
|
|
|
|
match p.current() {
|
|
|
|
AS_KW => {
|
2018-08-23 17:19:38 -05:00
|
|
|
opt_alias(p);
|
2018-02-02 13:21:06 -06:00
|
|
|
}
|
|
|
|
COLONCOLON => {
|
|
|
|
p.bump();
|
|
|
|
match p.current() {
|
|
|
|
STAR => {
|
|
|
|
p.bump();
|
|
|
|
}
|
2018-08-24 11:27:30 -05:00
|
|
|
L_CURLY => use_tree_list(p),
|
2018-02-02 13:21:06 -06:00
|
|
|
_ => {
|
|
|
|
// is this unreachable?
|
2018-02-09 13:44:50 -06:00
|
|
|
p.error("expected `{` or `*`");
|
2018-02-02 13:21:06 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
m.abandon(p);
|
|
|
|
p.err_and_bump("expected one of `*`, `::`, `{`, `self`, `super`, `indent`");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m.complete(p, USE_TREE);
|
|
|
|
}
|
|
|
|
|
2018-08-24 11:27:30 -05:00
|
|
|
fn use_tree_list(p: &mut Parser) {
|
2018-02-02 13:21:06 -06:00
|
|
|
assert!(p.at(L_CURLY));
|
2018-08-24 11:27:30 -05:00
|
|
|
let m = p.start();
|
2018-02-02 13:21:06 -06:00
|
|
|
p.bump();
|
|
|
|
while !p.at(EOF) && !p.at(R_CURLY) {
|
|
|
|
use_tree(p);
|
|
|
|
if !p.at(R_CURLY) {
|
|
|
|
p.expect(COMMA);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p.expect(R_CURLY);
|
2018-08-24 11:27:30 -05:00
|
|
|
m.complete(p, USE_TREE_LIST);
|
2018-02-02 13:21:06 -06:00
|
|
|
}
|