2018-01-09 23:32:18 +03:00
|
|
|
use super::*;
|
|
|
|
|
2018-01-20 21:49:58 +03:00
|
|
|
pub(crate) fn is_path_start(p: &Parser) -> bool {
|
2018-01-13 13:42:19 +03:00
|
|
|
AnyOf(&[IDENT, SELF_KW, SUPER_KW, COLONCOLON]).is_ahead(p)
|
|
|
|
}
|
|
|
|
|
2018-01-09 23:32:18 +03:00
|
|
|
pub(crate) fn use_path(p: &mut Parser) {
|
2018-01-13 13:42:19 +03:00
|
|
|
if !is_path_start(p) {
|
2018-01-09 23:32:18 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-01-12 20:59:19 +03:00
|
|
|
let mut prev = p.mark();
|
2018-01-20 21:49:58 +03:00
|
|
|
p.start(PATH);
|
|
|
|
path_segment(p, true);
|
|
|
|
p.finish();
|
|
|
|
loop {
|
2018-01-12 20:59:19 +03:00
|
|
|
let curr = p.mark();
|
2018-01-20 21:49:58 +03:00
|
|
|
if p.at(COLONCOLON) && !items::is_use_tree_start(p.raw_lookahead(1)) {
|
|
|
|
p.start(PATH);
|
|
|
|
p.bump();
|
|
|
|
path_segment(p, false);
|
|
|
|
p.forward_parent(prev, curr);
|
|
|
|
prev = curr;
|
|
|
|
p.finish();
|
2018-01-13 13:42:19 +03:00
|
|
|
} else {
|
2018-01-20 21:49:58 +03:00
|
|
|
break;
|
2018-01-13 13:42:19 +03:00
|
|
|
}
|
2018-01-20 21:49:58 +03:00
|
|
|
}
|
2018-01-09 23:32:18 +03:00
|
|
|
}
|
|
|
|
|
2018-01-11 22:11:44 +03:00
|
|
|
fn path_segment(p: &mut Parser, first: bool) {
|
2018-01-20 21:49:58 +03:00
|
|
|
p.start(PATH_SEGMENT);
|
|
|
|
if first {
|
|
|
|
p.eat(COLONCOLON);
|
|
|
|
}
|
|
|
|
match p.current() {
|
|
|
|
IDENT | SELF_KW | SUPER_KW => {
|
|
|
|
p.bump();
|
2018-01-11 22:11:44 +03:00
|
|
|
}
|
2018-01-20 21:49:58 +03:00
|
|
|
_ => {
|
|
|
|
p.error()
|
|
|
|
.message("expected identifier")
|
|
|
|
.emit();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
p.finish();
|
|
|
|
}
|