diff options
| author | Brian Anderson <banderson@mozilla.com> | 2011-08-19 15:16:48 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2011-08-20 11:04:00 -0700 |
| commit | 518dc52f85c2efb67aaa1208c02e9a7e0bdaca49 (patch) | |
| tree | 9af4f631455ff5ba42b233819fe4bb9f3b9ac194 /src/comp/syntax/ext | |
| parent | 4aa165553bfb2a74e2e54f08fd9507e23bc24708 (diff) | |
Reformat
This changes the indexing syntax from .() to [], the vector syntax from ~[] to [] and the extension syntax from #fmt() to #fmt[]
Diffstat (limited to 'src/comp/syntax/ext')
| -rw-r--r-- | src/comp/syntax/ext/base.rs | 33 | ||||
| -rw-r--r-- | src/comp/syntax/ext/concat_idents.rs | 17 | ||||
| -rw-r--r-- | src/comp/syntax/ext/env.rs | 13 | ||||
| -rw-r--r-- | src/comp/syntax/ext/expand.rs | 9 | ||||
| -rw-r--r-- | src/comp/syntax/ext/fmt.rs | 57 | ||||
| -rw-r--r-- | src/comp/syntax/ext/ident_to_str.rs | 13 | ||||
| -rw-r--r-- | src/comp/syntax/ext/log_syntax.rs | 2 | ||||
| -rw-r--r-- | src/comp/syntax/ext/simplext.rs | 137 |
8 files changed, 146 insertions, 135 deletions
diff --git a/src/comp/syntax/ext/base.rs b/src/comp/syntax/ext/base.rs index 9c0ea438678..6d1bd6626c2 100644 --- a/src/comp/syntax/ext/base.rs +++ b/src/comp/syntax/ext/base.rs @@ -7,10 +7,10 @@ import std::map::new_str_hash; import codemap; type syntax_expander = - fn(&ext_ctxt, span, @ast::expr, option::t<str>) -> @ast::expr ; + fn(&ext_ctxt, span, @ast::expr, option::t<str>) -> @ast::expr; type macro_def = {ident: str, ext: syntax_extension}; type macro_definer = - fn(&ext_ctxt, span, @ast::expr, option::t<str>) -> macro_def ; + fn(&ext_ctxt, span, @ast::expr, option::t<str>) -> macro_def; tag syntax_extension { normal(syntax_expander); @@ -34,20 +34,22 @@ fn syntax_expander_table() -> hashmap<str, syntax_extension> { ret syntax_expanders; } -obj ext_ctxt(sess: @session, crate_file_name_hack: str, +obj ext_ctxt(sess: @session, + crate_file_name_hack: str, mutable backtrace: codemap::opt_span) { fn crate_file_name() -> str { ret crate_file_name_hack; } fn session() -> @session { ret sess; } - fn print_backtrace() { - } + fn print_backtrace() { } fn backtrace() -> codemap::opt_span { ret backtrace; } fn bt_push(sp: span) { - backtrace = codemap::os_some(@{lo: sp.lo, hi: sp.hi, - expanded_from: backtrace}); + backtrace = + codemap::os_some(@{lo: sp.lo, + hi: sp.hi, + expanded_from: backtrace}); } fn bt_pop() { alt backtrace { @@ -67,21 +69,16 @@ obj ext_ctxt(sess: @session, crate_file_name_hack: str, self.print_backtrace(); sess.span_err(sp, msg); } - fn span_unimpl(sp:span, msg: str) -> ! { + fn span_unimpl(sp: span, msg: str) -> ! { self.print_backtrace(); sess.span_unimpl(sp, msg); } - fn span_bug(sp:span, msg: str) -> ! { + fn span_bug(sp: span, msg: str) -> ! { self.print_backtrace(); sess.span_bug(sp, msg); } - fn bug(msg: str) -> ! { - self.print_backtrace(); - sess.bug(msg); - } - fn next_id() -> ast::node_id { - ret sess.next_node_id(); - } + fn bug(msg: str) -> ! { self.print_backtrace(); sess.bug(msg); } + fn next_id() -> ast::node_id { ret sess.next_node_id(); } } @@ -93,7 +90,7 @@ fn mk_ctxt(sess: &session) -> ext_ctxt { // the extensions the file name of the crate being compiled so they can // use it to guess whether paths should be prepended with "std::". This is // super-ugly and needs a better solution. - let crate_file_name_hack = sess.get_codemap().files.(0).name; + let crate_file_name_hack = sess.get_codemap().files[0].name; ret ext_ctxt(@sess, crate_file_name_hack, codemap::os_none); } @@ -115,7 +112,7 @@ fn expr_to_ident(cx: &ext_ctxt, expr: @ast::expr, error: str) -> ast::ident { ast::expr_path(p) { if vec::len(p.node.types) > 0u || vec::len(p.node.idents) != 1u { cx.span_fatal(expr.span, error); - } else { ret p.node.idents.(0); } + } else { ret p.node.idents[0]; } } _ { cx.span_fatal(expr.span, error); } } diff --git a/src/comp/syntax/ext/concat_idents.rs b/src/comp/syntax/ext/concat_idents.rs index 13f87e044c4..466f55e60e6 100644 --- a/src/comp/syntax/ext/concat_idents.rs +++ b/src/comp/syntax/ext/concat_idents.rs @@ -4,18 +4,21 @@ import syntax::ast; fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr, _body: option::t<str>) -> @ast::expr { - let args: [@ast::expr] = alt arg.node { - ast::expr_vec(elts, _) { elts } - _ { cx.span_fatal(sp, "#concat_idents requires a vector argument .") } - }; + let args: [@ast::expr] = + alt arg.node { + ast::expr_vec(elts, _) { elts } + _ { + cx.span_fatal(sp, "#concat_idents requires a vector argument .") + } + }; let res: ast::ident = ""; for e: @ast::expr in args { res += expr_to_ident(cx, e, "expected an ident"); } ret @{id: cx.next_id(), - node: ast::expr_path( { - node: {global: false, idents: ~[res], types: ~[]}, - span: sp}), + node: + ast::expr_path({node: {global: false, idents: [res], types: []}, + span: sp}), span: sp}; } diff --git a/src/comp/syntax/ext/env.rs b/src/comp/syntax/ext/env.rs index 50c5bda5858..52a738ab97f 100644 --- a/src/comp/syntax/ext/env.rs +++ b/src/comp/syntax/ext/env.rs @@ -12,17 +12,20 @@ export expand_syntax_ext; fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr, _body: option::t<str>) -> @ast::expr { - let args: [@ast::expr] = alt arg.node { - ast::expr_vec(elts, _) { elts } - _ { cx.span_fatal(sp, "#env requires arguments of the form `[...]`.") } - }; + let args: [@ast::expr] = + alt arg.node { + ast::expr_vec(elts, _) { elts } + _ { + cx.span_fatal(sp, "#env requires arguments of the form `[...]`.") + } + }; if vec::len::<@ast::expr>(args) != 1u { cx.span_fatal(sp, "malformed #env call"); } // FIXME: if this was more thorough it would manufacture an // option::t<str> rather than just an maybe-empty string. - let var = expr_to_str(cx, args.(0), "#env requires a string"); + let var = expr_to_str(cx, args[0], "#env requires a string"); alt generic_os::getenv(var) { option::none. { ret make_new_str(cx, sp, ""); } option::some(s) { ret make_new_str(cx, sp, s); } diff --git a/src/comp/syntax/ext/expand.rs b/src/comp/syntax/ext/expand.rs index 044bee4ba2b..149216aa6cd 100644 --- a/src/comp/syntax/ext/expand.rs +++ b/src/comp/syntax/ext/expand.rs @@ -15,14 +15,14 @@ import syntax::ext::base::*; fn expand_expr(exts: &hashmap<str, syntax_extension>, cx: &ext_ctxt, - e: &expr_, fld: ast_fold, - orig: &fn(&expr_, ast_fold) -> expr_ ) -> expr_ { + e: &expr_, fld: ast_fold, orig: &fn(&expr_, ast_fold) -> expr_) + -> expr_ { ret alt e { expr_mac(mac) { alt mac.node { mac_invoc(pth, args, body) { assert (vec::len(pth.node.idents) > 0u); - let extname = pth.node.idents.(0); + let extname = pth.node.idents[0]; alt exts.find(extname) { none. { cx.span_fatal(pth.span, @@ -41,7 +41,7 @@ fn expand_expr(exts: &hashmap<str, syntax_extension>, cx: &ext_ctxt, some(macro_defining(ext)) { let named_extension = ext(cx, pth.span, args, body); exts.insert(named_extension.ident, named_extension.ext); - ast::expr_rec(~[], none) + ast::expr_rec([], none) } } } @@ -65,7 +65,6 @@ fn expand_crate(sess: &session::session, c: &@crate) -> @crate { ret res; } - // Local Variables: // mode: rust // fill-column: 78; diff --git a/src/comp/syntax/ext/fmt.rs b/src/comp/syntax/ext/fmt.rs index 738b65c7d91..9b8a1b61684 100644 --- a/src/comp/syntax/ext/fmt.rs +++ b/src/comp/syntax/ext/fmt.rs @@ -17,17 +17,20 @@ export expand_syntax_ext; fn expand_syntax_ext(cx: &ext_ctxt, sp: span, arg: @ast::expr, _body: option::t<str>) -> @ast::expr { - let args: [@ast::expr] = alt arg.node { - ast::expr_vec(elts, _) { elts } - _ { cx.span_fatal(sp, "#fmt requires arguments of the form `[...]`.") } - }; + let args: [@ast::expr] = + alt arg.node { + ast::expr_vec(elts, _) { elts } + _ { + cx.span_fatal(sp, "#fmt requires arguments of the form `[...]`.") + } + }; if vec::len::<@ast::expr>(args) == 0u { cx.span_fatal(sp, "#fmt requires a format string"); } let fmt = - expr_to_str(cx, args.(0), + expr_to_str(cx, args[0], "first argument to #fmt must be a " + "string literal."); - let fmtspan = args.(0).span; + let fmtspan = args[0].span; log "Format string:"; log fmt; fn parse_fmt_err_(cx: &ext_ctxt, sp: span, msg: str) -> ! { @@ -66,7 +69,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], } fn make_path_expr(cx: &ext_ctxt, sp: span, idents: &[ast::ident]) -> @ast::expr { - let path = {global: false, idents: idents, types: ~[]}; + let path = {global: false, idents: idents, types: []}; let sp_path = {node: path, span: sp}; let pathexpr = ast::expr_path(sp_path); ret @{id: cx.next_id(), node: pathexpr, span: sp}; @@ -85,13 +88,13 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], fn make_rec_expr(cx: &ext_ctxt, sp: span, fields: &[{ident: ast::ident, ex: @ast::expr}]) -> @ast::expr { - let astfields: [ast::field] = ~[]; + let astfields: [ast::field] = []; for field: {ident: ast::ident, ex: @ast::expr} in fields { let ident = field.ident; let val = field.ex; let astfield = {node: {mut: ast::imm, ident: ident, expr: val}, span: sp}; - astfields += ~[astfield]; + astfields += [astfield]; } let recexpr = ast::expr_rec(astfields, option::none::<@ast::expr>); ret @{id: cx.next_id(), node: recexpr, span: sp}; @@ -101,8 +104,8 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], ret str::find(cx.crate_file_name(), "std.rc") >= 0; } if compiling_std(cx) { - ret ~["extfmt", "rt", ident]; - } else { ret ~["std", "extfmt", "rt", ident]; } + ret ["extfmt", "rt", ident]; + } else { ret ["std", "extfmt", "rt", ident]; } } fn make_rt_path_expr(cx: &ext_ctxt, sp: span, ident: str) -> @ast::expr { let path = make_path_vec(cx, ident); @@ -112,9 +115,8 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], // which tells the RT::conv* functions how to perform the conversion fn make_rt_conv_expr(cx: &ext_ctxt, sp: span, cnv: &conv) -> @ast::expr { - fn make_flags(cx: &ext_ctxt, sp: span, flags: &[flag]) -> - @ast::expr { - let flagexprs: [@ast::expr] = ~[]; + fn make_flags(cx: &ext_ctxt, sp: span, flags: &[flag]) -> @ast::expr { + let flagexprs: [@ast::expr] = []; for f: flag in flags { let fstr; alt f { @@ -124,14 +126,14 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], flag_sign_always. { fstr = "flag_sign_always"; } flag_alternate. { fstr = "flag_alternate"; } } - flagexprs += ~[make_rt_path_expr(cx, sp, fstr)]; + flagexprs += [make_rt_path_expr(cx, sp, fstr)]; } // FIXME: 0-length vectors can't have their type inferred // through the rec that these flags are a member of, so // this is a hack placeholder flag if vec::len::<@ast::expr>(flagexprs) == 0u { - flagexprs += ~[make_rt_path_expr(cx, sp, "flag_none")]; + flagexprs += [make_rt_path_expr(cx, sp, "flag_none")]; } ret make_vec_expr(cx, sp, flagexprs); } @@ -143,7 +145,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], count_is(c) { let count_lit = make_new_int(cx, sp, c); let count_is_path = make_path_vec(cx, "count_is"); - let count_is_args = ~[count_lit]; + let count_is_args = [count_lit]; ret make_call(cx, sp, count_is_path, count_is_args); } _ { cx.span_unimpl(sp, "unimplemented #fmt conversion"); } @@ -168,10 +170,10 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], width_expr: @ast::expr, precision_expr: @ast::expr, ty_expr: @ast::expr) -> @ast::expr { ret make_rec_expr(cx, sp, - ~[{ident: "flags", ex: flags_expr}, - {ident: "width", ex: width_expr}, - {ident: "precision", ex: precision_expr}, - {ident: "ty", ex: ty_expr}]); + [{ident: "flags", ex: flags_expr}, + {ident: "width", ex: width_expr}, + {ident: "precision", ex: precision_expr}, + {ident: "ty", ex: ty_expr}]); } let rt_conv_flags = make_flags(cx, sp, cnv.flags); let rt_conv_width = make_count(cx, sp, cnv.width); @@ -185,7 +187,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], let fname = "conv_" + conv_type; let path = make_path_vec(cx, fname); let cnv_expr = make_rt_conv_expr(cx, sp, cnv); - let args = ~[cnv_expr, arg]; + let args = [cnv_expr, arg]; ret make_call(cx, arg.span, path, args); } fn make_new_conv(cx: &ext_ctxt, sp: span, cnv: conv, arg: @ast::expr) -> @@ -304,7 +306,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], ty_octal. { log "type: octal"; } } } - let fmt_sp = args.(0).span; + let fmt_sp = args[0].span; let n = 0u; let tmp_expr = make_new_str(cx, sp, ""); let nargs = vec::len::<@ast::expr>(args); @@ -323,7 +325,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], } log "Building conversion:"; log_conv(conv); - let arg_expr = args.(n); + let arg_expr = args[n]; let c_expr = make_new_conv(cx, fmt_sp, conv, arg_expr); tmp_expr = make_add_expr(cx, fmt_sp, tmp_expr, c_expr); } @@ -332,9 +334,10 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], let expected_nargs = n + 1u; // n conversions + the fmt string if expected_nargs < nargs { - cx.span_fatal - (sp, #fmt("too many arguments to #fmt. found %u, expected %u", - nargs, expected_nargs)); + cx.span_fatal( + sp, + #fmt["too many arguments to #fmt. found %u, expected %u", + nargs, expected_nargs]); } ret tmp_expr; } diff --git a/src/comp/syntax/ext/ident_to_str.rs b/src/comp/syntax/ext/ident_to_str.rs index ce24e2605e4..4eb381762fe 100644 --- a/src/comp/syntax/ext/ident_to_str.rs +++ b/src/comp/syntax/ext/ident_to_str.rs @@ -5,16 +5,19 @@ import syntax::ast; fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr, _body: option::t<str>) -> @ast::expr { - let args: [@ast::expr] = alt arg.node { - ast::expr_vec(elts, _) { elts } - _ { cx.span_fatal(sp, "#ident_to_str requires a vector argument .") } - }; + let args: [@ast::expr] = + alt arg.node { + ast::expr_vec(elts, _) { elts } + _ { + cx.span_fatal(sp, "#ident_to_str requires a vector argument .") + } + }; if vec::len::<@ast::expr>(args) != 1u { cx.span_fatal(sp, "malformed #ident_to_str call"); } ret make_new_lit(cx, sp, - ast::lit_str(expr_to_ident(cx, args.(0u), + ast::lit_str(expr_to_ident(cx, args[0u], "expected an ident"), ast::sk_rc)); diff --git a/src/comp/syntax/ext/log_syntax.rs b/src/comp/syntax/ext/log_syntax.rs index f0834f4f079..a03ff11a66d 100644 --- a/src/comp/syntax/ext/log_syntax.rs +++ b/src/comp/syntax/ext/log_syntax.rs @@ -9,5 +9,5 @@ fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr, std::io::stdout().write_line(print::pprust::expr_to_str(arg)); //trivial expression - ret @{id: cx.next_id(), node: ast::expr_rec(~[], option::none), span: sp}; + ret @{id: cx.next_id(), node: ast::expr_rec([], option::none), span: sp}; } diff --git a/src/comp/syntax/ext/simplext.rs b/src/comp/syntax/ext/simplext.rs index 9b8a5e28e09..e5dd343203a 100644 --- a/src/comp/syntax/ext/simplext.rs +++ b/src/comp/syntax/ext/simplext.rs @@ -34,7 +34,7 @@ export add_new_extension; fn path_to_ident(pth: &path) -> option::t<ident> { if vec::len(pth.node.idents) == 1u && vec::len(pth.node.types) == 0u { - ret some(pth.node.idents.(0u)); + ret some(pth.node.idents[0u]); } ret none; } @@ -89,10 +89,10 @@ fn match_error(cx: &ext_ctxt, m: &matchable, expected: &str) -> ! { // we'll want to return something indicating amount of progress and location // of failure instead of `none`. type match_result = option::t<arb_depth<matchable>>; -type selector = fn(&matchable) -> match_result ; +type selector = fn(&matchable) -> match_result; -fn elts_to_ell(cx: &ext_ctxt, elts: &[@expr]) - -> {pre: [@expr], rep: option::t<@expr>, post: [@expr]} { +fn elts_to_ell(cx: &ext_ctxt, elts: &[@expr]) -> + {pre: [@expr], rep: option::t<@expr>, post: [@expr]} { let idx: uint = 0u; let res = none; for elt: @expr in elts { @@ -103,10 +103,10 @@ fn elts_to_ell(cx: &ext_ctxt, elts: &[@expr]) if res != none { cx.span_fatal(m.span, "only one ellipsis allowed"); } - res = some({pre: vec::slice(elts, 0u, idx - 1u), - rep: some(elts.(idx - 1u)), - post: vec::slice(elts, idx + 1u, - vec::len(elts))}); + res = + some({pre: vec::slice(elts, 0u, idx - 1u), + rep: some(elts[idx - 1u]), + post: vec::slice(elts, idx + 1u, vec::len(elts))}); } _ { } } @@ -116,16 +116,16 @@ fn elts_to_ell(cx: &ext_ctxt, elts: &[@expr]) idx += 1u; } ret alt res { - some(val) { val } - none. { {pre: elts, rep: none, post: ~[]} } - } + some(val) { val } + none. { {pre: elts, rep: none, post: []} } + } } fn option_flatten_map<T, U>(f: &fn(&T) -> option::t<U>, v: &[T]) -> option::t<[U]> { - let res = ~[]; + let res = []; for elem: T in v { - alt f(elem) { none. { ret none; } some(fv) { res += ~[fv]; } } + alt f(elem) { none. { ret none; } some(fv) { res += [fv]; } } } ret some(res); } @@ -168,7 +168,7 @@ fn acumm_bindings(_cx: &ext_ctxt, _b_dest: &bindings, _b_src: &bindings) { } fn pattern_to_selectors(cx: &ext_ctxt, e: @expr) -> binders { let res: binders = {real_binders: new_str_hash::<selector>(), - mutable literal_ast_matchers: ~[]}; + mutable literal_ast_matchers: []}; //this oughta return binders instead, but macro args are a sequence of //expressions, rather than a single expression fn trivial_selector(m: &matchable) -> match_result { ret some(leaf(m)); } @@ -203,7 +203,7 @@ fn use_selectors_to_bind(b: &binders, e: @expr) -> option::t<bindings> { /* use the bindings on the body to generate the expanded code */ fn transcribe(cx: &ext_ctxt, b: &bindings, body: @expr) -> @expr { - let idx_path: @mutable [uint] = @mutable ~[]; + let idx_path: @mutable [uint] = @mutable []; fn new_id(_old: node_id, cx: &ext_ctxt) -> node_id { ret cx.next_id(); } fn new_span(cx: &ext_ctxt, sp: &span) -> span { /* this discards information in the case of macro-defining macros */ @@ -236,7 +236,7 @@ fn follow(m: &arb_depth<matchable>, idx_path: @mutable [uint]) -> for idx: uint in *idx_path { alt res { leaf(_) { ret res;/* end of the line */ } - seq(new_ms, _) { res = new_ms.(idx); } + seq(new_ms, _) { res = new_ms[idx]; } } } ret res; @@ -282,13 +282,12 @@ iter free_vars(b: &bindings, e: @expr) -> ident { /* handle sequences (anywhere in the AST) of exprs, either real or ...ed */ fn transcribe_exprs(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], - recur: fn(&@expr) -> @expr , exprs: [@expr]) - -> [@expr] { + recur: fn(&@expr) -> @expr, exprs: [@expr]) -> [@expr] { alt elts_to_ell(cx, exprs) { {pre: pre, rep: repeat_me_maybe, post: post} { let res = vec::map(recur, pre); alt repeat_me_maybe { - none. {} + none. { } some(repeat_me) { let repeat: option::t<{rep_count: uint, name: ident}> = none; /* we need to walk over all the free vars in lockstep, except for @@ -305,9 +304,10 @@ fn transcribe_exprs(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], some({rep_count: old_len, name: old_name}) { let len = vec::len(*ms); if old_len != len { - let msg = #fmt("'%s' occurs %u times, but ", fv, - len) + #fmt("'%s' occurs %u times", - old_name, old_len); + let msg = + #fmt["'%s' occurs %u times, but ", fv, len] + + #fmt["'%s' occurs %u times", old_name, + old_len]; cx.span_fatal(repeat_me.span, msg); } } @@ -319,14 +319,14 @@ fn transcribe_exprs(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], none. { cx.span_fatal(repeat_me.span, "'...' surrounds an expression without any" + - " repeating syntax variables"); + " repeating syntax variables"); } some({rep_count: rc, _}) { /* Whew, we now know how how many times to repeat */ let idx: uint = 0u; while idx < rc { - *idx_path += ~[idx]; - res += ~[recur(repeat_me)]; // whew! + *idx_path += [idx]; + res += [recur(repeat_me)]; // whew! vec::pop(*idx_path); idx += 1u; } @@ -357,9 +357,9 @@ fn transcribe_path(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], p: &path_, _fld: ast_fold) -> path_ { // Don't substitute into qualified names. if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { ret p; } - ret alt follow_for_trans(cx, b.find(p.idents.(0)), idx_path) { + ret alt follow_for_trans(cx, b.find(p.idents[0]), idx_path) { some(match_ident(id)) { - {global: false, idents: ~[id.node], types: ~[]} + {global: false, idents: [id.node], types: []} } some(match_path(a_pth)) { a_pth.node } some(m) { match_error(cx, m, "a path") } @@ -370,21 +370,20 @@ fn transcribe_path(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], fn transcribe_expr(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], e: &ast::expr_, fld: ast_fold, - orig: fn(&ast::expr_, ast_fold) -> ast::expr_ ) -> + orig: fn(&ast::expr_, ast_fold) -> ast::expr_) -> ast::expr_ { ret alt e { expr_path(p) { // Don't substitute into qualified names. - if vec::len(p.node.types) > 0u || vec::len(p.node.idents) != 1u - { + if vec::len(p.node.types) > 0u || vec::len(p.node.idents) != 1u { e } - alt follow_for_trans(cx, b.find(p.node.idents.(0)), idx_path) { + alt follow_for_trans(cx, b.find(p.node.idents[0]), idx_path) { some(match_ident(id)) { expr_path(respan(id.span, {global: false, - idents: ~[id.node], - types: ~[]})) + idents: [id.node], + types: []})) } some(match_path(a_pth)) { expr_path(a_pth) } some(match_expr(a_exp)) { a_exp.node } @@ -398,7 +397,7 @@ fn transcribe_expr(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], fn transcribe_type(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], t: &ast::ty_, fld: ast_fold, - orig: fn(&ast::ty_, ast_fold) -> ast::ty_ ) -> ast::ty_ { + orig: fn(&ast::ty_, ast_fold) -> ast::ty_) -> ast::ty_ { ret alt t { ast::ty_path(pth, _) { alt path_to_ident(pth) { @@ -422,12 +421,13 @@ fn transcribe_type(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], fn transcribe_block(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], blk: &blk_, fld: ast_fold, - orig: fn(&blk_, ast_fold) -> blk_ ) -> blk_ { + orig: fn(&blk_, ast_fold) -> blk_) -> blk_ { ret alt block_to_ident(blk) { some(id) { alt follow_for_trans(cx, b.find(id), idx_path) { some(match_block(new_blk)) { new_blk.node } + // possibly allow promotion of ident/path/expr to blocks? some(m) { match_error(cx, m, "a block") @@ -452,20 +452,20 @@ fn p_t_s_rec(cx: &ext_ctxt, m: &matchable, s: &selector, b: &binders) { expr_vec(p_elts, _) { alt elts_to_ell(cx, p_elts) { {pre: pre, rep: some(repeat_me), post: post} { - p_t_s_r_length(cx, vec::len(pre) + vec::len(post), - true, s, b); - if(vec::len(pre) > 0u) { + p_t_s_r_length(cx, vec::len(pre) + vec::len(post), true, s, + b); + if vec::len(pre) > 0u { p_t_s_r_actual_vector(cx, pre, true, s, b); } p_t_s_r_ellipses(cx, repeat_me, vec::len(pre), s, b); - if(vec::len(post) > 0u) { + if vec::len(post) > 0u { cx.span_unimpl(e.span, "matching after `...` not yet supported"); } } {pre: pre, rep: none., post: post} { - if post != ~[] { + if post != [] { cx.bug("elts_to_ell provided an invalid result"); } p_t_s_r_length(cx, vec::len(pre), false, s, b); @@ -474,6 +474,7 @@ fn p_t_s_rec(cx: &ext_ctxt, m: &matchable, s: &selector, b: &binders) { } } + /* TODO: handle embedded types and blocks, at least */ expr_mac(mac) { p_t_s_r_mac(cx, mac, s, b); @@ -488,7 +489,7 @@ fn p_t_s_rec(cx: &ext_ctxt, m: &matchable, s: &selector, b: &binders) { _ { cx.bug("broken traversal in p_t_s_r") } } } - b.literal_ast_matchers += ~[bind select(cx, _, e)]; + b.literal_ast_matchers += [bind select(cx, _, e)]; } } } @@ -545,7 +546,7 @@ fn block_to_ident(blk: &blk_) -> option::t<ident> { fn p_t_s_r_mac(cx: &ext_ctxt, mac: &ast::mac, s: &selector, b: &binders) { fn select_pt_1(cx: &ext_ctxt, m: &matchable, - fn_m: fn(&ast::mac) -> match_result ) -> match_result { + fn_m: fn(&ast::mac) -> match_result) -> match_result { ret alt m { match_expr(e) { alt e.node { expr_mac(mac) { fn_m(mac) } _ { none } } @@ -603,17 +604,18 @@ fn p_t_s_r_mac(cx: &ext_ctxt, mac: &ast::mac, s: &selector, b: &binders) { fn p_t_s_r_ellipses(cx: &ext_ctxt, repeat_me: @expr, offset: uint, s: &selector, b: &binders) { fn select(cx: &ext_ctxt, repeat_me: @expr, offset: uint, m: &matchable) -> - match_result { + match_result { ret alt m { match_expr(e) { alt e.node { expr_vec(arg_elts, _) { - let elts = ~[]; + let elts = []; let idx = offset; while idx < vec::len(arg_elts) { - elts += ~[leaf(match_expr(arg_elts.(idx)))]; + elts += [leaf(match_expr(arg_elts[idx]))]; idx += 1u; } + // using repeat_me.span is a little wacky, but the // error we want to report is one in the macro def some(seq(@elts, repeat_me.span)) @@ -631,14 +633,14 @@ fn p_t_s_r_ellipses(cx: &ext_ctxt, repeat_me: @expr, offset: uint, fn p_t_s_r_length(cx: &ext_ctxt, len: uint, at_least: bool, s: selector, b: &binders) { - fn len_select(_cx: &ext_ctxt, m: &matchable, at_least: bool, len: uint) - -> match_result { + fn len_select(_cx: &ext_ctxt, m: &matchable, at_least: bool, len: uint) -> + match_result { ret alt m { match_expr(e) { alt e.node { expr_vec(arg_elts, _) { let actual_len = vec::len(arg_elts); - if (at_least && actual_len >= len) || actual_len == len { + if at_least && actual_len >= len || actual_len == len { some(leaf(match_exact)) } else { none } } @@ -649,7 +651,7 @@ fn p_t_s_r_length(cx: &ext_ctxt, len: uint, at_least: bool, s: selector, } } b.literal_ast_matchers += - ~[compose_sels(s, bind len_select(cx, _, at_least, len))]; + [compose_sels(s, bind len_select(cx, _, at_least, len))]; } fn p_t_s_r_actual_vector(cx: &ext_ctxt, elts: [@expr], _repeat_after: bool, @@ -661,7 +663,7 @@ fn p_t_s_r_actual_vector(cx: &ext_ctxt, elts: [@expr], _repeat_after: bool, match_expr(e) { alt e.node { expr_vec(arg_elts, _) { - some(leaf(match_expr(arg_elts.(idx)))) + some(leaf(match_expr(arg_elts[idx]))) } _ { none } } @@ -669,7 +671,7 @@ fn p_t_s_r_actual_vector(cx: &ext_ctxt, elts: [@expr], _repeat_after: bool, _ { cx.bug("broken traversal in p_t_s_r") } } } - p_t_s_rec(cx, match_expr(elts.(idx)), + p_t_s_rec(cx, match_expr(elts[idx]), compose_sels(s, bind select(cx, _, idx)), b); idx += 1u; } @@ -677,15 +679,17 @@ fn p_t_s_r_actual_vector(cx: &ext_ctxt, elts: [@expr], _repeat_after: bool, fn add_new_extension(cx: &ext_ctxt, sp: span, arg: @expr, _body: option::t<str>) -> base::macro_def { - let args: [@ast::expr] = alt arg.node { - ast::expr_vec(elts, _) { elts } - _ { - cx.span_fatal(sp, "#macro requires arguments of the form `[...]`.") - } - }; + let args: [@ast::expr] = + alt arg.node { + ast::expr_vec(elts, _) { elts } + _ { + cx.span_fatal(sp, + "#macro requires arguments of the form `[...]`.") + } + }; let macro_name: option::t<str> = none; - let clauses: [@clause] = ~[]; + let clauses: [@clause] = []; for arg: @expr in args { alt arg.node { expr_vec(elts, mut) { @@ -696,7 +700,7 @@ fn add_new_extension(cx: &ext_ctxt, sp: span, arg: @expr, } - alt elts.(0u).node { + alt elts[0u].node { expr_mac(mac) { alt mac.node { mac_invoc(pth, invoc_arg, body) { @@ -706,8 +710,9 @@ fn add_new_extension(cx: &ext_ctxt, sp: span, arg: @expr, none. { macro_name = some(id); } some(other_id) { if id != other_id { - cx.span_fatal(pth.span, "macro name must be " - + "consistent"); + cx.span_fatal(pth.span, + "macro name must be " + + "consistent"); } } } @@ -718,15 +723,15 @@ fn add_new_extension(cx: &ext_ctxt, sp: span, arg: @expr, } } clauses += - ~[@{params: pattern_to_selectors(cx, invoc_arg), - body: elts.(1u)}]; + [@{params: pattern_to_selectors(cx, invoc_arg), + body: elts[1u]}]; // FIXME: check duplicates (or just simplify // the macro arg situation) } } } _ { - cx.span_fatal(elts.(0u).span, + cx.span_fatal(elts[0u].span, "extension clause must" + " start with a macro invocation."); } @@ -756,9 +761,7 @@ fn add_new_extension(cx: &ext_ctxt, sp: span, arg: @expr, _body: option::t<str>, clauses: [@clause]) -> @expr { for c: @clause in clauses { alt use_selectors_to_bind(c.params, arg) { - some(bindings) { - ret transcribe(cx, bindings, c.body) - } + some(bindings) { ret transcribe(cx, bindings, c.body) } none. { cont; } } } |
