diff options
| author | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2013-04-30 20:20:08 -0700 |
|---|---|---|
| committer | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2013-05-01 07:49:41 -0700 |
| commit | 3e3e2f00250d77719598ad052bb2016d46e6a148 (patch) | |
| tree | 54d73d9114028163156ef6947e6b95d80a91c25f /src/libsyntax/parse/parser.rs | |
| parent | c2e1f47955571fab24fc731c0af97e4c71f4ada9 (diff) | |
| download | rust-3e3e2f00250d77719598ad052bb2016d46e6a148.tar.gz rust-3e3e2f00250d77719598ad052bb2016d46e6a148.zip | |
allow parsing attributes on struct fields
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 27a1cde2f96..74af7458408 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2520,7 +2520,9 @@ pub impl Parser { } // parse a structure field - fn parse_name_and_ty(&self, pr: visibility) -> @struct_field { + fn parse_name_and_ty(&self, + pr: visibility, + attrs: ~[attribute]) -> @struct_field { let mut is_mutbl = struct_immutable; let lo = self.span.lo; if self.eat_keyword(&~"mut") { @@ -2535,7 +2537,8 @@ pub impl Parser { @spanned(lo, self.last_span.hi, ast::struct_field_ { kind: named_field(name, is_mutbl, pr), id: self.get_id(), - ty: ty + ty: ty, + attrs: attrs, }) } @@ -3318,11 +3321,13 @@ pub impl Parser { &token::RPAREN, seq_sep_trailing_allowed(token::COMMA) ) |p| { + let attrs = self.parse_outer_attributes(); let lo = p.span.lo; let struct_field_ = ast::struct_field_ { kind: unnamed_field, id: self.get_id(), - ty: p.parse_ty(false) + ty: p.parse_ty(false), + attrs: attrs, }; @spanned(lo, p.span.hi, struct_field_) }; @@ -3359,12 +3364,14 @@ pub impl Parser { } // parse a structure field declaration - fn parse_single_struct_field(&self, vis: visibility) -> @struct_field { + fn parse_single_struct_field(&self, + vis: visibility, + attrs: ~[attribute]) -> @struct_field { if self.eat_obsolete_ident("let") { self.obsolete(*self.last_span, ObsoleteLet); } - let a_var = self.parse_name_and_ty(vis); + let a_var = self.parse_name_and_ty(vis, attrs); match *self.token { token::SEMI => { self.obsolete(copy *self.span, ObsoleteFieldTerminator); @@ -3390,26 +3397,25 @@ pub impl Parser { // parse an element of a struct definition fn parse_struct_decl_field(&self) -> ~[@struct_field] { - if self.try_parse_obsolete_priv_section() { + let attrs = self.parse_outer_attributes(); + + if self.try_parse_obsolete_priv_section(attrs) { return ~[]; } - // Need this to parse comments on fields. - let _attrs = self.parse_outer_attributes(); - if self.eat_keyword(&~"priv") { - return ~[self.parse_single_struct_field(private)] + return ~[self.parse_single_struct_field(private, attrs)] } if self.eat_keyword(&~"pub") { - return ~[self.parse_single_struct_field(public)]; + return ~[self.parse_single_struct_field(public, attrs)]; } if self.try_parse_obsolete_struct_ctor() { return ~[]; } - return ~[self.parse_single_struct_field(inherited)]; + return ~[self.parse_single_struct_field(inherited, attrs)]; } // parse visiility: PUB, PRIV, or nothing |
