Skip to content

Commit ae4e09f

Browse files
committed
adding parse_path
1 parent 28b2857 commit ae4e09f

File tree

1 file changed

+34
-19
lines changed

1 file changed

+34
-19
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -900,30 +900,45 @@ pub impl Parser {
900900
codemap::spanned { node: lit, span: mk_sp(lo, self.last_span.hi) }
901901
}
902902

903-
// parse a path that doesn't have type parameters attached
904-
fn parse_path_without_tps(&self)
905-
-> @ast::Path {
906-
maybe_whole!(self, nt_path);
903+
// parse a path into a vector of idents, whether the path starts
904+
// with ::, and a span.
905+
fn parse_path(&self) -> (~[ast::ident],bool,span) {
906+
let lo = self.span.lo;
907+
let is_global = self.eat(&token::MOD_SEP);
908+
let (ids,span{lo:_,hi,expn_info}) = self.parse_path_non_global();
909+
(ids,is_global,span{lo:lo,hi:hi,expn_info:expn_info})
910+
}
911+
912+
// parse a path beginning with an identifier into a vector of idents and a span
913+
fn parse_path_non_global(&self) -> (~[ast::ident],span) {
907914
let lo = self.span.lo;
908-
let global = self.eat(&token::MOD_SEP);
909915
let mut ids = ~[];
916+
// must be at least one to begin:
917+
ids.push(self.parse_ident());
910918
loop {
911-
// if there's a ::< coming, stop processing
912-
// the path.
913-
let is_not_last =
914-
self.look_ahead(2u) != token::LT
915-
&& self.look_ahead(1u) == token::MOD_SEP;
916-
917-
if is_not_last {
918-
ids.push(self.parse_ident());
919-
self.expect(&token::MOD_SEP);
920-
} else {
921-
ids.push(self.parse_ident());
922-
break;
919+
match *self.token {
920+
token::MOD_SEP => {
921+
match self.look_ahead(1u) {
922+
token::IDENT(id,_) => {
923+
self.bump();
924+
ids.push(self.parse_ident());
925+
}
926+
_ => break
927+
}
928+
}
929+
_ => break
923930
}
924931
}
925-
@ast::Path { span: mk_sp(lo, self.last_span.hi),
926-
global: global,
932+
(ids, mk_sp(lo, self.last_span.hi))
933+
}
934+
935+
// parse a path that doesn't have type parameters attached
936+
fn parse_path_without_tps(&self)
937+
-> @ast::Path {
938+
maybe_whole!(self, nt_path);
939+
let (ids,is_global,sp) = self.parse_path();
940+
@ast::Path { span: sp,
941+
global: is_global,
927942
idents: ids,
928943
rp: None,
929944
types: ~[] }

0 commit comments

Comments
 (0)