libsyntax: change attr::parse_seq_* to take &Token

This commit is contained in:
Erick Tryzelaar 2013-02-24 18:55:24 -08:00
parent 3180d22dde
commit cf6e21a17f
4 changed files with 55 additions and 55 deletions

View File

@ -28,7 +28,7 @@ pub impl proto_parser for parser::Parser {
let proto = protocol(id, *self.span);
self.parse_seq_to_before_end(
token::EOF,
&token::EOF,
SeqSep {
sep: None,
trailing_sep_allowed: false,
@ -65,8 +65,8 @@ pub impl proto_parser for parser::Parser {
// parse the messages
self.parse_unspanned_seq(
token::LBRACE,
token::RBRACE,
&token::LBRACE,
&token::RBRACE,
SeqSep {
sep: Some(token::COMMA),
trailing_sep_allowed: true,
@ -80,8 +80,8 @@ pub impl proto_parser for parser::Parser {
let args = if *self.token == token::LPAREN {
self.parse_unspanned_seq(
token::LPAREN,
token::RPAREN,
&token::LPAREN,
&token::RPAREN,
SeqSep {
sep: Some(token::COMMA),
trailing_sep_allowed: true,
@ -98,8 +98,8 @@ pub impl proto_parser for parser::Parser {
let name = *self.interner.get(self.parse_ident());
let ntys = if *self.token == token::LT {
self.parse_unspanned_seq(
token::LT,
token::GT,
&token::LT,
&token::GT,
SeqSep {
sep: Some(token::COMMA),
trailing_sep_allowed: true,

View File

@ -152,8 +152,8 @@ impl parser_attr for Parser {
fn parse_meta_seq() -> ~[@ast::meta_item] {
self.parse_seq(
token::LPAREN,
token::RPAREN,
&token::LPAREN,
&token::RPAREN,
seq_sep_trailing_disallowed(token::COMMA),
|p| p.parse_meta_item()
).node

View File

@ -295,7 +295,7 @@ pub impl Parser {
// f must consume tokens until reaching the next separator or
// closing bracket.
fn parse_seq_to_end<T: Copy>(
ket: token::Token,
ket: &token::Token,
sep: SeqSep,
f: fn(Parser) -> T
) -> ~[T] {
@ -308,13 +308,13 @@ pub impl Parser {
// f must consume tokens until reaching the next separator or
// closing bracket.
fn parse_seq_to_before_end<T: Copy>(
ket: token::Token,
ket: &token::Token,
sep: SeqSep,
f: fn(Parser) -> T
) -> ~[T] {
let mut first: bool = true;
let mut v: ~[T] = ~[];
while *self.token != ket {
while *self.token != *ket {
match sep.sep {
Some(ref t) => {
if first { first = false; }
@ -322,22 +322,22 @@ pub impl Parser {
}
_ => ()
}
if sep.trailing_sep_allowed && *self.token == ket { break; }
if sep.trailing_sep_allowed && *self.token == *ket { break; }
v.push(f(self));
}
v
return v;
}
// parse a sequence, including the closing delimiter. The function
// f must consume tokens until reaching the next separator or
// closing bracket.
fn parse_unspanned_seq<T: Copy>(
+bra: token::Token,
+ket: token::Token,
bra: &token::Token,
ket: &token::Token,
sep: SeqSep,
f: fn(Parser) -> T
) -> ~[T] {
self.expect(&bra);
self.expect(bra);
let result = self.parse_seq_to_before_end(ket, sep, f);
self.bump();
result
@ -346,13 +346,13 @@ pub impl Parser {
// NB: Do not use this function unless you actually plan to place the
// spanned list in the AST.
fn parse_seq<T: Copy>(
+bra: token::Token,
+ket: token::Token,
bra: &token::Token,
ket: &token::Token,
sep: SeqSep,
f: fn(Parser) -> T
) -> spanned<~[T]> {
let lo = self.span.lo;
self.expect(&bra);
self.expect(bra);
let result = self.parse_seq_to_before_end(ket, sep, f);
let hi = self.span.hi;
self.bump();

View File

@ -421,8 +421,8 @@ pub impl Parser {
self.expect(&token::GT);
}
let inputs = self.parse_unspanned_seq(
token::LPAREN,
token::RPAREN,
&token::LPAREN,
&token::RPAREN,
seq_sep_trailing_disallowed(token::COMMA),
|p| p.parse_arg_general(false)
);
@ -432,8 +432,8 @@ pub impl Parser {
fn parse_trait_methods() -> ~[trait_method] {
do self.parse_unspanned_seq(
token::LBRACE,
token::RBRACE,
&token::LBRACE,
&token::RBRACE,
seq_sep_none()
) |p| {
let attrs = p.parse_outer_attributes();
@ -628,8 +628,8 @@ pub impl Parser {
ty_ptr(self.parse_mt())
} else if *self.token == token::LBRACE {
let elems = self.parse_unspanned_seq(
token::LBRACE,
token::RBRACE,
&token::LBRACE,
&token::RBRACE,
seq_sep_trailing_allowed(token::COMMA),
|p| p.parse_ty_field()
);
@ -1190,7 +1190,7 @@ pub impl Parser {
// Vector with two or more elements.
self.bump();
let remaining_exprs = self.parse_seq_to_end(
token::RBRACKET,
&token::RBRACKET,
seq_sep_trailing_allowed(token::COMMA),
|p| p.parse_expr()
);
@ -1246,8 +1246,8 @@ pub impl Parser {
let ket = token::flip_delimiter(&*self.token);
let tts = self.parse_unspanned_seq(
*self.token,
ket,
&copy *self.token,
&ket,
seq_sep_none(),
|p| p.parse_token_tree()
);
@ -1339,8 +1339,8 @@ pub impl Parser {
match *self.token {
token::LPAREN if self.permits_call() => {
let es = self.parse_unspanned_seq(
token::LPAREN,
token::RPAREN,
&token::LPAREN,
&token::RPAREN,
seq_sep_trailing_disallowed(token::COMMA),
|p| p.parse_expr()
);
@ -1363,8 +1363,8 @@ pub impl Parser {
// expr(...)
token::LPAREN if self.permits_call() => {
let es = self.parse_unspanned_seq(
token::LPAREN,
token::RPAREN,
&token::LPAREN,
&token::RPAREN,
seq_sep_trailing_disallowed(token::COMMA),
|p| p.parse_expr()
);
@ -1434,8 +1434,8 @@ pub impl Parser {
if *p.token == token::LPAREN {
let seq = p.parse_seq(
token::LPAREN,
token::RPAREN,
&token::LPAREN,
&token::RPAREN,
seq_sep_none(),
|p| p.parse_token_tree()
);
@ -1471,7 +1471,7 @@ pub impl Parser {
~[parse_any_tt_tok(self)],
vec::append(
self.parse_seq_to_before_end(
ket,
&ket,
seq_sep_none(),
|p| p.parse_token_tree()
),
@ -2320,8 +2320,8 @@ pub impl Parser {
}
_ => {
args = self.parse_unspanned_seq(
token::LPAREN,
token::RPAREN,
&token::LPAREN,
&token::RPAREN,
seq_sep_trailing_disallowed(
token::COMMA
),
@ -2470,8 +2470,8 @@ pub impl Parser {
};
let tts = self.parse_unspanned_seq(
token::LPAREN,
token::RPAREN,
&token::LPAREN,
&token::RPAREN,
seq_sep_none(),
|p| p.parse_token_tree()
);
@ -2780,8 +2780,8 @@ pub impl Parser {
{
let args_or_capture_items: ~[arg_or_capture_item] =
self.parse_unspanned_seq(
token::LPAREN,
token::RPAREN,
&token::LPAREN,
&token::RPAREN,
seq_sep_trailing_disallowed(token::COMMA),
parse_arg_fn
);
@ -2865,7 +2865,7 @@ pub impl Parser {
self.bump();
let sep = seq_sep_trailing_disallowed(token::COMMA);
args_or_capture_items = self.parse_seq_to_before_end(
token::RPAREN,
&token::RPAREN,
sep,
parse_arg_fn
);
@ -2882,7 +2882,7 @@ pub impl Parser {
} else {
let sep = seq_sep_trailing_disallowed(token::COMMA);
args_or_capture_items = self.parse_seq_to_before_end(
token::RPAREN,
&token::RPAREN,
sep,
parse_arg_fn
);
@ -2910,8 +2910,8 @@ pub impl Parser {
~[]
} else {
self.parse_unspanned_seq(
token::BINOP(token::OR),
token::BINOP(token::OR),
&token::BINOP(token::OR),
&token::BINOP(token::OR),
seq_sep_trailing_disallowed(token::COMMA),
|p| p.parse_fn_block_arg()
)
@ -3112,7 +3112,7 @@ pub impl Parser {
fn parse_trait_ref_list(ket: &token::Token) -> ~[@trait_ref] {
self.parse_seq_to_before_end(
*ket,
ket,
seq_sep_none(),
|p| p.parse_trait_ref()
)
@ -3163,8 +3163,8 @@ pub impl Parser {
// It's a tuple-like struct.
is_tuple_like = true;
fields = do self.parse_unspanned_seq(
token::LPAREN,
token::RPAREN,
&token::LPAREN,
&token::RPAREN,
seq_sep_trailing_allowed(token::COMMA)
) |p| {
let lo = p.span.lo;
@ -3729,8 +3729,8 @@ pub impl Parser {
} else if *self.token == token::LPAREN {
all_nullary = false;
let arg_tys = self.parse_unspanned_seq(
token::LPAREN,
token::RPAREN,
&token::LPAREN,
&token::RPAREN,
seq_sep_trailing_disallowed(token::COMMA),
|p| p.parse_ty(false)
);
@ -3982,8 +3982,8 @@ pub impl Parser {
token::LPAREN | token::LBRACE => {
let ket = token::flip_delimiter(&*self.token);
self.parse_unspanned_seq(
*self.token,
ket,
&copy *self.token,
&ket,
seq_sep_none(),
|p| p.parse_token_tree()
)
@ -4074,8 +4074,8 @@ pub impl Parser {
// foo::bar::{a,b,c}
token::LBRACE => {
let idents = self.parse_unspanned_seq(
token::LBRACE,
token::RBRACE,
&token::LBRACE,
&token::RBRACE,
seq_sep_trailing_allowed(token::COMMA),
|p| p.parse_path_list_ident()
);