diff options
Diffstat (limited to 'src/comp/syntax')
| -rw-r--r-- | src/comp/syntax/ast.rs | 4 | ||||
| -rw-r--r-- | src/comp/syntax/fold.rs | 5 | ||||
| -rw-r--r-- | src/comp/syntax/parse/parser.rs | 10 | ||||
| -rw-r--r-- | src/comp/syntax/print/pprust.rs | 4 | ||||
| -rw-r--r-- | src/comp/syntax/visit.rs | 2 |
5 files changed, 17 insertions, 8 deletions
diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs index f064519cca3..5e6269a9a8f 100644 --- a/src/comp/syntax/ast.rs +++ b/src/comp/syntax/ast.rs @@ -149,7 +149,9 @@ type local = spanned<local_>; type decl = spanned<decl_>; -tag decl_ { decl_local([@local]); decl_item(@item); } +tag let_style { let_copy; let_ref; } + +tag decl_ { decl_local([(let_style, @local)]); decl_item(@item); } type arm = {pats: [@pat], guard: option::t<@expr>, body: blk}; diff --git a/src/comp/syntax/fold.rs b/src/comp/syntax/fold.rs index ad0edde86e6..d3702dacfc6 100644 --- a/src/comp/syntax/fold.rs +++ b/src/comp/syntax/fold.rs @@ -296,7 +296,10 @@ fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ { fn noop_fold_decl(d: decl_, fld: ast_fold) -> decl_ { ret alt d { - decl_local(ls) { decl_local(vec::map(fld.fold_local, ls)) } + decl_local(ls) { + decl_local(vec::map({|l| let (st, lc) = l; + (st, fld.fold_local(lc))}, ls)) + } decl_item(it) { decl_item(fld.fold_item(it)) } } } diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index 1ea3ddbec67..4a449c25a97 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -1505,11 +1505,13 @@ fn parse_local(p: parser, allow_init: bool) -> @ast::local { } fn parse_let(p: parser) -> @ast::decl { + fn parse_let_style(p: parser) -> ast::let_style { + eat(p, token::BINOP(token::AND)) ? ast::let_ref : ast::let_copy + } let lo = p.get_lo_pos(); - let locals = [parse_local(p, true)]; - while p.peek() == token::COMMA { - p.bump(); - locals += [parse_local(p, true)]; + let locals = [(parse_let_style(p), parse_local(p, true))]; + while eat(p, token::COMMA) { + locals += [(parse_let_style(p), parse_local(p, true))]; } ret @spanned(lo, p.get_last_hi_pos(), ast::decl_local(locals)); } diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs index c550531e386..b6964b429f5 100644 --- a/src/comp/syntax/print/pprust.rs +++ b/src/comp/syntax/print/pprust.rs @@ -1024,8 +1024,10 @@ fn print_decl(s: ps, decl: @ast::decl) { space_if_not_bol(s); ibox(s, indent_unit); word_nbsp(s, "let"); - fn print_local(s: ps, loc: @ast::local) { + fn print_local(s: ps, loc_st: (ast::let_style, @ast::local)) { + let (st, loc) = loc_st; ibox(s, indent_unit); + if st == ast::let_ref { word(s.s, "&"); } print_local_decl(s, loc); end(s); alt loc.node.init { diff --git a/src/comp/syntax/visit.rs b/src/comp/syntax/visit.rs index a50785ced24..386f5564781 100644 --- a/src/comp/syntax/visit.rs +++ b/src/comp/syntax/visit.rs @@ -212,7 +212,7 @@ fn visit_stmt<E>(s: @stmt, e: E, v: vt<E>) { fn visit_decl<E>(d: @decl, e: E, v: vt<E>) { alt d.node { decl_local(locs) { - for loc: @ast::local in locs { v.visit_local(loc, e, v); } + for (_, loc) in locs { v.visit_local(loc, e, v); } } decl_item(it) { v.visit_item(it, e, v); } } |
