diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2013-12-30 14:04:00 -0800 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2014-01-02 14:16:07 -0800 |
| commit | f499d365ada01a23bd046bac9b1bef7ccdb9fa8c (patch) | |
| tree | f8f22773382ac7774384f8ec58417f16e04f9041 /src/libsyntax/parse/attr.rs | |
| parent | 0df9b850ac1ed3abd0ff5abfbb716af83501dd5a (diff) | |
| download | rust-f499d365ada01a23bd046bac9b1bef7ccdb9fa8c.tar.gz rust-f499d365ada01a23bd046bac9b1bef7ccdb9fa8c.zip | |
libsyntax: Make the parser mutable
Diffstat (limited to 'src/libsyntax/parse/attr.rs')
| -rw-r--r-- | src/libsyntax/parse/attr.rs | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index 18e45a20fed..ef2322939aa 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -17,19 +17,18 @@ 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={:?}", @@ -66,7 +65,7 @@ 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 { @@ -85,8 +84,9 @@ 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 { @@ -115,7 +115,7 @@ 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] = ~[]; @@ -154,9 +154,10 @@ 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()); + let ident = self.parse_ident(); + let name = self.id_to_str(ident); match *self.token { token::EQ => { self.bump(); @@ -187,14 +188,14 @@ 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] { + fn parse_optional_meta(&mut self) -> ~[@ast::MetaItem] { match *self.token { token::LPAREN => self.parse_meta_seq(), _ => ~[] |
