2018-01-09 14:32:18 -06:00
|
|
|
use super::*;
|
|
|
|
|
2018-01-20 12:49:58 -06:00
|
|
|
pub(crate) fn is_path_start(p: &Parser) -> bool {
|
2018-01-13 04:42:19 -06:00
|
|
|
AnyOf(&[IDENT, SELF_KW, SUPER_KW, COLONCOLON]).is_ahead(p)
|
|
|
|
}
|
|
|
|
|
2018-01-09 14:32:18 -06:00
|
|
|
pub(crate) fn use_path(p: &mut Parser) {
|
2018-01-13 04:42:19 -06:00
|
|
|
if !is_path_start(p) {
|
2018-01-09 14:32:18 -06:00
|
|
|
return;
|
|
|
|
}
|
2018-01-20 14:25:34 -06:00
|
|
|
let path = p.start();
|
2018-01-20 12:49:58 -06:00
|
|
|
path_segment(p, true);
|
2018-01-20 14:25:34 -06:00
|
|
|
let mut qual = path.complete(p, PATH);
|
2018-01-20 12:49:58 -06:00
|
|
|
loop {
|
2018-01-28 05:33:10 -06:00
|
|
|
if p.at(COLONCOLON) && !items::is_use_tree_start(p.nth(1)) {
|
2018-01-20 14:25:34 -06:00
|
|
|
let path = qual.precede(p);
|
2018-01-20 12:49:58 -06:00
|
|
|
p.bump();
|
|
|
|
path_segment(p, false);
|
2018-01-20 14:25:34 -06:00
|
|
|
let path = path.complete(p, PATH);
|
|
|
|
qual = path;
|
2018-01-13 04:42:19 -06:00
|
|
|
} else {
|
2018-01-20 12:49:58 -06:00
|
|
|
break;
|
2018-01-13 04:42:19 -06:00
|
|
|
}
|
2018-01-20 12:49:58 -06:00
|
|
|
}
|
2018-01-09 14:32:18 -06:00
|
|
|
}
|
|
|
|
|
2018-01-11 13:11:44 -06:00
|
|
|
fn path_segment(p: &mut Parser, first: bool) {
|
2018-01-20 14:25:34 -06:00
|
|
|
let segment = p.start();
|
2018-01-20 12:49:58 -06:00
|
|
|
if first {
|
|
|
|
p.eat(COLONCOLON);
|
|
|
|
}
|
|
|
|
match p.current() {
|
2018-01-28 05:58:01 -06:00
|
|
|
IDENT | SELF_KW | SUPER_KW => p.bump(),
|
|
|
|
_ => p.error().message("expected identifier").emit(),
|
2018-01-20 12:49:58 -06:00
|
|
|
};
|
2018-01-20 14:25:34 -06:00
|
|
|
segment.complete(p, PATH_SEGMENT);
|
2018-01-20 12:49:58 -06:00
|
|
|
}
|