Skip to content

Commit 8d239a2

Browse files
committed
libsyntax: change closures to take fn(&Parser)
1 parent 375c298 commit 8d239a2

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

src/libsyntax/parse/common.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ pub impl Parser {
250250
// before the '>'.
251251
fn parse_seq_to_before_gt<T: Copy>(
252252
sep: Option<token::Token>,
253-
f: fn(Parser) -> T
253+
f: fn(&Parser) -> T
254254
) -> ~[T] {
255255
let mut first = true;
256256
let mut v = ~[];
@@ -263,15 +263,15 @@ pub impl Parser {
263263
}
264264
_ => ()
265265
}
266-
v.push(f(self));
266+
v.push(f(&self));
267267
}
268268

269269
return v;
270270
}
271271

272272
fn parse_seq_to_gt<T: Copy>(
273273
sep: Option<token::Token>,
274-
f: fn(Parser) -> T
274+
f: fn(&Parser) -> T
275275
) -> ~[T] {
276276
let v = self.parse_seq_to_before_gt(sep, f);
277277
self.expect_gt();
@@ -282,7 +282,7 @@ pub impl Parser {
282282
// parse a sequence bracketed by '<' and '>'
283283
fn parse_seq_lt_gt<T: Copy>(
284284
sep: Option<token::Token>,
285-
f: fn(Parser) -> T
285+
f: fn(&Parser) -> T
286286
) -> spanned<~[T]> {
287287
let lo = self.span.lo;
288288
self.expect(&token::LT);
@@ -298,7 +298,7 @@ pub impl Parser {
298298
fn parse_seq_to_end<T: Copy>(
299299
ket: &token::Token,
300300
sep: SeqSep,
301-
f: fn(Parser) -> T
301+
f: fn(&Parser) -> T
302302
) -> ~[T] {
303303
let val = self.parse_seq_to_before_end(ket, sep, f);
304304
self.bump();
@@ -311,7 +311,7 @@ pub impl Parser {
311311
fn parse_seq_to_before_end<T: Copy>(
312312
ket: &token::Token,
313313
sep: SeqSep,
314-
f: fn(Parser) -> T
314+
f: fn(&Parser) -> T
315315
) -> ~[T] {
316316
let mut first: bool = true;
317317
let mut v: ~[T] = ~[];
@@ -324,7 +324,7 @@ pub impl Parser {
324324
_ => ()
325325
}
326326
if sep.trailing_sep_allowed && *self.token == *ket { break; }
327-
v.push(f(self));
327+
v.push(f(&self));
328328
}
329329
return v;
330330
}
@@ -336,7 +336,7 @@ pub impl Parser {
336336
bra: &token::Token,
337337
ket: &token::Token,
338338
sep: SeqSep,
339-
f: fn(Parser) -> T
339+
f: fn(&Parser) -> T
340340
) -> ~[T] {
341341
self.expect(bra);
342342
let result = self.parse_seq_to_before_end(ket, sep, f);
@@ -350,7 +350,7 @@ pub impl Parser {
350350
bra: &token::Token,
351351
ket: &token::Token,
352352
sep: SeqSep,
353-
f: fn(Parser) -> T
353+
f: fn(&Parser) -> T
354354
) -> spanned<~[T]> {
355355
let lo = self.span.lo;
356356
self.expect(bra);

src/libsyntax/parse/parser.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -768,15 +768,15 @@ pub impl Parser {
768768
}
769769
}
770770

771-
fn parse_capture_item_or(parse_arg_fn: fn(Parser) -> arg_or_capture_item)
771+
fn parse_capture_item_or(parse_arg_fn: fn(&Parser) -> arg_or_capture_item)
772772
-> arg_or_capture_item
773773
{
774774
if self.eat_keyword(&~"copy") {
775775
// XXX outdated syntax now that moves-based-on-type has gone in
776776
self.parse_ident();
777777
either::Right(())
778778
} else {
779-
parse_arg_fn(self)
779+
parse_arg_fn(&self)
780780
}
781781
}
782782

@@ -893,8 +893,8 @@ pub impl Parser {
893893
}
894894

895895
fn parse_path_without_tps_(
896-
parse_ident: fn(Parser) -> ident,
897-
parse_last_ident: fn(Parser) -> ident) -> @path {
896+
parse_ident: fn(&Parser) -> ident,
897+
parse_last_ident: fn(&Parser) -> ident) -> @path {
898898

899899
maybe_whole!(self, nt_path);
900900
let lo = self.span.lo;
@@ -906,10 +906,10 @@ pub impl Parser {
906906
&& self.look_ahead(1u) == token::MOD_SEP;
907907

908908
if is_not_last {
909-
ids.push(parse_ident(self));
909+
ids.push(parse_ident(&self));
910910
self.expect(&token::MOD_SEP);
911911
} else {
912-
ids.push(parse_last_ident(self));
912+
ids.push(parse_last_ident(&self));
913913
break;
914914
}
915915
}
@@ -1415,7 +1415,7 @@ pub impl Parser {
14151415
fn parse_token_tree() -> token_tree {
14161416
maybe_whole!(deref self, nt_tt);
14171417

1418-
fn parse_non_delim_tt_tok(p: Parser) -> token_tree {
1418+
fn parse_non_delim_tt_tok(p: &Parser) -> token_tree {
14191419
maybe_whole!(deref p, nt_tt);
14201420
match *p.token {
14211421
token::RPAREN | token::RBRACE | token::RBRACKET
@@ -1452,7 +1452,7 @@ pub impl Parser {
14521452
}
14531453

14541454
// turn the next token into a tt_tok:
1455-
fn parse_any_tt_tok(p: Parser) -> token_tree{
1455+
fn parse_any_tt_tok(p: &Parser) -> token_tree{
14561456
let res = tt_tok(*p.span, *p.token);
14571457
p.bump();
14581458
res
@@ -1468,20 +1468,20 @@ pub impl Parser {
14681468
tt_delim(
14691469
vec::append(
14701470
// the open delimiter:
1471-
~[parse_any_tt_tok(self)],
1471+
~[parse_any_tt_tok(&self)],
14721472
vec::append(
14731473
self.parse_seq_to_before_end(
14741474
&ket,
14751475
seq_sep_none(),
14761476
|p| p.parse_token_tree()
14771477
),
14781478
// the close delimiter:
1479-
~[parse_any_tt_tok(self)]
1479+
~[parse_any_tt_tok(&self)]
14801480
)
14811481
)
14821482
)
14831483
}
1484-
_ => parse_non_delim_tt_tok(self)
1484+
_ => parse_non_delim_tt_tok(&self)
14851485
}
14861486
}
14871487

@@ -2441,7 +2441,7 @@ pub impl Parser {
24412441
fn parse_stmt(+first_item_attrs: ~[attribute]) -> @stmt {
24422442
maybe_whole!(self, nt_stmt);
24432443

2444-
fn check_expected_item(p: Parser, current_attrs: ~[attribute]) {
2444+
fn check_expected_item(p: &Parser, current_attrs: ~[attribute]) {
24452445
// If we have attributes then we should have an item
24462446
if !current_attrs.is_empty() {
24472447
p.fatal(~"expected item after attrs");
@@ -2450,15 +2450,15 @@ pub impl Parser {
24502450

24512451
let lo = self.span.lo;
24522452
if self.is_keyword(&~"let") {
2453-
check_expected_item(self, first_item_attrs);
2453+
check_expected_item(&self, first_item_attrs);
24542454
self.expect_keyword(&~"let");
24552455
let decl = self.parse_let();
24562456
return @spanned(lo, decl.span.hi, stmt_decl(decl, self.get_id()));
24572457
} else if is_ident(&*self.token)
24582458
&& !self.is_any_keyword(&copy *self.token)
24592459
&& self.look_ahead(1) == token::NOT {
24602460

2461-
check_expected_item(self, first_item_attrs);
2461+
check_expected_item(&self, first_item_attrs);
24622462

24632463
// Potential trouble: if we allow macros with paths instead of
24642464
// idents, we'd need to look ahead past the whole path here...
@@ -2514,7 +2514,7 @@ pub impl Parser {
25142514
iovi_none() => { /* fallthrough */ }
25152515
}
25162516

2517-
check_expected_item(self, item_attrs);
2517+
check_expected_item(&self, item_attrs);
25182518

25192519
// Remainder are line-expr stmts.
25202520
let e = self.parse_expr_res(RESTRICT_STMT_EXPR);
@@ -2538,7 +2538,7 @@ pub impl Parser {
25382538

25392539
maybe_whole!(pair_empty self, nt_block);
25402540

2541-
fn maybe_parse_inner_attrs_and_next(p: Parser, parse_attrs: bool) ->
2541+
fn maybe_parse_inner_attrs_and_next(p: &Parser, parse_attrs: bool) ->
25422542
(~[attribute], ~[attribute]) {
25432543
if parse_attrs {
25442544
p.parse_inner_attrs_and_next()
@@ -2553,7 +2553,7 @@ pub impl Parser {
25532553
}
25542554
self.expect(&token::LBRACE);
25552555
let (inner, next) =
2556-
maybe_parse_inner_attrs_and_next(self, parse_attrs);
2556+
maybe_parse_inner_attrs_and_next(&self, parse_attrs);
25572557

25582558
(inner, self.parse_block_tail_(lo, default_blk, next))
25592559
}
@@ -2780,7 +2780,7 @@ pub impl Parser {
27802780
} else { ~[] }
27812781
}
27822782

2783-
fn parse_fn_decl(parse_arg_fn: fn(Parser) -> arg_or_capture_item)
2783+
fn parse_fn_decl(parse_arg_fn: fn(&Parser) -> arg_or_capture_item)
27842784
-> fn_decl
27852785
{
27862786
let args_or_capture_items: ~[arg_or_capture_item] =
@@ -2823,11 +2823,11 @@ pub impl Parser {
28232823

28242824
fn parse_fn_decl_with_self(
28252825
parse_arg_fn:
2826-
fn(Parser) -> arg_or_capture_item
2826+
fn(&Parser) -> arg_or_capture_item
28272827
) -> (self_ty, fn_decl) {
28282828
fn maybe_parse_self_ty(
28292829
cnstr: fn(+v: mutability) -> ast::self_ty_,
2830-
p: Parser
2830+
p: &Parser
28312831
) -> ast::self_ty_ {
28322832
// We need to make sure it isn't a mode or a type
28332833
if p.token_is_keyword(&~"self", &p.look_ahead(1)) ||
@@ -2851,13 +2851,13 @@ pub impl Parser {
28512851
let lo = self.span.lo;
28522852
let self_ty = match *self.token {
28532853
token::BINOP(token::AND) => {
2854-
maybe_parse_self_ty(sty_region, self)
2854+
maybe_parse_self_ty(sty_region, &self)
28552855
}
28562856
token::AT => {
2857-
maybe_parse_self_ty(sty_box, self)
2857+
maybe_parse_self_ty(sty_box, &self)
28582858
}
28592859
token::TILDE => {
2860-
maybe_parse_self_ty(sty_uniq, self)
2860+
maybe_parse_self_ty(sty_uniq, &self)
28612861
}
28622862
token::IDENT(*) if self.is_self_ident() => {
28632863
self.bump();
@@ -3028,7 +3028,7 @@ pub impl Parser {
30283028
// impl<T> ~[T] : to_str { ... }
30293029
// impl<T> to_str for ~[T] { ... }
30303030
fn parse_item_impl() -> item_info {
3031-
fn wrap_path(p: Parser, pt: @path) -> @Ty {
3031+
fn wrap_path(p: &Parser, pt: @path) -> @Ty {
30323032
@Ty {
30333033
id: p.get_id(),
30343034
node: ty_path(pt, p.get_id()),

0 commit comments

Comments
 (0)