diff options
Diffstat (limited to 'src/libsyntax/parse/attr.rs')
| -rw-r--r-- | src/libsyntax/parse/attr.rs | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index 18e45a20fed..c8ebc803604 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -17,24 +17,23 @@ use parse::token::INTERPOLATED; // a parser that can parse attributes. pub trait parser_attr { - fn parse_outer_attributes(&self) -> ~[ast::Attribute]; - fn parse_attribute(&self, permit_inner: bool) -> ast::Attribute; - fn parse_inner_attrs_and_next(&self) -> - (~[ast::Attribute], ~[ast::Attribute]); - fn parse_meta_item(&self) -> @ast::MetaItem; - fn parse_meta_seq(&self) -> ~[@ast::MetaItem]; - fn parse_optional_meta(&self) -> ~[@ast::MetaItem]; + fn parse_outer_attributes(&mut self) -> ~[ast::Attribute]; + fn parse_attribute(&mut self, permit_inner: bool) -> ast::Attribute; + fn parse_inner_attrs_and_next(&mut self) + -> (~[ast::Attribute], ~[ast::Attribute]); + fn parse_meta_item(&mut self) -> @ast::MetaItem; + fn parse_meta_seq(&mut self) -> ~[@ast::MetaItem]; + fn parse_optional_meta(&mut self) -> ~[@ast::MetaItem]; } impl parser_attr for Parser { - // Parse attributes that appear before an item - fn parse_outer_attributes(&self) -> ~[ast::Attribute] { + fn parse_outer_attributes(&mut self) -> ~[ast::Attribute] { let mut attrs: ~[ast::Attribute] = ~[]; loop { debug!("parse_outer_attributes: self.token={:?}", self.token); - match *self.token { + match self.token { token::INTERPOLATED(token::nt_attr(..)) => { attrs.push(self.parse_attribute(false)); } @@ -66,10 +65,10 @@ impl parser_attr for Parser { // // if permit_inner is true, then a trailing `;` indicates an inner // attribute - fn parse_attribute(&self, permit_inner: bool) -> ast::Attribute { + fn parse_attribute(&mut self, permit_inner: bool) -> ast::Attribute { debug!("parse_attributes: permit_inner={:?} self.token={:?}", permit_inner, self.token); - let (span, value) = match *self.token { + let (span, value) = match self.token { INTERPOLATED(token::nt_attr(attr)) => { assert!(attr.node.style == ast::AttrOuter); self.bump(); @@ -85,11 +84,12 @@ impl parser_attr for Parser { (mk_sp(lo, hi), meta_item) } _ => { + let token_str = self.this_token_to_str(); self.fatal(format!("expected `\\#` but found `{}`", - self.this_token_to_str())); + token_str)); } }; - let style = if permit_inner && *self.token == token::SEMI { + let style = if permit_inner && self.token == token::SEMI { self.bump(); ast::AttrInner } else { @@ -115,12 +115,12 @@ impl parser_attr for Parser { // matches inner_attrs* outer_attr? // you can make the 'next' field an Option, but the result is going to be // more useful as a vector. - fn parse_inner_attrs_and_next(&self) + fn parse_inner_attrs_and_next(&mut self) -> (~[ast::Attribute], ~[ast::Attribute]) { let mut inner_attrs: ~[ast::Attribute] = ~[]; let mut next_outer_attrs: ~[ast::Attribute] = ~[]; loop { - let attr = match *self.token { + let attr = match self.token { token::INTERPOLATED(token::nt_attr(..)) => { self.parse_attribute(true) } @@ -154,10 +154,11 @@ impl parser_attr for Parser { // matches meta_item = IDENT // | IDENT = lit // | IDENT meta_seq - fn parse_meta_item(&self) -> @ast::MetaItem { + fn parse_meta_item(&mut self) -> @ast::MetaItem { let lo = self.span.lo; - let name = self.id_to_str(self.parse_ident()); - match *self.token { + let ident = self.parse_ident(); + let name = self.id_to_str(ident); + match self.token { token::EQ => { self.bump(); let lit = self.parse_lit(); @@ -187,15 +188,15 @@ impl parser_attr for Parser { } // matches meta_seq = ( COMMASEP(meta_item) ) - fn parse_meta_seq(&self) -> ~[@ast::MetaItem] { + fn parse_meta_seq(&mut self) -> ~[@ast::MetaItem] { self.parse_seq(&token::LPAREN, &token::RPAREN, seq_sep_trailing_disallowed(token::COMMA), |p| p.parse_meta_item()).node } - fn parse_optional_meta(&self) -> ~[@ast::MetaItem] { - match *self.token { + fn parse_optional_meta(&mut self) -> ~[@ast::MetaItem] { + match self.token { token::LPAREN => self.parse_meta_seq(), _ => ~[] } |
