From 78d11b899b6ec4d2ed8c18499c1213fecd3c6424 Mon Sep 17 00:00:00 2001 From: Lindsey Kuper Date: Fri, 13 Jul 2012 15:27:21 -0700 Subject: Clean up various bugs with trait parsing. --- src/libsyntax/parse/parser.rs | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'src/libsyntax/parse/parser.rs') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 54c268722c8..5effab94397 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -279,41 +279,46 @@ class parser { do self.parse_unspanned_seq(token::LBRACE, token::RBRACE, seq_sep_none()) |p| { let attrs = p.parse_outer_attributes(); - let flo = p.span.lo; + let lo = p.span.lo; let pur = p.parse_fn_purity(); + // NB: at the moment, trait methods are public by default; this + // could change. + let vis = p.parse_visibility(public); let ident = p.parse_method_name(); let tps = p.parse_ty_params(); - let d = p.parse_ty_fn_decl(pur), fhi = p.last_span.hi; - #debug["parse_trait_methods(): trait method ends in %s", - token_to_str(self.reader, self.token)]; - alt self.token { + let d = p.parse_ty_fn_decl(pur); + let hi = p.last_span.hi; + #debug["parse_trait_methods(): trait method signature ends in \ + `%s`", + token_to_str(p.reader, p.token)]; + alt p.token { token::SEMI { - self.bump(); + p.bump(); + #debug["parse_trait_methods(): parsing required method"]; + // NB: at the moment, visibility annotations on required + // methods are ignored; this could change. required({ident: ident, attrs: attrs, decl: {purity: pur with d}, tps: tps, - span: mk_sp(flo, fhi)}) + span: mk_sp(lo, hi)}) } token::LBRACE { - self.bump(); + #debug["parse_trait_methods(): parsing provided method"]; let (inner_attrs, body) = - self.parse_inner_attrs_and_block(true); + p.parse_inner_attrs_and_block(true); let attrs = vec::append(attrs, inner_attrs); - self.eat(token::RBRACE); provided(@{ident: ident, attrs: attrs, tps: tps, decl: d, body: body, - id: self.get_id(), - span: mk_sp(flo, fhi), - self_id: self.get_id(), - // Provided traits methods always public for now - vis: public}) + id: p.get_id(), + span: mk_sp(lo, hi), + self_id: p.get_id(), + vis: vis}) } - _ { self.fatal("expected `;` or `}` \ - but found `" - + token_to_str(self.reader, self.token) + "`"); + _ { p.fatal("expected `;` or `}` but found `" + + token_to_str(p.reader, p.token) + "`"); } } } -- cgit 1.4.1-3-g733a5