From 49ab44102496ac8c4a05b00c584adecf583f4d87 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 13 Aug 2018 23:54:00 +0300 Subject: Qualified paths --- crates/libsyntax2/src/grammar/paths.rs | 44 +++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 16 deletions(-) (limited to 'crates/libsyntax2/src/grammar/paths.rs') diff --git a/crates/libsyntax2/src/grammar/paths.rs b/crates/libsyntax2/src/grammar/paths.rs index aa5ecf4b8..97ab1880b 100644 --- a/crates/libsyntax2/src/grammar/paths.rs +++ b/crates/libsyntax2/src/grammar/paths.rs @@ -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); - } - match p.current() { - IDENT => { - name_ref(p); - path_generic_args(p, mode); + let m = p.start(); + // test qual_paths + // type X = ::Output; + // fn foo() { ::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"); + } } - SELF_KW | SUPER_KW => p.bump(), - _ => { - p.err_and_bump("expected identifier"); + p.expect(R_ANGLE); + } else { + if first { + p.eat(COLONCOLON); } - }; - segment.complete(p, PATH_SEGMENT); + match p.current() { + IDENT => { + name_ref(p); + path_generic_args(p, mode); + } + SELF_KW | SUPER_KW => p.bump(), + _ => { + p.err_and_bump("expected identifier"); + } + }; + } + m.complete(p, PATH_SEGMENT); } fn path_generic_args(p: &mut Parser, mode: Mode) { -- cgit v1.2.3