Qualified paths

This commit is contained in:
Aleksey Kladov 2018-08-13 23:54:00 +03:00
parent d9e86e574a
commit 49ab441024
6 changed files with 113 additions and 20 deletions

View file

@ -38,7 +38,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMark
Some(m) => return Some(m),
None => (),
}
if paths::is_path_start(p) {
if paths::is_path_start(p) || p.at(L_ANGLE) {
return Some(path_expr(p, r));
}
let la = p.nth(1);

View file

@ -332,7 +332,7 @@ fn arg_list(p: &mut Parser) {
// let _ = format!();
// }
fn path_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker {
assert!(paths::is_path_start(p));
assert!(paths::is_path_start(p) || p.at(L_ANGLE));
let m = p.start();
paths::expr_path(p);
match p.current() {

View file

@ -27,9 +27,6 @@ enum Mode {
}
fn path(p: &mut Parser, mode: Mode) {
if !is_path_start(p) {
return;
}
let path = p.start();
path_segment(p, mode, true);
let mut qual = path.complete(p, PATH);
@ -51,21 +48,36 @@ fn path(p: &mut Parser, mode: Mode) {
}
fn path_segment(p: &mut Parser, mode: Mode, first: bool) {
let segment = p.start();
if first {
p.eat(COLONCOLON);
let m = p.start();
// test qual_paths
// type X = <A as B>::Output;
// fn foo() { <usize as Default>::default(); }
if first && p.eat(L_ANGLE) {
types::type_(p);
if p.eat(AS_KW) {
if is_path_start(p) {
types::path_type(p);
} else {
p.error("expected a trait");
}
}
p.expect(R_ANGLE);
} else {
if first {
p.eat(COLONCOLON);
}
match p.current() {
IDENT => {
name_ref(p);
path_generic_args(p, mode);
}
SELF_KW | SUPER_KW => p.bump(),
_ => {
p.err_and_bump("expected identifier");
}
};
}
match p.current() {
IDENT => {
name_ref(p);
path_generic_args(p, mode);
}
SELF_KW | SUPER_KW => p.bump(),
_ => {
p.err_and_bump("expected identifier");
}
};
segment.complete(p, PATH_SEGMENT);
m.complete(p, PATH_SEGMENT);
}
fn path_generic_args(p: &mut Parser, mode: Mode) {

View file

@ -12,6 +12,7 @@ pub(super) fn type_(p: &mut Parser) {
FOR_KW => for_type(p),
IMPL_KW => impl_trait_type(p),
DYN_KW => dyn_trait_type(p),
L_ANGLE => path_type(p),
_ if paths::is_path_start(p) => path_type(p),
_ => {
p.err_and_bump("expected type");
@ -214,7 +215,7 @@ fn dyn_trait_type(p: &mut Parser) {
// type C = self::Foo;
// type D = super::Foo;
pub(super) fn path_type(p: &mut Parser) {
assert!(paths::is_path_start(p));
assert!(paths::is_path_start(p) || p.at(L_ANGLE));
let m = p.start();
paths::type_path(p);
// test path_type_with_bounds