2018-01-09 14:32:18 -06:00
|
|
|
use super::*;
|
|
|
|
|
2018-01-30 13:53:19 -06:00
|
|
|
pub(super) fn is_path_start(p: &Parser) -> bool {
|
2018-02-11 04:13:06 -06:00
|
|
|
match p.current() {
|
|
|
|
IDENT | SELF_KW | SUPER_KW | COLONCOLON => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
2018-01-13 04:42:19 -06:00
|
|
|
}
|
|
|
|
|
2018-01-30 13:53:19 -06:00
|
|
|
pub(super) fn use_path(p: &mut Parser) {
|
2018-07-30 09:02:51 -05:00
|
|
|
path(p, Mode::Use)
|
2018-01-30 13:53:19 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn type_path(p: &mut Parser) {
|
2018-07-30 09:02:51 -05:00
|
|
|
path(p, Mode::Type)
|
2018-01-30 13:53:19 -06:00
|
|
|
}
|
|
|
|
|
2018-07-30 09:02:51 -05:00
|
|
|
pub(super) fn expr_path(p: &mut Parser) {
|
|
|
|
path(p, Mode::Expr)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Eq, PartialEq)]
|
|
|
|
enum Mode { Use, Type, Expr }
|
|
|
|
|
|
|
|
fn path(p: &mut Parser, mode: Mode) {
|
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-07-30 09:02:51 -05:00
|
|
|
path_segment(p, mode, 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-02-02 13:21:06 -06:00
|
|
|
let use_tree = match p.nth(1) {
|
|
|
|
STAR | L_CURLY => true,
|
|
|
|
_ => false,
|
|
|
|
};
|
|
|
|
if p.at(COLONCOLON) && !use_tree {
|
2018-01-20 14:25:34 -06:00
|
|
|
let path = qual.precede(p);
|
2018-01-20 12:49:58 -06:00
|
|
|
p.bump();
|
2018-07-30 09:02:51 -05:00
|
|
|
path_segment(p, mode, 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-07-30 09:02:51 -05:00
|
|
|
fn path_segment(p: &mut Parser, mode: Mode, 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-07-30 09:02:51 -05:00
|
|
|
IDENT => {
|
|
|
|
name_ref(p);
|
|
|
|
path_generic_args(p, mode);
|
|
|
|
},
|
2018-02-10 05:17:38 -06:00
|
|
|
SELF_KW | SUPER_KW => p.bump(),
|
2018-02-09 13:44:50 -06:00
|
|
|
_ => {
|
|
|
|
p.error("expected identifier");
|
2018-02-09 13:55:50 -06:00
|
|
|
}
|
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
|
|
|
}
|
2018-07-30 09:02:51 -05:00
|
|
|
|
|
|
|
fn path_generic_args(p: &mut Parser, mode: Mode) {
|
|
|
|
match mode {
|
|
|
|
Mode::Use => return,
|
|
|
|
Mode::Type => type_args::list(p, false),
|
|
|
|
Mode::Expr => type_args::list(p, true),
|
|
|
|
}
|
|
|
|
}
|