diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2013-03-09 19:43:53 -0500 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2013-03-18 15:03:37 -0400 |
| commit | a6187c62e93ba96dce8f19849fb7016f4f941f8c (patch) | |
| tree | 64dbc33bf7e6756416d4998ffd933533496968a0 /src/libsyntax/parse/parser.rs | |
| parent | 087a015a727b11d46ff5a309ff37c7967e8636d1 (diff) | |
| download | rust-a6187c62e93ba96dce8f19849fb7016f4f941f8c.tar.gz rust-a6187c62e93ba96dce8f19849fb7016f4f941f8c.zip | |
Make &self permit explicit lifetimes, but don't really use them
(this will be needed for snapshotting at some point).
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index a30b910b347..1881a2115d7 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -975,6 +975,13 @@ pub impl Parser { } } + fn token_is_lifetime(&self, tok: &token::Token) -> bool { + match *tok { + token::LIFETIME(_) => true, + _ => false + } + } + fn parse_lifetime(&self) -> ast::Lifetime { /*! * @@ -1041,6 +1048,11 @@ pub impl Parser { } } + fn token_is_mutability(&self, tok: &token::Token) -> bool { + self.token_is_keyword(&~"mut", tok) || + self.token_is_keyword(&~"const", tok) + } + fn parse_mutability(&self) -> mutability { if self.eat_keyword(&~"mut") { m_mutbl @@ -2844,6 +2856,55 @@ pub impl Parser { } } + fn maybe_parse_borrowed_self_ty( + self: &Parser + ) -> ast::self_ty_ { + // The following things are possible to see here: + // + // fn(&self) + // fn(&mut self) + // fn(&'lt self) + // fn(&'lt mut self) + // + // We already know that the current token is `&`. + + if ( + self.token_is_keyword(&~"self", &self.look_ahead(1))) + { + self.bump(); + self.expect_self_ident(); + sty_region(None, m_imm) + } else if ( + self.token_is_mutability(&self.look_ahead(1)) && + self.token_is_keyword(&~"self", &self.look_ahead(2))) + { + self.bump(); + let mutability = self.parse_mutability(); + self.expect_self_ident(); + sty_region(None, mutability) + } else if ( + self.token_is_lifetime(&self.look_ahead(1)) && + self.token_is_keyword(&~"self", &self.look_ahead(2))) + { + self.bump(); + let lifetime = @self.parse_lifetime(); + self.expect_self_ident(); + sty_region(Some(lifetime), m_imm) + } else if ( + self.token_is_lifetime(&self.look_ahead(1)) && + self.token_is_mutability(&self.look_ahead(2)) && + self.token_is_keyword(&~"self", &self.look_ahead(3))) + { + self.bump(); + let lifetime = @self.parse_lifetime(); + let mutability = self.parse_mutability(); + self.expect_self_ident(); + sty_region(Some(lifetime), mutability) + } else { + sty_by_ref + } + } + self.expect(&token::LPAREN); // A bit of complexity and lookahead is needed here in order to to be @@ -2851,7 +2912,7 @@ pub impl Parser { let lo = self.span.lo; let self_ty = match *self.token { token::BINOP(token::AND) => { - maybe_parse_self_ty(sty_region, self) + maybe_parse_borrowed_self_ty(self) } token::AT => { maybe_parse_self_ty(sty_box, self) |
