libsyntax: Make the parser mutable
This commit is contained in:
@@ -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(),
|
||||
_ => ~[]
|
||||
|
||||
Reference in New Issue
Block a user