diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2013-10-29 06:03:32 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2013-11-08 19:42:46 -0500 |
| commit | 1f4faaee401f8681e25afbcf3b6296b6cd2ca55a (patch) | |
| tree | f0dac4e7f58ebab635c4bba59a04fca2833db4a8 /src/libsyntax/parse | |
| parent | 85c51d3b02e421e2ab99c330e0d8212293f64f04 (diff) | |
| download | rust-1f4faaee401f8681e25afbcf3b6296b6cd2ca55a.tar.gz rust-1f4faaee401f8681e25afbcf3b6296b6cd2ca55a.zip | |
Generalize AST and ty::Generics to accept multiple lifetimes.
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 20 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 55 |
2 files changed, 25 insertions, 50 deletions
diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 6c81784b5de..672865aadcc 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -368,7 +368,7 @@ mod test { segments: ~[ ast::PathSegment { identifier: str_to_ident("a"), - lifetime: None, + lifetimes: opt_vec::Empty, types: opt_vec::Empty, } ], @@ -387,12 +387,12 @@ mod test { segments: ~[ ast::PathSegment { identifier: str_to_ident("a"), - lifetime: None, + lifetimes: opt_vec::Empty, types: opt_vec::Empty, }, ast::PathSegment { identifier: str_to_ident("b"), - lifetime: None, + lifetimes: opt_vec::Empty, types: opt_vec::Empty, } ] @@ -592,7 +592,7 @@ mod test { segments: ~[ ast::PathSegment { identifier: str_to_ident("d"), - lifetime: None, + lifetimes: opt_vec::Empty, types: opt_vec::Empty, } ], @@ -614,7 +614,7 @@ mod test { segments: ~[ ast::PathSegment { identifier: str_to_ident("b"), - lifetime: None, + lifetimes: opt_vec::Empty, types: opt_vec::Empty, } ], @@ -641,7 +641,7 @@ mod test { segments: ~[ ast::PathSegment { identifier: str_to_ident("b"), - lifetime: None, + lifetimes: opt_vec::Empty, types: opt_vec::Empty, } ], @@ -669,7 +669,7 @@ mod test { ast::PathSegment { identifier: str_to_ident("int"), - lifetime: None, + lifetimes: opt_vec::Empty, types: opt_vec::Empty, } ], @@ -687,7 +687,7 @@ mod test { ast::PathSegment { identifier: str_to_ident("b"), - lifetime: None, + lifetimes: opt_vec::Empty, types: opt_vec::Empty, } ], @@ -724,8 +724,8 @@ mod test { identifier: str_to_ident( "b"), - lifetime: - None, + lifetimes: + opt_vec::Empty, types: opt_vec::Empty } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 7c98d8d1c85..cfb4da87720 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1490,7 +1490,7 @@ impl Parser { segments.push(PathSegmentAndBoundSet { segment: ast::PathSegment { identifier: identifier, - lifetime: None, + lifetimes: opt_vec::Empty, types: opt_vec::Empty, }, bound_set: bound_set @@ -1499,46 +1499,21 @@ impl Parser { } // Parse the `<` before the lifetime and types, if applicable. - let (any_lifetime_or_types, optional_lifetime, types) = - if mode != NoTypesAllowed && self.eat(&token::LT) { - // Parse an optional lifetime. - let optional_lifetime = match *self.token { - token::LIFETIME(*) => Some(self.parse_lifetime()), - _ => None, - }; - - // Parse type parameters. - let mut types = opt_vec::Empty; - let mut need_comma = optional_lifetime.is_some(); - loop { - // We're done if we see a `>`. - match *self.token { - token::GT | token::BINOP(token::SHR) => { - self.expect_gt(); - break - } - _ => {} // Go on. - } - - if need_comma { - self.expect(&token::COMMA) - } else { - need_comma = true - } - - types.push(self.parse_ty(false)) + let (any_lifetime_or_types, lifetimes, types) = { + if mode != NoTypesAllowed && self.eat(&token::LT) { + let (lifetimes, types) = + self.parse_generic_values_after_lt(); + (true, lifetimes, opt_vec::from(types)) + } else { + (false, opt_vec::Empty, opt_vec::Empty) } - - (true, optional_lifetime, types) - } else { - (false, None, opt_vec::Empty) }; // Assemble and push the result. segments.push(PathSegmentAndBoundSet { segment: ast::PathSegment { identifier: identifier, - lifetime: optional_lifetime, + lifetimes: lifetimes, types: types, }, bound_set: bound_set @@ -1609,11 +1584,11 @@ impl Parser { pub fn parse_lifetime(&self) -> ast::Lifetime { match *self.token { token::LIFETIME(i) => { - let span = self.span; + let span = *self.span; self.bump(); return ast::Lifetime { id: ast::DUMMY_NODE_ID, - span: *span, + span: span, ident: i }; } @@ -4856,7 +4831,7 @@ impl Parser { segments: path.move_iter().map(|identifier| { ast::PathSegment { identifier: identifier, - lifetime: None, + lifetimes: opt_vec::Empty, types: opt_vec::Empty, } }).collect() @@ -4892,7 +4867,7 @@ impl Parser { segments: path.move_iter().map(|identifier| { ast::PathSegment { identifier: identifier, - lifetime: None, + lifetimes: opt_vec::Empty, types: opt_vec::Empty, } }).collect() @@ -4910,7 +4885,7 @@ impl Parser { segments: path.move_iter().map(|identifier| { ast::PathSegment { identifier: identifier, - lifetime: None, + lifetimes: opt_vec::Empty, types: opt_vec::Empty, } }).collect() @@ -4932,7 +4907,7 @@ impl Parser { segments: path.move_iter().map(|identifier| { ast::PathSegment { identifier: identifier, - lifetime: None, + lifetimes: opt_vec::Empty, types: opt_vec::Empty, } }).collect() |
