diff options
| author | John Clements <clements@racket-lang.org> | 2013-03-27 12:36:10 -0700 |
|---|---|---|
| committer | John Clements <clements@racket-lang.org> | 2013-04-28 09:49:20 -0700 |
| commit | ae4e09f71ac545dbf51778ee3ffe695de1d50f60 (patch) | |
| tree | 50dff982b12f5d61a40406650912823af3857944 /src/libsyntax | |
| parent | 28b285764cd6d9b184584756177199d0f1c32ce3 (diff) | |
| download | rust-ae4e09f71ac545dbf51778ee3ffe695de1d50f60.tar.gz rust-ae4e09f71ac545dbf51778ee3ffe695de1d50f60.zip | |
adding parse_path
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 53 |
1 files changed, 34 insertions, 19 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index c843698a1dc..3925d4aa9bf 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -900,30 +900,45 @@ pub impl Parser { codemap::spanned { node: lit, span: mk_sp(lo, self.last_span.hi) } } - // parse a path that doesn't have type parameters attached - fn parse_path_without_tps(&self) - -> @ast::Path { - maybe_whole!(self, nt_path); + // parse a path into a vector of idents, whether the path starts + // with ::, and a span. + fn parse_path(&self) -> (~[ast::ident],bool,span) { + let lo = self.span.lo; + let is_global = self.eat(&token::MOD_SEP); + let (ids,span{lo:_,hi,expn_info}) = self.parse_path_non_global(); + (ids,is_global,span{lo:lo,hi:hi,expn_info:expn_info}) + } + + // parse a path beginning with an identifier into a vector of idents and a span + fn parse_path_non_global(&self) -> (~[ast::ident],span) { let lo = self.span.lo; - let global = self.eat(&token::MOD_SEP); let mut ids = ~[]; + // must be at least one to begin: + ids.push(self.parse_ident()); loop { - // if there's a ::< coming, stop processing - // the path. - let is_not_last = - self.look_ahead(2u) != token::LT - && self.look_ahead(1u) == token::MOD_SEP; - - if is_not_last { - ids.push(self.parse_ident()); - self.expect(&token::MOD_SEP); - } else { - ids.push(self.parse_ident()); - break; + match *self.token { + token::MOD_SEP => { + match self.look_ahead(1u) { + token::IDENT(id,_) => { + self.bump(); + ids.push(self.parse_ident()); + } + _ => break + } + } + _ => break } } - @ast::Path { span: mk_sp(lo, self.last_span.hi), - global: global, + (ids, mk_sp(lo, self.last_span.hi)) + } + + // parse a path that doesn't have type parameters attached + fn parse_path_without_tps(&self) + -> @ast::Path { + maybe_whole!(self, nt_path); + let (ids,is_global,sp) = self.parse_path(); + @ast::Path { span: sp, + global: is_global, idents: ids, rp: None, types: ~[] } |
