auto merge of #7873 : sstewartgallus/rust/cleanup_syntax, r=alexcrichton
This commit is contained in:
commit
43b1eab23b
1 changed files with 100 additions and 100 deletions
|
@ -406,7 +406,9 @@ impl Parser {
|
||||||
// consume token 'tok' if it exists. Returns true if the given
|
// consume token 'tok' if it exists. Returns true if the given
|
||||||
// token was present, false otherwise.
|
// token was present, false otherwise.
|
||||||
pub fn eat(&self, tok: &token::Token) -> bool {
|
pub fn eat(&self, tok: &token::Token) -> bool {
|
||||||
return if *self.token == *tok { self.bump(); true } else { false };
|
let is_present = *self.token == *tok;
|
||||||
|
if is_present { self.bump() }
|
||||||
|
is_present
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_keyword(&self, kw: keywords::Keyword) -> bool {
|
pub fn is_keyword(&self, kw: keywords::Keyword) -> bool {
|
||||||
|
@ -458,21 +460,16 @@ impl Parser {
|
||||||
// with a single > and continue. If a GT is not seen,
|
// with a single > and continue. If a GT is not seen,
|
||||||
// signal an error.
|
// signal an error.
|
||||||
pub fn expect_gt(&self) {
|
pub fn expect_gt(&self) {
|
||||||
if *self.token == token::GT {
|
match *self.token {
|
||||||
self.bump();
|
token::GT => self.bump(),
|
||||||
} else if *self.token == token::BINOP(token::SHR) {
|
token::BINOP(token::SHR) => self.replace_token(
|
||||||
self.replace_token(
|
|
||||||
token::GT,
|
token::GT,
|
||||||
self.span.lo + BytePos(1u),
|
self.span.lo + BytePos(1u),
|
||||||
self.span.hi
|
self.span.hi
|
||||||
);
|
),
|
||||||
} else {
|
_ => self.fatal(fmt!("expected `%s`, found `%s`",
|
||||||
let mut s: ~str = ~"expected `";
|
self.token_to_str(&token::GT),
|
||||||
s.push_str(self.token_to_str(&token::GT));
|
self.this_token_to_str()))
|
||||||
s.push_str("`, found `");
|
|
||||||
s.push_str(self.this_token_to_str());
|
|
||||||
s.push_str("`");
|
|
||||||
self.fatal(s);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1114,19 +1111,20 @@ impl Parser {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_named_argument(&self) -> bool {
|
pub fn is_named_argument(&self) -> bool {
|
||||||
let offset = if *self.token == token::BINOP(token::AND) {
|
let offset = match *self.token {
|
||||||
1
|
token::BINOP(token::AND) => 1,
|
||||||
} else if *self.token == token::BINOP(token::MINUS) {
|
token::BINOP(token::MINUS) => 1,
|
||||||
1
|
token::ANDAND => 1,
|
||||||
} else if *self.token == token::ANDAND {
|
token::BINOP(token::PLUS) => {
|
||||||
1
|
|
||||||
} else if *self.token == token::BINOP(token::PLUS) {
|
|
||||||
if self.look_ahead(1, |t| *t == token::BINOP(token::PLUS)) {
|
if self.look_ahead(1, |t| *t == token::BINOP(token::PLUS)) {
|
||||||
2
|
2
|
||||||
} else {
|
} else {
|
||||||
1
|
1
|
||||||
}
|
}
|
||||||
} else { 0 };
|
},
|
||||||
|
_ => 0
|
||||||
|
};
|
||||||
|
|
||||||
if offset == 0 {
|
if offset == 0 {
|
||||||
is_plain_ident(&*self.token)
|
is_plain_ident(&*self.token)
|
||||||
&& self.look_ahead(1, |t| *t == token::COLON)
|
&& self.look_ahead(1, |t| *t == token::COLON)
|
||||||
|
@ -1869,21 +1867,26 @@ impl Parser {
|
||||||
// parse an optional separator followed by a kleene-style
|
// parse an optional separator followed by a kleene-style
|
||||||
// repetition token (+ or *).
|
// repetition token (+ or *).
|
||||||
pub fn parse_sep_and_zerok(&self) -> (Option<token::Token>, bool) {
|
pub fn parse_sep_and_zerok(&self) -> (Option<token::Token>, bool) {
|
||||||
if *self.token == token::BINOP(token::STAR)
|
fn parse_zerok(parser: &Parser) -> Option<bool> {
|
||||||
|| *self.token == token::BINOP(token::PLUS) {
|
match *parser.token {
|
||||||
let zerok = *self.token == token::BINOP(token::STAR);
|
token::BINOP(token::STAR) | token::BINOP(token::PLUS) => {
|
||||||
self.bump();
|
let zerok = *parser.token == token::BINOP(token::STAR);
|
||||||
(None, zerok)
|
parser.bump();
|
||||||
} else {
|
Some(zerok)
|
||||||
let sep = self.bump_and_get();
|
},
|
||||||
if *self.token == token::BINOP(token::STAR)
|
_ => None
|
||||||
|| *self.token == token::BINOP(token::PLUS) {
|
|
||||||
let zerok = *self.token == token::BINOP(token::STAR);
|
|
||||||
self.bump();
|
|
||||||
(Some(sep), zerok)
|
|
||||||
} else {
|
|
||||||
self.fatal("expected `*` or `+`");
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
match parse_zerok(self) {
|
||||||
|
Some(zerok) => return (None, zerok),
|
||||||
|
None => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
let separator = self.bump_and_get();
|
||||||
|
match parse_zerok(self) {
|
||||||
|
Some(zerok) => (Some(separator), zerok),
|
||||||
|
None => self.fatal("expected `*` or `+`")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2145,14 +2148,21 @@ impl Parser {
|
||||||
// parse an expression of binops of at least min_prec precedence
|
// parse an expression of binops of at least min_prec precedence
|
||||||
pub fn parse_more_binops(&self, lhs: @expr, min_prec: uint) -> @expr {
|
pub fn parse_more_binops(&self, lhs: @expr, min_prec: uint) -> @expr {
|
||||||
if self.expr_is_complete(lhs) { return lhs; }
|
if self.expr_is_complete(lhs) { return lhs; }
|
||||||
if token::BINOP(token::OR) == *self.token &&
|
|
||||||
(*self.restriction == RESTRICT_NO_BAR_OP ||
|
// Prevent dynamic borrow errors later on by limiting the
|
||||||
*self.restriction == RESTRICT_NO_BAR_OR_DOUBLEBAR_OP) {
|
// scope of the borrows.
|
||||||
lhs
|
{
|
||||||
} else if token::OROR == *self.token &&
|
let token: &token::Token = self.token;
|
||||||
*self.restriction == RESTRICT_NO_BAR_OR_DOUBLEBAR_OP {
|
let restriction: &restriction = self.restriction;
|
||||||
lhs
|
match (token, restriction) {
|
||||||
} else {
|
(&token::BINOP(token::OR), &RESTRICT_NO_BAR_OP) => return lhs,
|
||||||
|
(&token::BINOP(token::OR),
|
||||||
|
&RESTRICT_NO_BAR_OR_DOUBLEBAR_OP) => return lhs,
|
||||||
|
(&token::OROR, &RESTRICT_NO_BAR_OR_DOUBLEBAR_OP) => return lhs,
|
||||||
|
_ => { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let cur_opt = token_to_binop(self.token);
|
let cur_opt = token_to_binop(self.token);
|
||||||
match cur_opt {
|
match cur_opt {
|
||||||
Some(cur_op) => {
|
Some(cur_op) => {
|
||||||
|
@ -2181,7 +2191,6 @@ impl Parser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// parse an assignment expression....
|
// parse an assignment expression....
|
||||||
// actually, this seems to be the main entry point for
|
// actually, this seems to be the main entry point for
|
||||||
|
@ -2198,19 +2207,18 @@ impl Parser {
|
||||||
token::BINOPEQ(op) => {
|
token::BINOPEQ(op) => {
|
||||||
self.bump();
|
self.bump();
|
||||||
let rhs = self.parse_expr();
|
let rhs = self.parse_expr();
|
||||||
let aop;
|
let aop = match op {
|
||||||
match op {
|
token::PLUS => add,
|
||||||
token::PLUS => aop = add,
|
token::MINUS => subtract,
|
||||||
token::MINUS => aop = subtract,
|
token::STAR => mul,
|
||||||
token::STAR => aop = mul,
|
token::SLASH => div,
|
||||||
token::SLASH => aop = div,
|
token::PERCENT => rem,
|
||||||
token::PERCENT => aop = rem,
|
token::CARET => bitxor,
|
||||||
token::CARET => aop = bitxor,
|
token::AND => bitand,
|
||||||
token::AND => aop = bitand,
|
token::OR => bitor,
|
||||||
token::OR => aop = bitor,
|
token::SHL => shl,
|
||||||
token::SHL => aop = shl,
|
token::SHR => shr
|
||||||
token::SHR => aop = shr
|
};
|
||||||
}
|
|
||||||
self.mk_expr(lo, rhs.span.hi,
|
self.mk_expr(lo, rhs.span.hi,
|
||||||
self.mk_assign_op(aop, lhs, rhs))
|
self.mk_assign_op(aop, lhs, rhs))
|
||||||
}
|
}
|
||||||
|
@ -2759,6 +2767,7 @@ impl Parser {
|
||||||
self.bump();
|
self.bump();
|
||||||
let (before, slice, after) =
|
let (before, slice, after) =
|
||||||
self.parse_pat_vec_elements();
|
self.parse_pat_vec_elements();
|
||||||
|
|
||||||
self.expect(&token::RBRACKET);
|
self.expect(&token::RBRACKET);
|
||||||
pat = ast::pat_vec(before, slice, after);
|
pat = ast::pat_vec(before, slice, after);
|
||||||
hi = self.last_span.hi;
|
hi = self.last_span.hi;
|
||||||
|
@ -3347,9 +3356,7 @@ impl Parser {
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse a generic use site
|
// parse a generic use site
|
||||||
fn parse_generic_values(
|
fn parse_generic_values(&self) -> (OptVec<ast::Lifetime>, ~[Ty]) {
|
||||||
&self) -> (OptVec<ast::Lifetime>, ~[Ty])
|
|
||||||
{
|
|
||||||
if !self.eat(&token::LT) {
|
if !self.eat(&token::LT) {
|
||||||
(opt_vec::Empty, ~[])
|
(opt_vec::Empty, ~[])
|
||||||
} else {
|
} else {
|
||||||
|
@ -3357,9 +3364,7 @@ impl Parser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_generic_values_after_lt(
|
fn parse_generic_values_after_lt(&self) -> (OptVec<ast::Lifetime>, ~[Ty]) {
|
||||||
&self) -> (OptVec<ast::Lifetime>, ~[Ty])
|
|
||||||
{
|
|
||||||
let lifetimes = self.parse_lifetimes();
|
let lifetimes = self.parse_lifetimes();
|
||||||
let result = self.parse_seq_to_gt(
|
let result = self.parse_seq_to_gt(
|
||||||
Some(token::COMMA),
|
Some(token::COMMA),
|
||||||
|
@ -3388,11 +3393,7 @@ impl Parser {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_self_ident(&self) -> bool {
|
fn is_self_ident(&self) -> bool {
|
||||||
match *self.token {
|
*self.token == token::IDENT(special_idents::self_, false)
|
||||||
token::IDENT(id, false) if id == special_idents::self_
|
|
||||||
=> true,
|
|
||||||
_ => false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expect_self_ident(&self) {
|
fn expect_self_ident(&self) {
|
||||||
|
@ -4660,14 +4661,12 @@ impl Parser {
|
||||||
|
|
||||||
pub fn parse_item(&self, attrs: ~[Attribute]) -> Option<@ast::item> {
|
pub fn parse_item(&self, attrs: ~[Attribute]) -> Option<@ast::item> {
|
||||||
match self.parse_item_or_view_item(attrs, true) {
|
match self.parse_item_or_view_item(attrs, true) {
|
||||||
iovi_none(_) =>
|
iovi_none(_) => None,
|
||||||
None,
|
|
||||||
iovi_view_item(_) =>
|
iovi_view_item(_) =>
|
||||||
self.fatal("view items are not allowed here"),
|
self.fatal("view items are not allowed here"),
|
||||||
iovi_foreign_item(_) =>
|
iovi_foreign_item(_) =>
|
||||||
self.fatal("foreign items are not allowed here"),
|
self.fatal("foreign items are not allowed here"),
|
||||||
iovi_item(item) =>
|
iovi_item(item) => Some(item)
|
||||||
Some(item)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4830,6 +4829,7 @@ impl Parser {
|
||||||
// First, parse view items.
|
// First, parse view items.
|
||||||
let mut view_items : ~[ast::view_item] = ~[];
|
let mut view_items : ~[ast::view_item] = ~[];
|
||||||
let mut items = ~[];
|
let mut items = ~[];
|
||||||
|
|
||||||
// I think this code would probably read better as a single
|
// I think this code would probably read better as a single
|
||||||
// loop with a mutable three-state-variable (for extern mods,
|
// loop with a mutable three-state-variable (for extern mods,
|
||||||
// view items, and regular items) ... except that because
|
// view items, and regular items) ... except that because
|
||||||
|
|
Loading…
Reference in a new issue