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 | |
| parent | 4aa165553bfb2a74e2e54f08fd9507e23bc24708 (diff) | |
| download | rust-518dc52f85c2efb67aaa1208c02e9a7e0bdaca49.tar.gz rust-518dc52f85c2efb67aaa1208c02e9a7e0bdaca49.zip | |
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')
| -rw-r--r-- | src/comp/syntax/ast.rs | 67 | ||||
| -rw-r--r-- | src/comp/syntax/codemap.rs | 55 | ||||
| -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 | ||||
| -rw-r--r-- | src/comp/syntax/fold.rs | 158 | ||||
| -rw-r--r-- | src/comp/syntax/parse/eval.rs | 15 | ||||
| -rw-r--r-- | src/comp/syntax/parse/lexer.rs | 92 | ||||
| -rw-r--r-- | src/comp/syntax/parse/parser.rs | 618 | ||||
| -rw-r--r-- | src/comp/syntax/parse/token.rs | 3 | ||||
| -rw-r--r-- | src/comp/syntax/print/pp.rs | 101 | ||||
| -rw-r--r-- | src/comp/syntax/print/pprust.rs | 300 | ||||
| -rw-r--r-- | src/comp/syntax/util/interner.rs | 8 | ||||
| -rw-r--r-- | src/comp/syntax/visit.rs | 81 |
19 files changed, 857 insertions, 922 deletions
diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs index 7c9bd7c6897..80d327b119b 100644 --- a/src/comp/syntax/ast.rs +++ b/src/comp/syntax/ast.rs @@ -49,6 +49,7 @@ tag def { def_arg(def_id); def_local(def_id); def_variant(def_id, /* tag */def_id); + /* variant */ def_ty(def_id); def_ty_arg(uint, kind); @@ -56,6 +57,7 @@ tag def { def_use(def_id); def_native_ty(def_id); def_native_fn(def_id); + /* A "fake" def for upvars. This never appears in the def_map, but * freevars::def_lookup will return it for a def that is an upvar. * It contains the actual def. */ @@ -77,7 +79,7 @@ fn def_id_of_def(d: def) -> def_id { def_local(id) { ret id; } def_variant(_, id) { ret id; } def_ty(id) { ret id; } - def_ty_arg(_,_) { fail; } + def_ty_arg(_, _) { fail; } def_binding(id) { ret id; } def_use(id) { ret id; } def_native_ty(id) { ret id; } @@ -100,10 +102,7 @@ type crate_ = tag crate_directive_ { cdir_src_mod(ident, option::t<filename>, [attribute]); - cdir_dir_mod(ident, - option::t<filename>, - [@crate_directive], - [attribute]); + cdir_dir_mod(ident, option::t<filename>, [@crate_directive], [attribute]); cdir_view_item(@view_item); cdir_syntax(path); cdir_auth(path, _auth); @@ -155,30 +154,22 @@ iter pat_bindings(pat: &@pat) -> @pat { alt pat.node { pat_bind(_) { put pat; } pat_tag(_, sub) { - for p in sub { - for each b in pat_bindings(p) { put b; } - } + for p in sub { for each b in pat_bindings(p) { put b; } } } pat_rec(fields, _) { - for f in fields { - for each b in pat_bindings(f.pat) { put b; } - } + for f in fields { for each b in pat_bindings(f.pat) { put b; } } } pat_tup(elts) { - for elt in elts { - for each b in pat_bindings(elt) { put b; } - } - } - pat_box(sub) { - for each b in pat_bindings(sub) { put b; } + for elt in elts { for each b in pat_bindings(elt) { put b; } } } - pat_wild. | pat_lit(_) {} + pat_box(sub) { for each b in pat_bindings(sub) { put b; } } + pat_wild. | pat_lit(_) { } } } fn pat_binding_ids(pat: &@pat) -> [node_id] { - let found = ~[]; - for each b in pat_bindings(pat) { found += ~[b.id]; } + let found = []; + for each b in pat_bindings(pat) { found += [b.id]; } ret found; } @@ -258,6 +249,7 @@ type stmt = spanned<stmt_>; tag stmt_ { stmt_decl(@decl, node_id); stmt_expr(@expr, node_id); + // These only exist in crate-level blocks. stmt_crate_directive(@crate_directive); } @@ -266,10 +258,8 @@ tag init_op { init_assign; init_move; } type initializer = {op: init_op, expr: @expr}; -type local_ = {ty: @ty, - pat: @pat, // FIXME: should really be a refinement on pat - init: option::t<initializer>, - id: node_id}; +type local_ = // FIXME: should really be a refinement on pat + {ty: @ty, pat: @pat, init: option::t<initializer>, id: node_id}; type local = spanned<local_>; @@ -312,6 +302,7 @@ tag expr_ { expr_alt(@expr, [arm]); expr_fn(_fn); expr_block(blk); + /* * FIXME: many of these @exprs should be constrained with * is_lval once we have constrained types working. @@ -331,10 +322,13 @@ tag expr_ { expr_put(option::t<@expr>); expr_be(@expr); expr_log(int, @expr); + /* just an assert, no significance to typestate */ expr_assert(@expr); + /* preds that typestate is aware of */ expr_check(check_mode, @expr); + /* FIXME Would be nice if expr_check desugared to expr_if_check. */ expr_if_check(@expr, blk, option::t<@expr>); @@ -428,10 +422,11 @@ tag ty_ { ty_bot; /* return type of ! functions and type of ret/fail/break/cont. there is no syntax for this type. */ + /* bot represents the value of functions that don't return a value locally to their context. in contrast, things like log that do return, but don't return a meaningful value, have result type nil. */ - ty_bool; + ty_bool; ty_int; ty_uint; ty_float; @@ -453,6 +448,7 @@ tag ty_ { ty_type; ty_constr(@ty, [@ty_constr]); ty_mac(mac); + // ty_infer means the type should be inferred instead of it having been // specified. This should only appear at the "top level" of a type and not // nested in one. @@ -514,6 +510,7 @@ tag purity { tag controlflow { noreturn; // functions with return type _|_ that always // raise an error or exit (i.e. never return to the caller) + return; // everything else } @@ -531,9 +528,9 @@ type _obj = {fields: [obj_field], methods: [@method]}; type anon_obj = // New fields and methods, if they exist. + // inner_obj: the original object being extended, if it exists. {fields: option::t<[anon_obj_field]>, methods: [@method], - // inner_obj: the original object being extended, if it exists. inner_obj: option::t<@expr>}; type _mod = {view_items: [@view_item], items: [@item]}; @@ -601,10 +598,14 @@ tag item_ { item_ty(@ty, [ty_param]); item_tag([variant], [ty_param]); item_obj(_obj, [ty_param], /* constructor id */node_id); - item_res(_fn, /* dtor */ - node_id, /* dtor id */ + item_res(_fn, + /* dtor */ + node_id, + /* dtor id */ [ty_param], - node_id /* ctor id */); + + /* ctor id */ + node_id); } type native_item = @@ -637,11 +638,7 @@ fn is_exported(i: ident, m: _mod) -> bool { for vi: @ast::view_item in m.view_items { alt vi.node { ast::view_item_export(ids, _) { - for id in ids { - if str::eq(i, id) { - ret true; - } - } + for id in ids { if str::eq(i, id) { ret true; } } count += 1u; } _ {/* fall through */ } @@ -670,7 +667,7 @@ fn eq_ty(a: &@ty, b: &@ty) -> bool { ret std::box::ptr_eq(a, b); } fn hash_ty(t: &@ty) -> uint { ret t.span.lo << 16u + t.span.hi; } fn block_from_expr(e: @expr) -> blk { - let blk_ = {stmts: ~[], expr: option::some::<@expr>(e), id: e.id}; + let blk_ = {stmts: [], expr: option::some::<@expr>(e), id: e.id}; ret {node: blk_, span: e.span}; } diff --git a/src/comp/syntax/codemap.rs b/src/comp/syntax/codemap.rs index a2542e5fddf..a52a58e629e 100644 --- a/src/comp/syntax/codemap.rs +++ b/src/comp/syntax/codemap.rs @@ -23,36 +23,36 @@ type codemap = @{mutable files: [filemap]}; type loc = {filename: filename, line: uint, col: uint}; -fn new_codemap() -> codemap { ret @{mutable files: ~[]}; } +fn new_codemap() -> codemap { ret @{mutable files: []}; } fn new_filemap(filename: filename, start_pos_ch: uint, start_pos_byte: uint) -> filemap { ret @{name: filename, start_pos: {ch: start_pos_ch, byte: start_pos_byte}, - mutable lines: ~[{ch: start_pos_ch, byte: start_pos_byte}]}; + mutable lines: [{ch: start_pos_ch, byte: start_pos_byte}]}; } fn next_line(file: filemap, chpos: uint, byte_pos: uint) { - file.lines += ~[{ch: chpos, byte: byte_pos}]; + file.lines += [{ch: chpos, byte: byte_pos}]; } -type lookup_fn = fn(file_pos) -> uint ; +type lookup_fn = fn(file_pos) -> uint; fn lookup_pos(map: codemap, pos: uint, lookup: lookup_fn) -> loc { let a = 0u; let b = vec::len(map.files); while b - a > 1u { let m = (a + b) / 2u; - if lookup(map.files.(m).start_pos) > pos { b = m; } else { a = m; } + if lookup(map.files[m].start_pos) > pos { b = m; } else { a = m; } } - let f = map.files.(a); + let f = map.files[a]; a = 0u; b = vec::len(f.lines); while b - a > 1u { let m = (a + b) / 2u; - if lookup(f.lines.(m)) > pos { b = m; } else { a = m; } + if lookup(f.lines[m]) > pos { b = m; } else { a = m; } } - ret {filename: f.name, line: a + 1u, col: pos - lookup(f.lines.(a))}; + ret {filename: f.name, line: a + 1u, col: pos - lookup(f.lines[a])}; } fn lookup_char_pos(map: codemap, pos: uint) -> loc { @@ -65,7 +65,8 @@ fn lookup_byte_pos(map: codemap, pos: uint) -> loc { ret lookup_pos(map, pos, lookup); } -tag opt_span { //hack (as opposed to option::t), to make `span` compile +tag opt_span { + //hack (as opposed to option::t), to make `span` compile os_none; os_some(@span); } @@ -75,13 +76,14 @@ fn span_to_str(sp: &span, cm: &codemap) -> str { let cur = sp; let res = ""; let prev_file = none; - while(true) { + while true { let lo = lookup_char_pos(cm, cur.lo); let hi = lookup_char_pos(cm, cur.hi); - res += #fmt("%s:%u:%u:%u:%u", - if some(lo.filename) == prev_file { "-" } - else { lo.filename }, - lo.line, lo.col, hi.line, hi.col); + res += + #fmt["%s:%u:%u:%u:%u", + if some(lo.filename) == prev_file { + "-" + } else { lo.filename }, lo.line, lo.col, hi.line, hi.col]; alt cur.expanded_from { os_none. { break; } os_some(new_sp) { @@ -110,11 +112,9 @@ fn emit_diagnostic(sp: &option::t<span>, msg: &str, kind: &str, color: u8, if term::color_supported() { term::fg(io::stdout().get_buf_writer(), color); } - io::stdout().write_str(#fmt("%s:", kind)); - if term::color_supported() { - term::reset(io::stdout().get_buf_writer()); - } - io::stdout().write_str(#fmt(" %s\n", msg)); + io::stdout().write_str(#fmt["%s:", kind]); + if term::color_supported() { term::reset(io::stdout().get_buf_writer()); } + io::stdout().write_str(#fmt[" %s\n", msg]); maybe_highlight_lines(sp, cm, maybe_lines); } @@ -143,14 +143,14 @@ fn maybe_highlight_lines(sp: &option::t<span>, cm: &codemap, } // Print the offending lines for line: uint in display_lines { - io::stdout().write_str(#fmt("%s:%u ", fm.name, line + 1u)); + io::stdout().write_str(#fmt["%s:%u ", fm.name, line + 1u]); let s = get_line(fm, line as int, file); if !str::ends_with(s, "\n") { s += "\n"; } io::stdout().write_str(s); } if elided { - let last_line = display_lines.(vec::len(display_lines) - 1u); - let s = #fmt("%s:%u ", fm.name, last_line + 1u); + let last_line = display_lines[vec::len(display_lines) - 1u]; + let s = #fmt["%s:%u ", fm.name, last_line + 1u]; let indent = str::char_len(s); let out = ""; while indent > 0u { out += " "; indent -= 1u; } @@ -163,7 +163,7 @@ fn maybe_highlight_lines(sp: &option::t<span>, cm: &codemap, if vec::len(lines.lines) == 1u { let lo = lookup_char_pos(cm, option::get(sp).lo); let digits = 0u; - let num = lines.lines.(0) / 10u; + let num = lines.lines[0] / 10u; // how many digits must be indent past? while num > 0u { num /= 10u; digits += 1u; } @@ -202,18 +202,18 @@ type file_lines = {name: str, lines: [uint]}; fn span_to_lines(sp: span, cm: codemap::codemap) -> @file_lines { let lo = lookup_char_pos(cm, sp.lo); let hi = lookup_char_pos(cm, sp.hi); - let lines = ~[]; + let lines = []; for each i: uint in uint::range(lo.line - 1u, hi.line as uint) { - lines += ~[i]; + lines += [i]; } ret @{name: lo.filename, lines: lines}; } fn get_line(fm: filemap, line: int, file: &str) -> str { - let begin: uint = fm.lines.(line).byte - fm.start_pos.byte; + let begin: uint = fm.lines[line].byte - fm.start_pos.byte; let end: uint; if line as uint < vec::len(fm.lines) - 1u { - end = fm.lines.(line + 1).byte - fm.start_pos.byte; + end = fm.lines[line + 1].byte - fm.start_pos.byte; } else { // If we're not done parsing the file, we're at the limit of what's // parsed. If we just slice the rest of the string, we'll print out @@ -232,7 +232,6 @@ fn get_filemap(cm: codemap, filename: str) -> filemap { // (or expected function, found _|_) fail; // ("asking for " + filename + " which we don't know about"); } - // // Local Variables: // mode: rust 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; } } } diff --git a/src/comp/syntax/fold.rs b/src/comp/syntax/fold.rs index 5593ddb21c6..b781a2481c2 100644 --- a/src/comp/syntax/fold.rs +++ b/src/comp/syntax/fold.rs @@ -20,57 +20,57 @@ type ast_fold = @mutable a_f; type ast_fold_precursor = //unlike the others, item_ is non-trivial - {fold_crate: fn(&crate_, ast_fold) -> crate_ , + {fold_crate: fn(&crate_, ast_fold) -> crate_, fold_crate_directive: - fn(&crate_directive_, ast_fold) -> crate_directive_ , - fold_view_item: fn(&view_item_, ast_fold) -> view_item_ , - fold_native_item: fn(&@native_item, ast_fold) -> @native_item , - fold_item: fn(&@item, ast_fold) -> @item , - fold_item_underscore: fn(&item_, ast_fold) -> item_ , - fold_method: fn(&method_, ast_fold) -> method_ , - fold_block: fn(&blk_, ast_fold) -> blk_ , - fold_stmt: fn(&stmt_, ast_fold) -> stmt_ , - fold_arm: fn(&arm, ast_fold) -> arm , - fold_pat: fn(&pat_, ast_fold) -> pat_ , - fold_decl: fn(&decl_, ast_fold) -> decl_ , - fold_expr: fn(&expr_, ast_fold) -> expr_ , - fold_ty: fn(&ty_, ast_fold) -> ty_ , - fold_constr: fn(&ast::constr_, ast_fold) -> constr_ , - fold_fn: fn(&_fn, ast_fold) -> _fn , - fold_mod: fn(&_mod, ast_fold) -> _mod , - fold_native_mod: fn(&native_mod, ast_fold) -> native_mod , - fold_variant: fn(&variant_, ast_fold) -> variant_ , - fold_ident: fn(&ident, ast_fold) -> ident , - fold_path: fn(&path_, ast_fold) -> path_ , - fold_local: fn(&local_, ast_fold) -> local_ , - map_exprs: fn(fn(&@expr) -> @expr , [@expr]) -> [@expr], + fn(&crate_directive_, ast_fold) -> crate_directive_, + fold_view_item: fn(&view_item_, ast_fold) -> view_item_, + fold_native_item: fn(&@native_item, ast_fold) -> @native_item, + fold_item: fn(&@item, ast_fold) -> @item, + fold_item_underscore: fn(&item_, ast_fold) -> item_, + fold_method: fn(&method_, ast_fold) -> method_, + fold_block: fn(&blk_, ast_fold) -> blk_, + fold_stmt: fn(&stmt_, ast_fold) -> stmt_, + fold_arm: fn(&arm, ast_fold) -> arm, + fold_pat: fn(&pat_, ast_fold) -> pat_, + fold_decl: fn(&decl_, ast_fold) -> decl_, + fold_expr: fn(&expr_, ast_fold) -> expr_, + fold_ty: fn(&ty_, ast_fold) -> ty_, + fold_constr: fn(&ast::constr_, ast_fold) -> constr_, + fold_fn: fn(&_fn, ast_fold) -> _fn, + fold_mod: fn(&_mod, ast_fold) -> _mod, + fold_native_mod: fn(&native_mod, ast_fold) -> native_mod, + fold_variant: fn(&variant_, ast_fold) -> variant_, + fold_ident: fn(&ident, ast_fold) -> ident, + fold_path: fn(&path_, ast_fold) -> path_, + fold_local: fn(&local_, ast_fold) -> local_, + map_exprs: fn(fn(&@expr) -> @expr, [@expr]) -> [@expr], new_id: fn(node_id) -> node_id, new_span: fn(&span) -> span}; type a_f = - {fold_crate: fn(&crate) -> crate , - fold_crate_directive: fn(&@crate_directive) -> @crate_directive , - fold_view_item: fn(&@view_item) -> @view_item , - fold_native_item: fn(&@native_item) -> @native_item , - fold_item: fn(&@item) -> @item , - fold_item_underscore: fn(&item_) -> item_ , - fold_method: fn(&@method) -> @method , - fold_block: fn(&blk) -> blk , - fold_stmt: fn(&@stmt) -> @stmt , - fold_arm: fn(&arm) -> arm , - fold_pat: fn(&@pat) -> @pat , - fold_decl: fn(&@decl) -> @decl , - fold_expr: fn(&@expr) -> @expr , - fold_ty: fn(&@ty) -> @ty , - fold_constr: fn(&@constr) -> @constr , - fold_fn: fn(&_fn) -> _fn , - fold_mod: fn(&_mod) -> _mod , - fold_native_mod: fn(&native_mod) -> native_mod , - fold_variant: fn(&variant) -> variant , - fold_ident: fn(&ident) -> ident , - fold_path: fn(&path) -> path , - fold_local: fn(&@local) -> @local , - map_exprs: fn(fn(&@expr) -> @expr , [@expr]) -> [@expr], + {fold_crate: fn(&crate) -> crate, + fold_crate_directive: fn(&@crate_directive) -> @crate_directive, + fold_view_item: fn(&@view_item) -> @view_item, + fold_native_item: fn(&@native_item) -> @native_item, + fold_item: fn(&@item) -> @item, + fold_item_underscore: fn(&item_) -> item_, + fold_method: fn(&@method) -> @method, + fold_block: fn(&blk) -> blk, + fold_stmt: fn(&@stmt) -> @stmt, + fold_arm: fn(&arm) -> arm, + fold_pat: fn(&@pat) -> @pat, + fold_decl: fn(&@decl) -> @decl, + fold_expr: fn(&@expr) -> @expr, + fold_ty: fn(&@ty) -> @ty, + fold_constr: fn(&@constr) -> @constr, + fold_fn: fn(&_fn) -> _fn, + fold_mod: fn(&_mod) -> _mod, + fold_native_mod: fn(&native_mod) -> native_mod, + fold_variant: fn(&variant) -> variant, + fold_ident: fn(&ident) -> ident, + fold_path: fn(&path) -> path, + fold_local: fn(&@local) -> @local, + map_exprs: fn(fn(&@expr) -> @expr, [@expr]) -> [@expr], new_id: fn(node_id) -> node_id, new_span: fn(&span) -> span}; @@ -120,7 +120,7 @@ fn fold_meta_item_(mi: &@meta_item, fld: ast_fold) -> @meta_item { span: mi.span}; } //used in noop_fold_item and noop_fold_crate -fn fold_attribute_(at: &attribute, fmi: fn(&@meta_item) -> @meta_item ) -> +fn fold_attribute_(at: &attribute, fmi: fn(&@meta_item) -> @meta_item) -> attribute { ret {node: {style: at.node.style, value: *fmi(@at.node.value)}, span: at.span}; @@ -135,14 +135,14 @@ fn fold_arg_(a: &arg, fld: ast_fold) -> arg { //used in noop_fold_expr, and possibly elsewhere in the future fn fold_mac_(m: &mac, fld: ast_fold) -> mac { ret {node: - alt m.node { - mac_invoc(pth, arg, body) { - mac_invoc(fld.fold_path(pth), fld.fold_expr(arg), body) - } - mac_embed_type(ty) { mac_embed_type(fld.fold_ty(ty)) } - mac_embed_block(blk) { mac_embed_block(fld.fold_block(blk)) } - mac_ellipsis. { mac_ellipsis } - }, + alt m.node { + mac_invoc(pth, arg, body) { + mac_invoc(fld.fold_path(pth), fld.fold_expr(arg), body) + } + mac_embed_type(ty) { mac_embed_type(fld.fold_ty(ty)) } + mac_embed_block(blk) { mac_embed_block(fld.fold_block(blk)) } + mac_ellipsis. { mac_ellipsis } + }, span: m.span}; } @@ -200,7 +200,7 @@ fn noop_fold_native_item(ni: &@native_item, fld: ast_fold) -> @native_item { cf: fdec.cf, constraints: vec::map(fld.fold_constr, - fdec.constraints)}, typms) + fdec.constraints)}, typms) } }, id: ni.id, @@ -238,8 +238,8 @@ fn noop_fold_item_underscore(i: &item_, fld: ast_fold) -> item_ { } item_obj(o, typms, d) { item_obj({fields: vec::map(fold_obj_field, o.fields), - methods: vec::map(fld.fold_method, o.methods)}, - typms, d) + methods: vec::map(fld.fold_method, o.methods)}, typms, + d) } item_res(dtor, did, typms, cid) { item_res(fld.fold_fn(dtor), did, typms, cid) @@ -269,8 +269,7 @@ fn noop_fold_stmt(s: &stmt_, fld: ast_fold) -> stmt_ { } fn noop_fold_arm(a: &arm, fld: ast_fold) -> arm { - ret {pats: vec::map(fld.fold_pat, a.pats), - body: fld.fold_block(a.body)}; + ret {pats: vec::map(fld.fold_pat, a.pats), body: fld.fold_block(a.body)}; } fn noop_fold_pat(p: &pat_, fld: ast_fold) -> pat_ { @@ -282,15 +281,13 @@ fn noop_fold_pat(p: &pat_, fld: ast_fold) -> pat_ { pat_tag(fld.fold_path(pth), vec::map(fld.fold_pat, pats)) } pat_rec(fields, etc) { - let fs = ~[]; + let fs = []; for f: ast::field_pat in fields { - fs += ~[{ident: f.ident, pat: fld.fold_pat(f.pat)}]; + fs += [{ident: f.ident, pat: fld.fold_pat(f.pat)}]; } pat_rec(fs, etc) } - pat_tup(elts) { - pat_tup(vec::map(fld.fold_pat, elts)) - } + pat_tup(elts) { pat_tup(vec::map(fld.fold_pat, elts)) } pat_box(inner) { pat_box(fld.fold_pat(inner)) } }; } @@ -346,9 +343,7 @@ fn noop_fold_expr(e: &expr_, fld: ast_fold) -> expr_ { expr_rec(vec::map(fold_field, fields), option::map(fld.fold_expr, maybe_expr)) } - expr_tup(elts) { - expr_tup(vec::map(fld.fold_expr, elts)) - } + expr_tup(elts) { expr_tup(vec::map(fld.fold_expr, elts)) } expr_call(f, args) { expr_call(fld.fold_expr(f), fld.map_exprs(fld.fold_expr, args)) } @@ -393,9 +388,7 @@ fn noop_fold_expr(e: &expr_, fld: ast_fold) -> expr_ { expr_move(el, er) { expr_move(fld.fold_expr(el), fld.fold_expr(er)) } - expr_copy(e) { - expr_copy(fld.fold_expr(e)) - } + expr_copy(e) { expr_copy(fld.fold_expr(e)) } expr_assign(el, er) { expr_assign(fld.fold_expr(el), fld.fold_expr(er)) } @@ -487,19 +480,20 @@ fn noop_fold_path(p: &path_, fld: ast_fold) -> path_ { fn noop_fold_local(l: &local_, fld: ast_fold) -> local_ { ret {ty: fld.fold_ty(l.ty), pat: fld.fold_pat(l.pat), - init: alt l.init { - option::none::<initializer>. { l.init } - option::some::<initializer>(init) { - option::some::<initializer>({op: init.op, - expr: fld.fold_expr(init.expr)}) - } - }, + init: + alt l.init { + option::none::<initializer>. { l.init } + option::some::<initializer>(init) { + option::some::<initializer>({op: init.op, + expr: fld.fold_expr(init.expr)}) + } + }, id: l.id}; } /* temporarily eta-expand because of a compiler bug with using `fn<T>` as a value */ -fn noop_map_exprs(f: fn(&@expr) -> @expr , es: [@expr]) -> [@expr] { +fn noop_map_exprs(f: fn(&@expr) -> @expr, es: [@expr]) -> [@expr] { ret vec::map(f, es); } @@ -634,14 +628,16 @@ fn make_fold(afp: &ast_fold_precursor) -> ast_fold { } fn f_pat(afp: &ast_fold_precursor, f: ast_fold, x: &@pat) -> @pat { ret @{id: afp.new_id(x.id), - node: afp.fold_pat(x.node, f), span: afp.new_span(x.span)}; + node: afp.fold_pat(x.node, f), + span: afp.new_span(x.span)}; } fn f_decl(afp: &ast_fold_precursor, f: ast_fold, x: &@decl) -> @decl { ret @{node: afp.fold_decl(x.node, f), span: afp.new_span(x.span)}; } fn f_expr(afp: &ast_fold_precursor, f: ast_fold, x: &@expr) -> @expr { ret @{id: afp.new_id(x.id), - node: afp.fold_expr(x.node, f), span: afp.new_span(x.span)}; + node: afp.fold_expr(x.node, f), + span: afp.new_span(x.span)}; } fn f_ty(afp: &ast_fold_precursor, f: ast_fold, x: &@ty) -> @ty { ret @{node: afp.fold_ty(x.node, f), span: afp.new_span(x.span)}; diff --git a/src/comp/syntax/parse/eval.rs b/src/comp/syntax/parse/eval.rs index fb52960517d..af1ba91b37b 100644 --- a/src/comp/syntax/parse/eval.rs +++ b/src/comp/syntax/parse/eval.rs @@ -26,8 +26,7 @@ type ctx = cfg: ast::crate_cfg}; fn eval_crate_directives(cx: ctx, cdirs: &[@ast::crate_directive], - prefix: str, - view_items: &mutable [@ast::view_item], + prefix: str, view_items: &mutable [@ast::view_item], items: &mutable [@ast::item]) { for sub_cdir: @ast::crate_directive in cdirs { eval_crate_directive(cx, sub_cdir, prefix, view_items, items); @@ -36,8 +35,8 @@ fn eval_crate_directives(cx: ctx, cdirs: &[@ast::crate_directive], fn eval_crate_directives_to_mod(cx: ctx, cdirs: &[@ast::crate_directive], prefix: str) -> ast::_mod { - let view_items: [@ast::view_item] = ~[]; - let items: [@ast::item] = ~[]; + let view_items: [@ast::view_item] = []; + let items: [@ast::item] = []; eval_crate_directives(cx, cdirs, prefix, view_items, items); ret {view_items: view_items, items: items}; } @@ -53,7 +52,7 @@ fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: str, if std::fs::path_is_absolute(file_path) { file_path } else { prefix + std::fs::path_sep() + file_path }; - if cx.mode == mode_depend { cx.deps += ~[full_path]; ret; } + if cx.mode == mode_depend { cx.deps += [full_path]; ret; } let p0 = new_parser_from_file(cx.sess, cx.cfg, full_path, cx.chpos, cx.byte_pos, SOURCE_FILE); @@ -68,7 +67,7 @@ fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: str, // Thread defids, chpos and byte_pos through the parsers cx.chpos = p0.get_chpos(); cx.byte_pos = p0.get_byte_pos(); - items += ~[i]; + items += [i]; } ast::cdir_dir_mod(id, dir_opt, cdirs, attrs) { let path = id; @@ -85,9 +84,9 @@ fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: str, node: ast::item_mod(m0), span: cdir.span}; cx.sess.next_id += 1; - items += ~[i]; + items += [i]; } - ast::cdir_view_item(vi) { view_items += ~[vi]; } + ast::cdir_view_item(vi) { view_items += [vi]; } ast::cdir_syntax(pth) { } ast::cdir_auth(pth, eff) { } } diff --git a/src/comp/syntax/parse/lexer.rs b/src/comp/syntax/parse/lexer.rs index 9e78c8e7e82..6e4cc10abb7 100644 --- a/src/comp/syntax/parse/lexer.rs +++ b/src/comp/syntax/parse/lexer.rs @@ -14,18 +14,18 @@ import codemap; type reader = obj { - fn is_eof() -> bool ; - fn curr() -> char ; - fn next() -> char ; - fn init() ; - fn bump() ; - fn get_str_from(uint) -> str ; - fn get_interner() -> @interner::interner<str> ; - fn get_chpos() -> uint ; - fn get_byte_pos() -> uint ; - fn get_col() -> uint ; - fn get_filemap() -> codemap::filemap ; - fn err(str) ; + fn is_eof() -> bool; + fn curr() -> char; + fn next() -> char; + fn init(); + fn bump(); + fn get_str_from(uint) -> str; + fn get_interner() -> @interner::interner<str>; + fn get_chpos() -> uint; + fn get_byte_pos() -> uint; + fn get_col() -> uint; + fn get_filemap() -> codemap::filemap; + fn err(str); }; fn new_reader(cm: &codemap::codemap, src: str, filemap: codemap::filemap, @@ -81,7 +81,7 @@ fn new_reader(cm: &codemap::codemap, src: str, filemap: codemap::filemap, codemap::emit_error(some(ast::mk_sp(chpos, chpos)), m, cm); } } - let strs: [str] = ~[]; + let strs: [str] = []; let rd = reader(cm, src, str::byte_len(src), 0u, 0u, -1 as char, filemap.start_pos.ch, strs, filemap, itr); @@ -166,10 +166,7 @@ fn consume_block_comment(rdr: &reader) { fn digits_to_string(s: str) -> int { let accum_int: int = 0; - for c: u8 in s { - accum_int *= 10; - accum_int += dec_digit_val(c as char); - } + for c: u8 in s { accum_int *= 10; accum_int += dec_digit_val(c as char); } ret accum_int; } @@ -177,11 +174,11 @@ fn scan_exponent(rdr: &reader) -> option::t<str> { let c = rdr.curr(); let rslt = ""; if c == 'e' || c == 'E' { - rslt += str::unsafe_from_bytes(~[c as u8]); + rslt += str::unsafe_from_bytes([c as u8]); rdr.bump(); c = rdr.curr(); if c == '-' || c == '+' { - rslt += str::unsafe_from_bytes(~[c as u8]); + rslt += str::unsafe_from_bytes([c as u8]); rdr.bump(); } let exponent = scan_dec_digits(rdr); @@ -195,7 +192,7 @@ fn scan_dec_digits(rdr: &reader) -> str { let c = rdr.curr(); let rslt: str = ""; while is_dec_digit(c) || c == '_' { - if c != '_' { rslt += str::unsafe_from_bytes(~[c as u8]); } + if c != '_' { rslt += str::unsafe_from_bytes([c as u8]); } rdr.bump(); c = rdr.curr(); } @@ -216,7 +213,7 @@ fn scan_number(c: char, rdr: &reader) -> token::token { rdr.bump(); c = rdr.curr(); } - } else if (c == '0' && n == 'b') { + } else if c == '0' && n == 'b' { rdr.bump(); rdr.bump(); c = rdr.curr(); @@ -290,7 +287,7 @@ fn scan_number(c: char, rdr: &reader) -> token::token { ret token::LIT_MACH_FLOAT(ast::ty_f32, intern(*rdr.get_interner(), float_str)); - } else if (c == '6' && n == '4') { + } else if c == '6' && n == '4' { rdr.bump(); rdr.bump(); ret token::LIT_MACH_FLOAT(ast::ty_f64, @@ -302,14 +299,14 @@ fn scan_number(c: char, rdr: &reader) -> token::token { } } else { ret token::LIT_FLOAT(interner::intern::<str>(*rdr.get_interner(), - float_str)); + float_str)); } } let maybe_exponent = scan_exponent(rdr); alt maybe_exponent { some(s) { ret token::LIT_FLOAT(interner::intern::<str>(*rdr.get_interner(), - dec_str + s)); + dec_str + s)); } none. { ret token::LIT_INT(accum_int); } } @@ -321,7 +318,7 @@ fn scan_numeric_escape(rdr: &reader, n_hex_digits: uint) -> char { let n = rdr.curr(); rdr.bump(); if !is_hex_digit(n) { - rdr.err(#fmt("illegal numeric character escape: %d", n as int)); + rdr.err(#fmt["illegal numeric character escape: %d", n as int]); fail; } accum_int *= 16; @@ -351,7 +348,7 @@ fn next_token_inner(rdr: &reader) -> token::token { if str::eq(accum_str, "_") { ret token::UNDERSCORE; } let is_mod_name = c == ':' && rdr.next() == ':'; ret token::IDENT(interner::intern::<str>(*rdr.get_interner(), - accum_str), is_mod_name); + accum_str), is_mod_name); } if is_dec_digit(c) { ret scan_number(c, rdr); } fn binop(rdr: &reader, op: token::binop) -> token::token { @@ -363,6 +360,7 @@ fn next_token_inner(rdr: &reader) -> token::token { } alt c { + // One-byte tokens. '?' { rdr.bump(); @@ -401,6 +399,7 @@ fn next_token_inner(rdr: &reader) -> token::token { } else { ret token::COLON; } } + // Multi-byte tokens. '=' { rdr.bump(); @@ -461,7 +460,7 @@ fn next_token_inner(rdr: &reader) -> token::token { 'u' { c2 = scan_numeric_escape(rdr, 4u); } 'U' { c2 = scan_numeric_escape(rdr, 8u); } c2 { - rdr.err(#fmt("unknown character escape: %d", c2 as int)); + rdr.err(#fmt["unknown character escape: %d", c2 as int]); fail; } } @@ -500,7 +499,7 @@ fn next_token_inner(rdr: &reader) -> token::token { str::push_char(accum_str, scan_numeric_escape(rdr, 8u)); } c2 { - rdr.err(#fmt("unknown string escape: %d", c2 as int)); + rdr.err(#fmt["unknown string escape: %d", c2 as int]); fail; } } @@ -510,7 +509,7 @@ fn next_token_inner(rdr: &reader) -> token::token { } rdr.bump(); ret token::LIT_STR(interner::intern::<str>(*rdr.get_interner(), - accum_str)); + accum_str)); } '-' { if rdr.next() == '>' { @@ -537,7 +536,7 @@ fn next_token_inner(rdr: &reader) -> token::token { '/' { ret binop(rdr, token::SLASH); } '^' { ret binop(rdr, token::CARET); } '%' { ret binop(rdr, token::PERCENT); } - c { rdr.err(#fmt("unkown start of token: %d", c as int)); fail; } + c { rdr.err(#fmt["unkown start of token: %d", c as int]); fail; } } } @@ -562,7 +561,7 @@ fn read_to_eol(rdr: &reader) -> str { fn read_one_line_comment(rdr: &reader) -> str { let val = read_to_eol(rdr); - assert (val.(0) == '/' as u8 && val.(1) == '/' as u8); + assert (val[0] == '/' as u8 && val[1] == '/' as u8); ret val; } @@ -578,8 +577,8 @@ fn consume_non_eol_whitespace(rdr: &reader) { fn push_blank_line_comment(rdr: &reader, comments: &mutable [cmnt]) { log ">>> blank-line comment"; - let v: [str] = ~[]; - comments += ~[{style: blank_line, lines: v, pos: rdr.get_chpos()}]; + let v: [str] = []; + comments += [{style: blank_line, lines: v, pos: rdr.get_chpos()}]; } fn consume_whitespace_counting_blank_lines(rdr: &reader, @@ -595,11 +594,11 @@ fn consume_whitespace_counting_blank_lines(rdr: &reader, fn read_line_comments(rdr: &reader, code_to_the_left: bool) -> cmnt { log ">>> line comments"; let p = rdr.get_chpos(); - let lines: [str] = ~[]; + let lines: [str] = []; while rdr.curr() == '/' && rdr.next() == '/' { let line = read_one_line_comment(rdr); log line; - lines += ~[line]; + lines += [line]; consume_non_eol_whitespace(rdr); } log "<<< line comments"; @@ -610,10 +609,7 @@ fn read_line_comments(rdr: &reader, code_to_the_left: bool) -> cmnt { fn all_whitespace(s: &str, begin: uint, end: uint) -> bool { let i: uint = begin; - while i != end { - if !is_whitespace(s.(i) as char) { ret false; } - i += 1u; - } + while i != end { if !is_whitespace(s[i] as char) { ret false; } i += 1u; } ret true; } @@ -626,20 +622,20 @@ fn trim_whitespace_prefix_and_push_line(lines: &mutable [str], s: &str, } else { s1 = ""; } } else { s1 = s; } log "pushing line: " + s1; - lines += ~[s1]; + lines += [s1]; } fn read_block_comment(rdr: &reader, code_to_the_left: bool) -> cmnt { log ">>> block comment"; let p = rdr.get_chpos(); - let lines: [str] = ~[]; + let lines: [str] = []; let col: uint = rdr.get_col(); rdr.bump(); rdr.bump(); let curr_line = "/*"; let level: int = 1; while level > 0 { - log #fmt("=== block comment level %d", level); + log #fmt["=== block comment level %d", level]; if rdr.is_eof() { rdr.err("unterminated block comment"); fail; } if rdr.curr() == '\n' { trim_whitespace_prefix_and_push_line(lines, curr_line, col); @@ -683,9 +679,9 @@ fn consume_comment(rdr: &reader, code_to_the_left: bool, comments: &mutable [cmnt]) { log ">>> consume comment"; if rdr.curr() == '/' && rdr.next() == '/' { - comments += ~[read_line_comments(rdr, code_to_the_left)]; - } else if (rdr.curr() == '/' && rdr.next() == '*') { - comments += ~[read_block_comment(rdr, code_to_the_left)]; + comments += [read_line_comments(rdr, code_to_the_left)]; + } else if rdr.curr() == '/' && rdr.next() == '*' { + comments += [read_block_comment(rdr, code_to_the_left)]; } else { fail; } log "<<< consume comment"; } @@ -712,8 +708,8 @@ fn gather_comments_and_literals(cm: &codemap::codemap, path: str, let src = str::unsafe_from_bytes(srdr.read_whole_stream()); let itr = @interner::mk::<str>(str::hash, str::eq); let rdr = new_reader(cm, src, codemap::new_filemap(path, 0u, 0u), itr); - let comments: [cmnt] = ~[]; - let literals: [lit] = ~[]; + let comments: [cmnt] = []; + let literals: [lit] = []; let first_read: bool = true; while !rdr.is_eof() { while true { @@ -731,7 +727,7 @@ fn gather_comments_and_literals(cm: &codemap::codemap, path: str, } let tok = next_token(rdr); if is_lit(tok.tok) { - literals += ~[{lit: rdr.get_str_from(tok.bpos), pos: tok.chpos}]; + literals += [{lit: rdr.get_str_from(tok.bpos), pos: tok.chpos}]; } log "tok: " + token::to_str(rdr, tok.tok); first_read = false; diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index 2d11ae974d3..8113f9fd94d 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -33,39 +33,38 @@ fn next_node_id(sess: &parse_sess) -> node_id { type parser = obj { - fn peek() -> token::token ; - fn bump() ; - fn swap(token::token, uint, uint) ; - fn look_ahead(uint) -> token::token ; - fn fatal(str) -> ! ; - fn warn(str) ; - fn restrict(restriction) ; - fn get_restriction() -> restriction ; - fn get_file_type() -> file_type ; - fn get_cfg() -> ast::crate_cfg ; - fn get_span() -> span ; - fn get_lo_pos() -> uint ; - fn get_hi_pos() -> uint ; - fn get_last_lo_pos() -> uint ; - fn get_last_hi_pos() -> uint ; - fn get_prec_table() -> @[op_spec] ; - fn get_str(token::str_num) -> str ; - fn get_reader() -> lexer::reader ; - fn get_filemap() -> codemap::filemap ; - fn get_bad_expr_words() -> hashmap<str, ()> ; - fn get_chpos() -> uint ; - fn get_byte_pos() -> uint ; - fn get_id() -> node_id ; - fn get_sess() -> parse_sess ; + fn peek() -> token::token; + fn bump(); + fn swap(token::token, uint, uint); + fn look_ahead(uint) -> token::token; + fn fatal(str) -> ! ; + fn warn(str); + fn restrict(restriction); + fn get_restriction() -> restriction; + fn get_file_type() -> file_type; + fn get_cfg() -> ast::crate_cfg; + fn get_span() -> span; + fn get_lo_pos() -> uint; + fn get_hi_pos() -> uint; + fn get_last_lo_pos() -> uint; + fn get_last_hi_pos() -> uint; + fn get_prec_table() -> @[op_spec]; + fn get_str(token::str_num) -> str; + fn get_reader() -> lexer::reader; + fn get_filemap() -> codemap::filemap; + fn get_bad_expr_words() -> hashmap<str, ()>; + fn get_chpos() -> uint; + fn get_byte_pos() -> uint; + fn get_id() -> node_id; + fn get_sess() -> parse_sess; }; -fn new_parser_from_file(sess: parse_sess, cfg: - ast::crate_cfg, path: str, - chpos: uint, byte_pos: uint, - ftype: file_type) -> parser { +fn new_parser_from_file(sess: parse_sess, cfg: ast::crate_cfg, path: str, + chpos: uint, byte_pos: uint, ftype: file_type) -> + parser { let src = io::read_whole_file_str(path); let filemap = codemap::new_filemap(path, chpos, byte_pos); - sess.cm.files += ~[filemap]; + sess.cm.files += [filemap]; let itr = @interner::mk(str::hash, str::eq); let rdr = lexer::new_reader(sess.cm, src, filemap, itr); @@ -106,9 +105,9 @@ fn new_parser(sess: parse_sess, cfg: ast::crate_cfg, rdr: lexer::reader, while vec::len(buffer) < distance { let next = lexer::next_token(rdr); let sp = ast::mk_sp(next.chpos, rdr.get_chpos()); - buffer = ~[{tok: next.tok, span: sp}] + buffer; + buffer = [{tok: next.tok, span: sp}] + buffer; } - ret buffer.(distance - 1u).tok; + ret buffer[distance - 1u].tok; } fn fatal(m: str) -> ! { codemap::emit_error(some(self.get_span()), m, sess.cm); @@ -141,7 +140,7 @@ fn new_parser(sess: parse_sess, cfg: ast::crate_cfg, rdr: lexer::reader, let tok0 = lexer::next_token(rdr); let span0 = ast::mk_sp(tok0.chpos, rdr.get_chpos()); - ret stdio_parser(sess, cfg, ftype, tok0.tok, span0, span0, ~[], + ret stdio_parser(sess, cfg, ftype, tok0.tok, span0, span0, [], UNRESTRICTED, rdr, prec_table(), bad_expr_word_table()); } @@ -213,8 +212,7 @@ fn expect_gt(p: &parser) { } else if p.peek() == token::BINOP(token::LSR) { p.swap(token::GT, p.get_lo_pos() + 1u, p.get_hi_pos()); } else if p.peek() == token::BINOP(token::ASR) { - p.swap(token::BINOP(token::LSR), p.get_lo_pos() + 1u, - p.get_hi_pos()); + p.swap(token::BINOP(token::LSR), p.get_lo_pos() + 1u, p.get_hi_pos()); } else { let s: str = "expecting "; s += token::to_str(p.get_reader(), token::GT); @@ -304,7 +302,7 @@ fn parse_ty_fn(proto: ast::proto, p: &parser) -> ast::ty_ { parse_fn_input_ty, p); // FIXME: there's no syntax for this right now anyway // auto constrs = parse_constrs(~[], p); - let constrs: [@ast::constr] = ~[]; + let constrs: [@ast::constr] = []; let output: @ast::ty; let cf = ast::return; if p.peek() == token::RARROW { @@ -324,11 +322,11 @@ fn parse_ty_fn(proto: ast::proto, p: &parser) -> ast::ty_ { fn parse_proto(p: &parser) -> ast::proto { if eat_word(p, "iter") { ret ast::proto_iter; - } else if (eat_word(p, "fn")) { + } else if eat_word(p, "fn") { ret ast::proto_fn; - } else if (eat_word(p, "block")) { + } else if eat_word(p, "block") { ret ast::proto_block; - } else if (eat_word(p, "pred")) { + } else if eat_word(p, "pred") { ret ast::proto_fn; } else { unexpected(p, p.peek()); } } @@ -431,10 +429,10 @@ fn parse_constr_in_type(p: &parser) -> @ast::ty_constr { fn parse_constrs<T>(pser: fn(&parser) -> @ast::constr_general<T>, p: &parser) -> [@ast::constr_general<T>] { - let constrs: [@ast::constr_general<T>] = ~[]; + let constrs: [@ast::constr_general<T>] = []; while true { let constr = pser(p); - constrs += ~[constr]; + constrs += [constr]; if p.peek() == token::COMMA { p.bump(); } else { break; } } constrs @@ -445,7 +443,7 @@ fn parse_type_constraints(p: &parser) -> [@ast::ty_constr] { } fn parse_ty_postfix(orig_t: ast::ty_, p: &parser, colons_before_params: bool) - -> @ast::ty { + -> @ast::ty { let lo = p.get_lo_pos(); if colons_before_params && p.peek() == token::MOD_SEP { @@ -453,9 +451,7 @@ fn parse_ty_postfix(orig_t: ast::ty_, p: &parser, colons_before_params: bool) expect(p, token::LT); } else if !colons_before_params && p.peek() == token::LT { p.bump(); - } else { - ret @spanned(lo, p.get_lo_pos(), orig_t); - } + } else { ret @spanned(lo, p.get_lo_pos(), orig_t); } // If we're here, we have explicit type parameter instantiation. let seq = parse_seq_to_gt(some(token::COMMA), bind parse_ty(_, false), p); @@ -469,9 +465,7 @@ fn parse_ty_postfix(orig_t: ast::ty_, p: &parser, colons_before_params: bool) idents: pth.node.idents, types: seq}), ann)); } - _ { - p.fatal("type parameter instantiation only allowed for paths"); - } + _ { p.fatal("type parameter instantiation only allowed for paths"); } } } @@ -490,73 +484,71 @@ fn parse_ty(p: &parser, colons_before_params: bool) -> @ast::ty { if eat_word(p, "bool") { t = ast::ty_bool; - } else if (eat_word(p, "int")) { + } else if eat_word(p, "int") { t = ast::ty_int; - } else if (eat_word(p, "uint")) { + } else if eat_word(p, "uint") { t = ast::ty_uint; - } else if (eat_word(p, "float")) { + } else if eat_word(p, "float") { t = ast::ty_float; - } else if (eat_word(p, "str")) { + } else if eat_word(p, "str") { t = ast::ty_str; - } else if (eat_word(p, "istr")) { + } else if eat_word(p, "istr") { t = ast::ty_istr; - } else if (eat_word(p, "char")) { + } else if eat_word(p, "char") { t = ast::ty_char; -/* - } else if (eat_word(p, "task")) { - t = ast::ty_task; -*/ - } else if (eat_word(p, "i8")) { + /* + } else if (eat_word(p, "task")) { + t = ast::ty_task; + */ + } else if eat_word(p, "i8") { t = ast::ty_machine(ast::ty_i8); - } else if (eat_word(p, "i16")) { + } else if eat_word(p, "i16") { t = ast::ty_machine(ast::ty_i16); - } else if (eat_word(p, "i32")) { + } else if eat_word(p, "i32") { t = ast::ty_machine(ast::ty_i32); - } else if (eat_word(p, "i64")) { + } else if eat_word(p, "i64") { t = ast::ty_machine(ast::ty_i64); - } else if (eat_word(p, "u8")) { + } else if eat_word(p, "u8") { t = ast::ty_machine(ast::ty_u8); - } else if (eat_word(p, "u16")) { + } else if eat_word(p, "u16") { t = ast::ty_machine(ast::ty_u16); - } else if (eat_word(p, "u32")) { + } else if eat_word(p, "u32") { t = ast::ty_machine(ast::ty_u32); - } else if (eat_word(p, "u64")) { + } else if eat_word(p, "u64") { t = ast::ty_machine(ast::ty_u64); - } else if (eat_word(p, "f32")) { + } else if eat_word(p, "f32") { t = ast::ty_machine(ast::ty_f32); - } else if (eat_word(p, "f64")) { + } else if eat_word(p, "f64") { t = ast::ty_machine(ast::ty_f64); - } else if (p.peek() == token::LPAREN) { + } else if p.peek() == token::LPAREN { p.bump(); if p.peek() == token::RPAREN { hi = p.get_hi_pos(); p.bump(); t = ast::ty_nil; } else { - let ts = ~[parse_ty(p, false)]; + let ts = [parse_ty(p, false)]; while p.peek() == token::COMMA { p.bump(); - ts += ~[parse_ty(p, false)]; + ts += [parse_ty(p, false)]; } if vec::len(ts) == 1u { - t = ts.(0).node; - } else { - t = ast::ty_tup(ts); - } + t = ts[0].node; + } else { t = ast::ty_tup(ts); } hi = p.get_hi_pos(); expect(p, token::RPAREN); } - } else if (p.peek() == token::AT) { + } else if p.peek() == token::AT { p.bump(); let mt = parse_mt(p); hi = mt.ty.span.hi; t = ast::ty_box(mt); - } else if (p.peek() == token::BINOP(token::STAR)) { + } else if p.peek() == token::BINOP(token::STAR) { p.bump(); let mt = parse_mt(p); hi = mt.ty.span.hi; t = ast::ty_ptr(mt); - } else if (p.peek() == token::LBRACE) { + } else if p.peek() == token::LBRACE { let elems = parse_seq(token::LBRACE, token::RBRACE, some(token::COMMA), parse_ty_field, p); @@ -568,28 +560,28 @@ fn parse_ty(p: &parser, colons_before_params: bool) -> @ast::ty { ast::ty_constr(@spanned(lo, hi, t), parse_type_constraints(p)); } - } else if (p.peek() == token::LBRACKET) { + } else if p.peek() == token::LBRACKET { expect(p, token::LBRACKET); t = ast::ty_vec(parse_mt(p)); hi = p.get_hi_pos(); expect(p, token::RBRACKET); - } else if (eat_word(p, "fn")) { + } else if eat_word(p, "fn") { t = parse_ty_fn(ast::proto_fn, p); alt t { ast::ty_fn(_, _, out, _, _) { hi = out.span.hi; } } - } else if (eat_word(p, "block")) { + } else if eat_word(p, "block") { t = parse_ty_fn(ast::proto_block, p); alt t { ast::ty_fn(_, _, out, _, _) { hi = out.span.hi; } } - } else if (eat_word(p, "iter")) { + } else if eat_word(p, "iter") { t = parse_ty_fn(ast::proto_iter, p); alt t { ast::ty_fn(_, _, out, _, _) { hi = out.span.hi; } } - } else if (eat_word(p, "obj")) { + } else if eat_word(p, "obj") { t = parse_ty_obj(p, hi); - } else if (eat_word(p, "mutable")) { + } else if eat_word(p, "mutable") { p.warn("ignoring deprecated 'mutable' type constructor"); let typ = parse_ty(p, false); t = typ.node; hi = typ.span.hi; - } else if (p.peek() == token::MOD_SEP || is_ident(p.peek())) { + } else if p.peek() == token::MOD_SEP || is_ident(p.peek()) { let path = parse_path(p); t = ast::ty_path(path, p.get_id()); hi = path.span.hi; @@ -602,9 +594,7 @@ fn parse_arg_mode(p: &parser) -> ast::mode { ast::alias(eat_word(p, "mutable")) } else if eat(p, token::BINOP(token::MINUS)) { ast::move - } else { - ast::val - } + } else { ast::val } } fn parse_arg(p: &parser) -> ast::arg { @@ -625,15 +615,14 @@ fn parse_fn_block_arg(p: &parser) -> ast::arg { fn parse_seq_to_before_gt<T>(sep: option::t<token::token>, f: fn(&parser) -> T, p: &parser) -> [T] { let first = true; - let v = ~[]; - while p.peek() != token::GT && - p.peek() != token::BINOP(token::LSR) && - p.peek() != token::BINOP(token::ASR) { + let v = []; + while p.peek() != token::GT && p.peek() != token::BINOP(token::LSR) && + p.peek() != token::BINOP(token::ASR) { alt sep { some(t) { if first { first = false; } else { expect(p, t); } } _ { } } - v += ~[f(p)]; + v += [f(p)]; } ret v; @@ -658,30 +647,30 @@ fn parse_seq_lt_gt<T>(sep: option::t<token::token>, f: fn(&parser) -> T, } fn parse_seq_to_end<T>(ket: token::token, sep: option::t<token::token>, - f: fn(&parser) -> T , p: &parser) -> [T] { + f: fn(&parser) -> T, p: &parser) -> [T] { let val = parse_seq_to_before_end(ket, sep, f, p); p.bump(); ret val; } fn parse_seq_to_before_end<T>(ket: token::token, sep: option::t<token::token>, - f: fn(&parser) -> T , p: &parser) -> [T] { + f: fn(&parser) -> T, p: &parser) -> [T] { let first: bool = true; - let v: [T] = ~[]; + let v: [T] = []; while p.peek() != ket { alt sep { some(t) { if first { first = false; } else { expect(p, t); } } _ { } } - v += ~[f(p)]; + v += [f(p)]; } ret v; } fn parse_seq<T>(bra: token::token, ket: token::token, - sep: option::t<token::token>, f: fn(&parser) -> T , - p: &parser) -> spanned<[T]> { + sep: option::t<token::token>, f: fn(&parser) -> T, p: &parser) + -> spanned<[T]> { let lo = p.get_lo_pos(); expect(p, bra); let result = parse_seq_to_before_end::<T>(ket, sep, f, p); @@ -696,7 +685,7 @@ fn parse_lit(p: &parser) -> ast::lit { let lit: ast::lit_ = ast::lit_nil; if eat_word(p, "true") { lit = ast::lit_bool(true); - } else if (eat_word(p, "false")) { + } else if eat_word(p, "false") { lit = ast::lit_bool(false); } else { alt p.peek() { @@ -749,24 +738,22 @@ fn parse_path(p: &parser) -> ast::path { p.bump(); } else { global = false; } - let ids: [ast::ident] = ~[]; + let ids: [ast::ident] = []; while true { alt p.peek() { token::IDENT(i, _) { hi = p.get_hi_pos(); - ids += ~[p.get_str(i)]; + ids += [p.get_str(i)]; hi = p.get_hi_pos(); p.bump(); if p.peek() == token::MOD_SEP && p.look_ahead(1u) != token::LT { p.bump(); - } else { - break; - } + } else { break; } } _ { break; } } } - ret spanned(lo, hi, {global: global, idents: ids, types: ~[]}); + ret spanned(lo, hi, {global: global, idents: ids, types: []}); } fn parse_path_and_ty_param_substs(p: &parser) -> ast::path { @@ -775,8 +762,8 @@ fn parse_path_and_ty_param_substs(p: &parser) -> ast::path { if p.peek() == token::MOD_SEP { p.bump(); - let seq = parse_seq_lt_gt(some(token::COMMA), bind parse_ty(_, false), - p); + let seq = + parse_seq_lt_gt(some(token::COMMA), bind parse_ty(_, false), p); let hi = seq.span.hi; path = spanned(lo, hi, @@ -827,28 +814,23 @@ fn parse_bottom_expr(p: &parser) -> @ast::expr { let lit = @spanned(lo, hi, ast::lit_nil); ret mk_expr(p, lo, hi, ast::expr_lit(lit)); } - let es = ~[parse_expr(p)]; - while p.peek() == token::COMMA { - p.bump(); - es += ~[parse_expr(p)]; - } + let es = [parse_expr(p)]; + while p.peek() == token::COMMA { p.bump(); es += [parse_expr(p)]; } hi = p.get_hi_pos(); expect(p, token::RPAREN); if vec::len(es) == 1u { - ret mk_expr(p, lo, hi, es.(0).node); - } else { - ret mk_expr(p, lo, hi, ast::expr_tup(es)); - } - } else if (p.peek() == token::LBRACE) { + ret mk_expr(p, lo, hi, es[0].node); + } else { ret mk_expr(p, lo, hi, ast::expr_tup(es)); } + } else if p.peek() == token::LBRACE { p.bump(); if is_word(p, "mutable") || is_plain_ident(p) && p.look_ahead(1u) == token::COLON { - let fields = ~[parse_field(p, token::COLON)]; + let fields = [parse_field(p, token::COLON)]; let base = none; while p.peek() != token::RBRACE { if eat_word(p, "with") { base = some(parse_expr(p)); break; } expect(p, token::COMMA); - fields += ~[parse_field(p, token::COLON)]; + fields += [parse_field(p, token::COLON)]; } hi = p.get_hi_pos(); expect(p, token::RBRACE); @@ -859,48 +841,48 @@ fn parse_bottom_expr(p: &parser) -> @ast::expr { let blk = parse_block_tail(p, lo); ret mk_expr(p, blk.span.lo, blk.span.hi, ast::expr_block(blk)); } - } else if (eat_word(p, "if")) { + } else if eat_word(p, "if") { ret parse_if_expr(p); - } else if (eat_word(p, "for")) { + } else if eat_word(p, "for") { ret parse_for_expr(p); - } else if (eat_word(p, "while")) { + } else if eat_word(p, "while") { ret parse_while_expr(p); - } else if (eat_word(p, "do")) { + } else if eat_word(p, "do") { ret parse_do_while_expr(p); - } else if (eat_word(p, "alt")) { + } else if eat_word(p, "alt") { ret parse_alt_expr(p); -/* - } else if (eat_word(p, "spawn")) { - ret parse_spawn_expr(p); -*/ - } else if (eat_word(p, "fn")) { + /* + } else if (eat_word(p, "spawn")) { + ret parse_spawn_expr(p); + */ + } else if eat_word(p, "fn") { ret parse_fn_expr(p, ast::proto_fn); - } else if (eat_word(p, "block")) { + } else if eat_word(p, "block") { ret parse_fn_expr(p, ast::proto_block); - } else if (eat_word(p, "lambda")) { + } else if eat_word(p, "lambda") { ret parse_fn_expr(p, ast::proto_closure); - } else if (p.peek() == token::LBRACKET) { + } else if p.peek() == token::LBRACKET { p.bump(); let mut = parse_mutability(p); let es = parse_seq_to_end(token::RBRACKET, some(token::COMMA), parse_expr, p); ex = ast::expr_vec(es, mut); - } else if (p.peek() == token::POUND_LT) { + } else if p.peek() == token::POUND_LT { p.bump(); let ty = parse_ty(p, false); expect(p, token::GT); /* hack: early return to take advantage of specialized function */ ret mk_mac_expr(p, lo, p.get_hi_pos(), ast::mac_embed_type(ty)) - } else if (p.peek() == token::POUND_LBRACE) { + } else if p.peek() == token::POUND_LBRACE { p.bump(); let blk = ast::mac_embed_block(parse_block_tail(p, lo)); ret mk_mac_expr(p, lo, p.get_hi_pos(), blk); - } else if (p.peek() == token::ELLIPSIS) { + } else if p.peek() == token::ELLIPSIS { p.bump(); ret mk_mac_expr(p, lo, p.get_hi_pos(), ast::mac_ellipsis) - } else if (p.peek() == token::TILDE) { + } else if p.peek() == token::TILDE { p.bump(); alt p.peek() { token::LBRACKET. { // unique array (temporary) @@ -920,7 +902,7 @@ fn parse_bottom_expr(p: &parser) -> @ast::expr { } _ { ex = ast::expr_uniq(parse_expr(p)); } } - } else if (eat_word(p, "obj")) { + } else if eat_word(p, "obj") { // Anonymous object // Only make people type () if they're actually adding new fields @@ -931,13 +913,13 @@ fn parse_bottom_expr(p: &parser) -> @ast::expr { some(parse_seq_to_end(token::RPAREN, some(token::COMMA), parse_anon_obj_field, p)); } - let meths: [@ast::method] = ~[]; + let meths: [@ast::method] = []; let inner_obj: option::t<@ast::expr> = none; expect(p, token::LBRACE); while p.peek() != token::RBRACE { if eat_word(p, "with") { inner_obj = some(parse_expr(p)); - } else { meths += ~[parse_method(p)]; } + } else { meths += [parse_method(p)]; } } hi = p.get_hi_pos(); expect(p, token::RBRACE); @@ -949,7 +931,7 @@ fn parse_bottom_expr(p: &parser) -> @ast::expr { // "spanned". let ob = {fields: fields, methods: meths, inner_obj: inner_obj}; ex = ast::expr_anon_obj(ob); - } else if (eat_word(p, "bind")) { + } else if eat_word(p, "bind") { let e = parse_expr_res(p, RESTRICT_NO_CALL_EXPRS); fn parse_expr_opt(p: &parser) -> option::t<@ast::expr> { alt p.peek() { @@ -962,29 +944,29 @@ fn parse_bottom_expr(p: &parser) -> @ast::expr { parse_expr_opt, p); hi = es.span.hi; ex = ast::expr_bind(e, es.node); - } else if (p.peek() == token::POUND) { + } else if p.peek() == token::POUND { let ex_ext = parse_syntax_ext(p); hi = ex_ext.span.hi; ex = ex_ext.node; - } else if (eat_word(p, "fail")) { + } else if eat_word(p, "fail") { if can_begin_expr(p.peek()) { let e = parse_expr(p); hi = e.span.hi; ex = ast::expr_fail(some(e)); } else { ex = ast::expr_fail(none); } - } else if (eat_word(p, "log")) { + } else if eat_word(p, "log") { let e = parse_expr(p); ex = ast::expr_log(1, e); hi = e.span.hi; - } else if (eat_word(p, "log_err")) { + } else if eat_word(p, "log_err") { let e = parse_expr(p); ex = ast::expr_log(0, e); hi = e.span.hi; - } else if (eat_word(p, "assert")) { + } else if eat_word(p, "assert") { let e = parse_expr(p); ex = ast::expr_assert(e); hi = e.span.hi; - } else if (eat_word(p, "check")) { + } else if eat_word(p, "check") { /* Should be a predicate (pure boolean function) applied to arguments that are all either slot variables or literals. but the typechecker enforces that. */ @@ -992,7 +974,7 @@ fn parse_bottom_expr(p: &parser) -> @ast::expr { let e = parse_expr(p); hi = e.span.hi; ex = ast::expr_check(ast::checked, e); - } else if (eat_word(p, "claim")) { + } else if eat_word(p, "claim") { /* Same rules as check, except that if check-claims is enabled (a command-line flag), then the parser turns claims into check */ @@ -1000,19 +982,19 @@ fn parse_bottom_expr(p: &parser) -> @ast::expr { let e = parse_expr(p); hi = e.span.hi; ex = ast::expr_check(ast::unchecked, e); - } else if (eat_word(p, "ret")) { + } else if eat_word(p, "ret") { if can_begin_expr(p.peek()) { let e = parse_expr(p); hi = e.span.hi; ex = ast::expr_ret(some(e)); } else { ex = ast::expr_ret(none); } - } else if (eat_word(p, "break")) { + } else if eat_word(p, "break") { ex = ast::expr_break; hi = p.get_hi_pos(); - } else if (eat_word(p, "cont")) { + } else if eat_word(p, "cont") { ex = ast::expr_cont; hi = p.get_hi_pos(); - } else if (eat_word(p, "put")) { + } else if eat_word(p, "put") { alt p.peek() { token::SEMI. { ex = ast::expr_put(none); } _ { @@ -1021,18 +1003,19 @@ fn parse_bottom_expr(p: &parser) -> @ast::expr { ex = ast::expr_put(some(e)); } } - } else if (eat_word(p, "be")) { + } else if eat_word(p, "be") { let e = parse_expr(p); + // FIXME: Is this the right place for this check? if /*check*/ast::is_call_expr(e) { hi = e.span.hi; ex = ast::expr_be(e); } else { p.fatal("Non-call expression in tail call"); } - } else if (eat_word(p, "copy")) { + } else if eat_word(p, "copy") { let e = parse_expr(p); ex = ast::expr_copy(e); hi = e.span.hi; - } else if (eat_word(p, "self")) { + } else if eat_word(p, "self") { expect(p, token::DOT); // The rest is a call expression. let f: @ast::expr = parse_self_method(p); @@ -1041,9 +1024,9 @@ fn parse_bottom_expr(p: &parser) -> @ast::expr { parse_expr, p); hi = es.span.hi; ex = ast::expr_call(f, es.node); - } else if (p.peek() == token::MOD_SEP || - is_ident(p.peek()) && !is_word(p, "true") && - !is_word(p, "false")) { + } else if p.peek() == token::MOD_SEP || + is_ident(p.peek()) && !is_word(p, "true") && + !is_word(p, "false") { check_bad_word(p); let pth = parse_path_and_ty_param_substs(p); hi = pth.span.hi; @@ -1068,16 +1051,16 @@ fn parse_syntax_ext_naked(p: &parser, lo: uint) -> @ast::expr { p.fatal("expected a syntax expander name"); } //temporary for a backwards-compatible cycle: - let es = if p.peek() == token::LPAREN { - parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA), - parse_expr, p) - } else { - parse_seq(token::LBRACKET, token::RBRACKET, some(token::COMMA), - parse_expr, p) - }; + let es = + if p.peek() == token::LPAREN { + parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA), + parse_expr, p) + } else { + parse_seq(token::LBRACKET, token::RBRACKET, some(token::COMMA), + parse_expr, p) + }; let hi = es.span.hi; - let e = mk_expr(p, es.span.lo, hi, - ast::expr_vec(es.node, ast::imm)); + let e = mk_expr(p, es.span.lo, hi, ast::expr_vec(es.node, ast::imm)); ret mk_mac_expr(p, lo, hi, ast::mac_invoc(pth, e, none)); } @@ -1204,26 +1187,26 @@ type op_spec = {tok: token::token, op: ast::binop, prec: int}; // FIXME make this a const, don't store it in parser state fn prec_table() -> @[op_spec] { - ret @~[{tok: token::BINOP(token::STAR), op: ast::mul, prec: 11}, - {tok: token::BINOP(token::SLASH), op: ast::div, prec: 11}, - {tok: token::BINOP(token::PERCENT), op: ast::rem, prec: 11}, - {tok: token::BINOP(token::PLUS), op: ast::add, prec: 10}, - {tok: token::BINOP(token::MINUS), op: ast::sub, prec: 10}, - {tok: token::BINOP(token::LSL), op: ast::lsl, prec: 9}, - {tok: token::BINOP(token::LSR), op: ast::lsr, prec: 9}, - {tok: token::BINOP(token::ASR), op: ast::asr, prec: 9}, - {tok: token::BINOP(token::AND), op: ast::bitand, prec: 8}, - {tok: token::BINOP(token::CARET), op: ast::bitxor, prec: 6}, - {tok: token::BINOP(token::OR), op: ast::bitor, prec: 6}, - // 'as' sits between here with 5 - {tok: token::LT, op: ast::lt, prec: 4}, - {tok: token::LE, op: ast::le, prec: 4}, - {tok: token::GE, op: ast::ge, prec: 4}, - {tok: token::GT, op: ast::gt, prec: 4}, - {tok: token::EQEQ, op: ast::eq, prec: 3}, - {tok: token::NE, op: ast::ne, prec: 3}, - {tok: token::ANDAND, op: ast::and, prec: 2}, - {tok: token::OROR, op: ast::or, prec: 1}]; + ret @[{tok: token::BINOP(token::STAR), op: ast::mul, prec: 11}, + {tok: token::BINOP(token::SLASH), op: ast::div, prec: 11}, + {tok: token::BINOP(token::PERCENT), op: ast::rem, prec: 11}, + {tok: token::BINOP(token::PLUS), op: ast::add, prec: 10}, + {tok: token::BINOP(token::MINUS), op: ast::sub, prec: 10}, + {tok: token::BINOP(token::LSL), op: ast::lsl, prec: 9}, + {tok: token::BINOP(token::LSR), op: ast::lsr, prec: 9}, + {tok: token::BINOP(token::ASR), op: ast::asr, prec: 9}, + {tok: token::BINOP(token::AND), op: ast::bitand, prec: 8}, + {tok: token::BINOP(token::CARET), op: ast::bitxor, prec: 6}, + {tok: token::BINOP(token::OR), op: ast::bitor, prec: 6}, + // 'as' sits between here with 5 + {tok: token::LT, op: ast::lt, prec: 4}, + {tok: token::LE, op: ast::le, prec: 4}, + {tok: token::GE, op: ast::ge, prec: 4}, + {tok: token::GT, op: ast::gt, prec: 4}, + {tok: token::EQEQ, op: ast::eq, prec: 3}, + {tok: token::NE, op: ast::ne, prec: 3}, + {tok: token::ANDAND, op: ast::and, prec: 2}, + {tok: token::OROR, op: ast::or, prec: 1}]; } fn parse_binops(p: &parser) -> @ast::expr { @@ -1388,11 +1371,11 @@ fn parse_alt_expr(p: &parser) -> @ast::expr { let lo = p.get_last_lo_pos(); let discriminant = parse_expr(p); expect(p, token::LBRACE); - let arms: [ast::arm] = ~[]; + let arms: [ast::arm] = []; while p.peek() != token::RBRACE { let pats = parse_pats(p); let blk = parse_block(p); - arms += ~[{pats: pats, body: blk}]; + arms += [{pats: pats, body: blk}]; } let hi = p.get_hi_pos(); p.bump(); @@ -1422,6 +1405,7 @@ fn parse_initializer(p: &parser) -> option::t<ast::initializer> { ret some({op: ast::init_move, expr: parse_expr(p)}); } + // Now that the the channel is the first argument to receive, // combining it with an initializer doesn't really make sense. // case (token::RECV) { @@ -1436,9 +1420,9 @@ fn parse_initializer(p: &parser) -> option::t<ast::initializer> { } fn parse_pats(p: &parser) -> [@ast::pat] { - let pats = ~[]; + let pats = []; while true { - pats += ~[parse_pat(p)]; + pats += [parse_pat(p)]; if p.peek() == token::BINOP(token::OR) { p.bump(); } else { break; } } ret pats; @@ -1458,7 +1442,7 @@ fn parse_pat(p: &parser) -> @ast::pat { } token::LBRACE. { p.bump(); - let fields = ~[]; + let fields = []; let etc = false; let first = true; while p.peek() != token::RBRACE { @@ -1488,7 +1472,7 @@ fn parse_pat(p: &parser) -> @ast::pat { node: ast::pat_bind(fieldname), span: ast::mk_sp(lo, hi)}; } - fields += ~[{ident: fieldname, pat: subpat}]; + fields += [{ident: fieldname, pat: subpat}]; } hi = p.get_hi_pos(); p.bump(); @@ -1499,13 +1483,13 @@ fn parse_pat(p: &parser) -> @ast::pat { if p.peek() == token::RPAREN { hi = p.get_hi_pos(); p.bump(); - pat = ast::pat_lit(@{node: ast::lit_nil, - span: ast::mk_sp(lo,hi)}); + pat = + ast::pat_lit(@{node: ast::lit_nil, span: ast::mk_sp(lo, hi)}); } else { - let fields = ~[parse_pat(p)]; + let fields = [parse_pat(p)]; while p.peek() == token::COMMA { p.bump(); - fields += ~[parse_pat(p)]; + fields += [parse_pat(p)]; } if vec::len(fields) == 1u { expect(p, token::COMMA); } hi = p.get_hi_pos(); @@ -1518,13 +1502,13 @@ fn parse_pat(p: &parser) -> @ast::pat { let lit = parse_lit(p); hi = lit.span.hi; pat = ast::pat_lit(@lit); - } else if (is_plain_ident(p) && - alt p.look_ahead(1u) { - token::DOT. | token::LPAREN. | token::LBRACKET. { - false - } - _ { true } - }) { + } else if is_plain_ident(p) && + alt p.look_ahead(1u) { + token::DOT. | token::LPAREN. | token::LBRACKET. { + false + } + _ { true } + } { hi = p.get_hi_pos(); pat = ast::pat_bind(parse_value_ident(p)); } else { @@ -1539,7 +1523,7 @@ fn parse_pat(p: &parser) -> @ast::pat { args = a.node; hi = a.span.hi; } - token::DOT. { args = ~[]; p.bump(); } + token::DOT. { args = []; p.bump(); } _ { expect(p, token::LPAREN); fail; } } pat = ast::pat_tag(tag_path, args); @@ -1556,18 +1540,15 @@ fn parse_local(p: &parser, allow_init: bool) -> @ast::local { if eat(p, token::COLON) { ty = parse_ty(p, false); } let init = if allow_init { parse_initializer(p) } else { none }; ret @spanned(lo, p.get_last_hi_pos(), - {ty: ty, - pat: pat, - init: init, - id: p.get_id()}); + {ty: ty, pat: pat, init: init, id: p.get_id()}); } fn parse_let(p: &parser) -> @ast::decl { let lo = p.get_lo_pos(); - let locals = ~[parse_local(p, true)]; + let locals = [parse_local(p, true)]; while p.peek() == token::COMMA { p.bump(); - locals += ~[parse_local(p, true)]; + locals += [parse_local(p, true)]; } ret @spanned(lo, p.get_last_hi_pos(), ast::decl_local(locals)); } @@ -1579,7 +1560,7 @@ fn parse_stmt(p: &parser) -> @ast::stmt { } fn parse_crate_stmt(p: &parser) -> @ast::stmt { - let cdir = parse_crate_directive(p, ~[]); + let cdir = parse_crate_directive(p, []); ret @spanned(cdir.span.lo, cdir.span.hi, ast::stmt_crate_directive(@cdir)); } @@ -1593,7 +1574,7 @@ fn parse_source_stmt(p: &parser) -> @ast::stmt { let item_attrs; alt parse_outer_attrs_or_ext(p) { - none. { item_attrs = ~[]; } + none. { item_attrs = []; } some(left(attrs)) { item_attrs = attrs; } some(right(ext)) { ret @spanned(lo, ext.span.hi, ast::stmt_expr(ext, p.get_id())); @@ -1682,6 +1663,7 @@ fn stmt_ends_with_semi(stmt: &ast::stmt) -> bool { } } + // We should not be calling this on a cdir. ast::stmt_crate_directive(cdir) { fail; @@ -1697,7 +1679,7 @@ fn parse_block(p: &parser) -> ast::blk { // some blocks start with "#{"... fn parse_block_tail(p: &parser, lo: uint) -> ast::blk { - let stmts: [@ast::stmt] = ~[]; + let stmts: [@ast::stmt] = []; let expr: option::t<@ast::expr> = none; while p.peek() != token::RBRACE { alt p.peek() { @@ -1709,7 +1691,7 @@ fn parse_block_tail(p: &parser, lo: uint) -> ast::blk { alt stmt_to_expr(stmt) { some(e) { alt p.peek() { - token::SEMI. { p.bump(); stmts += ~[stmt]; } + token::SEMI. { p.bump(); stmts += [stmt]; } token::RBRACE. { expr = some(e); } t { if stmt_ends_with_semi(*stmt) { @@ -1717,13 +1699,13 @@ fn parse_block_tail(p: &parser, lo: uint) -> ast::blk { "expression but found " + token::to_str(p.get_reader(), t)); } - stmts += ~[stmt]; + stmts += [stmt]; } } } none. { // Not an expression statement. - stmts += ~[stmt]; + stmts += [stmt]; if p.get_file_type() == SOURCE_FILE && @@ -1742,16 +1724,17 @@ fn parse_block_tail(p: &parser, lo: uint) -> ast::blk { } fn parse_ty_param(p: &parser) -> ast::ty_param { - let k = alt p.peek() { - token::TILDE. { p.bump(); ast::kind_unique } - token::AT. { p.bump(); ast::kind_shared } - _ { ast::kind_pinned } - }; + let k = + alt p.peek() { + token::TILDE. { p.bump(); ast::kind_unique } + token::AT. { p.bump(); ast::kind_shared } + _ { ast::kind_pinned } + }; ret {ident: parse_ident(p), kind: k}; } fn parse_ty_params(p: &parser) -> [ast::ty_param] { - let ty_params: [ast::ty_param] = ~[]; + let ty_params: [ast::ty_param] = []; if p.peek() == token::LT { p.bump(); ty_params = parse_seq_to_gt(some(token::COMMA), parse_ty_param, p); @@ -1764,8 +1747,8 @@ fn parse_ty_params(p: &parser) -> [ast::ty_param] { ret ty_params; } -fn parse_fn_decl(p: &parser, purity: ast::purity, il: ast::inlineness) - -> ast::fn_decl { +fn parse_fn_decl(p: &parser, purity: ast::purity, il: ast::inlineness) -> + ast::fn_decl { let inputs: ast::spanned<[ast::arg]> = parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA), parse_arg, p); @@ -1773,7 +1756,7 @@ fn parse_fn_decl(p: &parser, purity: ast::purity, il: ast::inlineness) // Use the args list to translate each bound variable // mentioned in a constraint to an arg index. // Seems weird to do this in the parser, but I'm not sure how else to. - let constrs = ~[]; + let constrs = []; if p.peek() == token::COLON { p.bump(); constrs = parse_constrs(bind parse_ty_constr(inputs.node, _), p); @@ -1813,7 +1796,7 @@ fn parse_fn_block_decl(p: &parser) -> ast::fn_decl { purity: ast::impure_fn, il: ast::il_normal, cf: ast::return, - constraints: ~[]}; + constraints: []}; } fn parse_fn(p: &parser, proto: ast::proto, purity: ast::purity, @@ -1839,8 +1822,8 @@ fn mk_item(p: &parser, lo: uint, hi: uint, ident: &ast::ident, } fn parse_item_fn_or_iter(p: &parser, purity: ast::purity, proto: ast::proto, - attrs: &[ast::attribute], il: ast::inlineness) - -> @ast::item { + attrs: &[ast::attribute], il: ast::inlineness) -> + @ast::item { let lo = p.get_last_lo_pos(); let t = parse_fn_header(p); let f = parse_fn(p, proto, purity, il); @@ -1875,19 +1858,16 @@ fn parse_method(p: &parser) -> @ast::method { ret @spanned(lo, f.body.span.hi, meth); } -fn parse_item_obj(p: &parser, attrs: &[ast::attribute]) -> - @ast::item { +fn parse_item_obj(p: &parser, attrs: &[ast::attribute]) -> @ast::item { let lo = p.get_last_lo_pos(); let ident = parse_value_ident(p); let ty_params = parse_ty_params(p); let fields: ast::spanned<[ast::obj_field]> = parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA), parse_obj_field, p); - let meths: [@ast::method] = ~[]; + let meths: [@ast::method] = []; expect(p, token::LBRACE); - while p.peek() != token::RBRACE { - meths += ~[parse_method(p)]; - } + while p.peek() != token::RBRACE { meths += [parse_method(p)]; } let hi = p.get_hi_pos(); expect(p, token::RBRACE); let ob: ast::_obj = {fields: fields.node, methods: meths}; @@ -1895,8 +1875,7 @@ fn parse_item_obj(p: &parser, attrs: &[ast::attribute]) -> attrs); } -fn parse_item_res(p: &parser, attrs: &[ast::attribute]) -> - @ast::item { +fn parse_item_res(p: &parser, attrs: &[ast::attribute]) -> @ast::item { let lo = p.get_last_lo_pos(); let ident = parse_value_ident(p); let ty_params = parse_ty_params(p); @@ -1908,15 +1887,15 @@ fn parse_item_res(p: &parser, attrs: &[ast::attribute]) -> let dtor = parse_block(p); let decl = {inputs: - ~[{mode: ast::alias(false), - ty: t, - ident: arg_ident, - id: p.get_id()}], + [{mode: ast::alias(false), + ty: t, + ident: arg_ident, + id: p.get_id()}], output: @spanned(lo, lo, ast::ty_nil), purity: ast::impure_fn, il: ast::il_normal, cf: ast::return, - constraints: ~[]}; + constraints: []}; let f = {decl: decl, proto: ast::proto_fn, body: dtor}; ret mk_item(p, lo, dtor.span.hi, ident, ast::item_res(f, p.get_id(), ty_params, p.get_id()), attrs); @@ -1926,14 +1905,14 @@ fn parse_mod_items(p: &parser, term: token::token, first_item_attrs: &[ast::attribute]) -> ast::_mod { // Shouldn't be any view items since we've already parsed an item attr let view_items = - if vec::len(first_item_attrs) == 0u { parse_view(p) } else { ~[] }; - let items: [@ast::item] = ~[]; + if vec::len(first_item_attrs) == 0u { parse_view(p) } else { [] }; + let items: [@ast::item] = []; let initial_attrs = first_item_attrs; while p.peek() != term { let attrs = initial_attrs + parse_outer_attributes(p); - initial_attrs = ~[]; + initial_attrs = []; alt parse_item(p, attrs) { - some(i) { items += ~[i]; } + some(i) { items += [i]; } _ { p.fatal("expected item but found " + token::to_str(p.get_reader(), p.peek())); @@ -1999,25 +1978,25 @@ fn parse_native_item(p: &parser, attrs: &[ast::attribute]) -> @ast::native_item { if eat_word(p, "type") { ret parse_item_native_type(p, attrs); - } else if (eat_word(p, "fn")) { + } else if eat_word(p, "fn") { ret parse_item_native_fn(p, attrs); } else { unexpected(p, p.peek()); } } fn parse_native_mod_items(p: &parser, native_name: &str, abi: ast::native_abi, - first_item_attrs: &[ast::attribute]) - -> ast::native_mod { + first_item_attrs: &[ast::attribute]) -> + ast::native_mod { // Shouldn't be any view items since we've already parsed an item attr let view_items = if vec::len(first_item_attrs) == 0u { parse_native_view(p) - } else { ~[] }; - let items: [@ast::native_item] = ~[]; + } else { [] }; + let items: [@ast::native_item] = []; let initial_attrs = first_item_attrs; while p.peek() != token::RBRACE { let attrs = initial_attrs + parse_outer_attributes(p); - initial_attrs = ~[]; - items += ~[parse_native_item(p, attrs)]; + initial_attrs = []; + items += [parse_native_item(p, attrs)]; } ret {native_name: native_name, abi: abi, @@ -2031,13 +2010,13 @@ fn parse_item_native_mod(p: &parser, attrs: &[ast::attribute]) -> @ast::item { if !is_word(p, "mod") { let t = parse_str(p); if str::eq(t, "cdecl") { - } else if (str::eq(t, "rust")) { + } else if str::eq(t, "rust") { abi = ast::native_abi_rust; - } else if (str::eq(t, "llvm")) { + } else if str::eq(t, "llvm") { abi = ast::native_abi_llvm; - } else if (str::eq(t, "rust-intrinsic")) { + } else if str::eq(t, "rust-intrinsic") { abi = ast::native_abi_rust_intrinsic; - } else if (str::eq(t, "x86stdcall")) { + } else if str::eq(t, "x86stdcall") { abi = ast::native_abi_x86stdcall; } else { p.fatal("unsupported abi: " + t); } } @@ -2079,7 +2058,7 @@ fn parse_item_tag(p: &parser, attrs: &[ast::attribute]) -> @ast::item { let lo = p.get_last_lo_pos(); let id = parse_ident(p); let ty_params = parse_ty_params(p); - let variants: [ast::variant] = ~[]; + let variants: [ast::variant] = []; // Newtype syntax if p.peek() == token::EQ { if p.get_bad_expr_words().contains_key(id) { @@ -2091,10 +2070,10 @@ fn parse_item_tag(p: &parser, attrs: &[ast::attribute]) -> @ast::item { let variant = spanned(ty.span.lo, ty.span.hi, {name: id, - args: ~[{ty: ty, id: p.get_id()}], + args: [{ty: ty, id: p.get_id()}], id: p.get_id()}); ret mk_item(p, lo, ty.span.hi, id, - ast::item_tag(~[variant], ty_params), attrs); + ast::item_tag([variant], ty_params), attrs); } expect(p, token::LBRACE); while p.peek() != token::RBRACE { @@ -2104,7 +2083,7 @@ fn parse_item_tag(p: &parser, attrs: &[ast::attribute]) -> @ast::item { check_bad_word(p); let vlo = p.get_lo_pos(); p.bump(); - let args: [ast::variant_arg] = ~[]; + let args: [ast::variant_arg] = []; let vhi = p.get_hi_pos(); alt p.peek() { token::LPAREN. { @@ -2112,7 +2091,7 @@ fn parse_item_tag(p: &parser, attrs: &[ast::attribute]) -> @ast::item { parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA), bind parse_ty(_, false), p); for ty: @ast::ty in arg_tys.node { - args += ~[{ty: ty, id: p.get_id()}]; + args += [{ty: ty, id: p.get_id()}]; } vhi = arg_tys.span.hi; } @@ -2121,7 +2100,7 @@ fn parse_item_tag(p: &parser, attrs: &[ast::attribute]) -> @ast::item { expect(p, token::SEMI); p.get_id(); let vr = {name: p.get_str(name), args: args, id: p.get_id()}; - variants += ~[spanned(vlo, vhi, vr)]; + variants += [spanned(vlo, vhi, vr)]; } token::RBRACE. {/* empty */ } _ { @@ -2144,33 +2123,33 @@ fn parse_auth(p: &parser) -> ast::_auth { fn parse_item(p: &parser, attrs: &[ast::attribute]) -> option::t<@ast::item> { if eat_word(p, "const") { ret some(parse_item_const(p, attrs)); - } else if (eat_word(p, "inline")) { + } else if eat_word(p, "inline") { expect_word(p, "fn"); ret some(parse_item_fn_or_iter(p, ast::impure_fn, ast::proto_fn, attrs, ast::il_inline)); - } else if (is_word(p, "fn") && p.look_ahead(1u) != token::LPAREN) { + } else if is_word(p, "fn") && p.look_ahead(1u) != token::LPAREN { p.bump(); ret some(parse_item_fn_or_iter(p, ast::impure_fn, ast::proto_fn, attrs, ast::il_normal)); - } else if (eat_word(p, "pred")) { - ret some(parse_item_fn_or_iter(p, ast::pure_fn, ast::proto_fn, - attrs, ast::il_normal)); - } else if (eat_word(p, "iter")) { + } else if eat_word(p, "pred") { + ret some(parse_item_fn_or_iter(p, ast::pure_fn, ast::proto_fn, attrs, + ast::il_normal)); + } else if eat_word(p, "iter") { ret some(parse_item_fn_or_iter(p, ast::impure_fn, ast::proto_iter, attrs, ast::il_normal)); - } else if (eat_word(p, "mod")) { + } else if eat_word(p, "mod") { ret some(parse_item_mod(p, attrs)); - } else if (eat_word(p, "native")) { + } else if eat_word(p, "native") { ret some(parse_item_native_mod(p, attrs)); } if eat_word(p, "type") { ret some(parse_item_type(p, attrs)); - } else if (eat_word(p, "tag")) { + } else if eat_word(p, "tag") { ret some(parse_item_tag(p, attrs)); - } else if (is_word(p, "obj") && p.look_ahead(1u) != token::LPAREN) { + } else if is_word(p, "obj") && p.look_ahead(1u) != token::LPAREN { p.bump(); ret some(parse_item_obj(p, attrs)); - } else if (eat_word(p, "resource")) { + } else if eat_word(p, "resource") { ret some(parse_item_res(p, attrs)); } else { ret none; } } @@ -2185,8 +2164,8 @@ fn parse_outer_attrs_or_ext(p: &parser) -> attr_or_ext { p.bump(); if p.peek() == token::LBRACKET { let first_attr = parse_attribute_naked(p, ast::attr_outer, lo); - ret some(left(~[first_attr] + parse_outer_attributes(p))); - } else if (!(p.peek() == token::LT || p.peek() == token::LBRACKET)) { + ret some(left([first_attr] + parse_outer_attributes(p))); + } else if !(p.peek() == token::LT || p.peek() == token::LBRACKET) { ret some(right(parse_syntax_ext_naked(p, lo))); } else { ret none; } } else { ret none; } @@ -2194,9 +2173,9 @@ fn parse_outer_attrs_or_ext(p: &parser) -> attr_or_ext { // Parse attributes that appear before an item fn parse_outer_attributes(p: &parser) -> [ast::attribute] { - let attrs: [ast::attribute] = ~[]; + let attrs: [ast::attribute] = []; while p.peek() == token::POUND { - attrs += ~[parse_attribute(p, ast::attr_outer)]; + attrs += [parse_attribute(p, ast::attr_outer)]; } ret attrs; } @@ -2224,19 +2203,19 @@ fn parse_attribute_naked(p: &parser, style: ast::attr_style, lo: uint) -> // until we see the semi). fn parse_inner_attrs_and_next(p: &parser) -> {inner: [ast::attribute], next: [ast::attribute]} { - let inner_attrs: [ast::attribute] = ~[]; - let next_outer_attrs: [ast::attribute] = ~[]; + let inner_attrs: [ast::attribute] = []; + let next_outer_attrs: [ast::attribute] = []; while p.peek() == token::POUND { let attr = parse_attribute(p, ast::attr_inner); if p.peek() == token::SEMI { p.bump(); - inner_attrs += ~[attr]; + inner_attrs += [attr]; } else { // It's not really an inner attribute let outer_attr = spanned(attr.span.lo, attr.span.hi, {style: ast::attr_outer, value: attr.node.value}); - next_outer_attrs += ~[outer_attr]; + next_outer_attrs += [outer_attr]; break; } } @@ -2271,7 +2250,7 @@ fn parse_meta_seq(p: &parser) -> [@ast::meta_item] { } fn parse_optional_meta(p: &parser) -> [@ast::meta_item] { - alt p.peek() { token::LPAREN. { ret parse_meta_seq(p); } _ { ret ~[]; } } + alt p.peek() { token::LPAREN. { ret parse_meta_seq(p); } _ { ret []; } } } fn parse_use(p: &parser) -> ast::view_item_ { @@ -2283,16 +2262,14 @@ fn parse_use(p: &parser) -> ast::view_item_ { fn parse_rest_import_name(p: &parser, first: ast::ident, def_ident: option::t<ast::ident>) -> ast::view_item_ { - let identifiers: [ast::ident] = ~[first]; + let identifiers: [ast::ident] = [first]; let glob: bool = false; let from_idents = option::none::<[ast::import_ident]>; while true { alt p.peek() { token::SEMI. { break; } token::MOD_SEP. { - if glob { - p.fatal("cannot path into a glob"); - } + if glob { p.fatal("cannot path into a glob"); } if option::is_some(from_idents) { p.fatal("cannot path into import list"); } @@ -2301,7 +2278,8 @@ fn parse_rest_import_name(p: &parser, first: ast::ident, _ { p.fatal("expecting '::' or ';'"); } } alt p.peek() { - token::IDENT(_, _) { identifiers += ~[parse_ident(p)]; } + token::IDENT(_, _) { identifiers += [parse_ident(p)]; } + //the lexer can't tell the different kinds of stars apart ) : token::BINOP(token::STAR.) { @@ -2309,33 +2287,32 @@ fn parse_rest_import_name(p: &parser, first: ast::ident, p.bump(); } + token::LBRACE. { fn parse_import_ident(p: &parser) -> ast::import_ident { let lo = p.get_lo_pos(); let ident = parse_ident(p); let hi = p.get_hi_pos(); - ret spanned(lo, hi, {name: ident, - id: p.get_id()}); + ret spanned(lo, hi, {name: ident, id: p.get_id()}); } - let from_idents_ = parse_seq(token::LBRACE, - token::RBRACE, - some(token::COMMA), - parse_import_ident, - p).node; + let from_idents_ = + parse_seq(token::LBRACE, token::RBRACE, some(token::COMMA), + parse_import_ident, p).node; if vec::is_empty(from_idents_) { p.fatal("at least one import is required"); } from_idents = some(from_idents_); } - _ { p.fatal("expecting an identifier, or '*'"); } + + _ { + p.fatal("expecting an identifier, or '*'"); + } } } alt def_ident { some(i) { - if glob { - p.fatal("globbed imports can't be renamed"); - } + if glob { p.fatal("globbed imports can't be renamed"); } if option::is_some(from_idents) { p.fatal("can't rename import list"); } @@ -2350,7 +2327,7 @@ fn parse_rest_import_name(p: &parser, first: ast::ident, p.get_id()); } else { let len = vec::len(identifiers); - ret ast::view_item_import(identifiers.(len - 1u), identifiers, + ret ast::view_item_import(identifiers[len - 1u], identifiers, p.get_id()); } } @@ -2385,8 +2362,9 @@ fn parse_import(p: &parser) -> ast::view_item_ { } fn parse_export(p: &parser) -> ast::view_item_ { - let ids = parse_seq_to_before_end( - token::SEMI, option::some(token::COMMA), parse_ident, p); + let ids = + parse_seq_to_before_end(token::SEMI, option::some(token::COMMA), + parse_ident, p); ret ast::view_item_export(ids, p.get_id()); } @@ -2395,9 +2373,9 @@ fn parse_view_item(p: &parser) -> @ast::view_item { let the_item = if eat_word(p, "use") { parse_use(p) - } else if (eat_word(p, "import")) { + } else if eat_word(p, "import") { parse_import(p) - } else if (eat_word(p, "export")) { parse_export(p) } else { fail }; + } else if eat_word(p, "export") { parse_export(p) } else { fail }; let hi = p.get_lo_pos(); expect(p, token::SEMI); ret @spanned(lo, hi, the_item); @@ -2415,14 +2393,14 @@ fn is_view_item(p: &parser) -> bool { } fn parse_view(p: &parser) -> [@ast::view_item] { - let items: [@ast::view_item] = ~[]; - while is_view_item(p) { items += ~[parse_view_item(p)]; } + let items: [@ast::view_item] = []; + while is_view_item(p) { items += [parse_view_item(p)]; } ret items; } fn parse_native_view(p: &parser) -> [@ast::view_item] { - let items: [@ast::view_item] = ~[]; - while is_view_item(p) { items += ~[parse_view_item(p)]; } + let items: [@ast::view_item] = []; + while is_view_item(p) { items += [parse_view_item(p)]; } ret items; } @@ -2436,7 +2414,7 @@ fn parse_crate_from_source_str(name: &str, source: &str, cfg: &ast::crate_cfg, sess: &parse_sess) -> @ast::crate { let ftype = SOURCE_FILE; let filemap = codemap::new_filemap(name, 0u, 0u); - sess.cm.files += ~[filemap]; + sess.cm.files += [filemap]; let itr = @interner::mk(str::hash, str::eq); let rdr = lexer::new_reader(sess.cm, source, filemap, itr); let p = new_parser(sess, cfg, rdr, ftype); @@ -2444,14 +2422,13 @@ fn parse_crate_from_source_str(name: &str, source: &str, cfg: &ast::crate_cfg, } // Parses a source module as a crate -fn parse_crate_mod(p: &parser, _cfg: &ast::crate_cfg) -> - @ast::crate { +fn parse_crate_mod(p: &parser, _cfg: &ast::crate_cfg) -> @ast::crate { let lo = p.get_lo_pos(); let crate_attrs = parse_inner_attrs_and_next(p); let first_item_outer_attrs = crate_attrs.next; let m = parse_mod_items(p, token::EOF, first_item_outer_attrs); ret @spanned(lo, p.get_lo_pos(), - {directives: ~[], + {directives: [], module: m, attrs: crate_attrs.inner, config: p.get_cfg()}); @@ -2488,6 +2465,7 @@ fn parse_crate_directive(p: &parser, first_outer_attr: &[ast::attribute]) -> }; alt p.peek() { + // mod x = "foo.rs"; token::SEMI. { let hi = p.get_hi_pos(); @@ -2495,6 +2473,7 @@ fn parse_crate_directive(p: &parser, first_outer_attr: &[ast::attribute]) -> ret spanned(lo, hi, ast::cdir_src_mod(id, file_opt, outer_attrs)); } + // mod x = "foo_dir" { ...directives... } token::LBRACE. { p.bump(); @@ -2510,14 +2489,14 @@ fn parse_crate_directive(p: &parser, first_outer_attr: &[ast::attribute]) -> } t { unexpected(p, t); } } - } else if (eat_word(p, "auth")) { + } else if eat_word(p, "auth") { let n = parse_path(p); expect(p, token::EQ); let a = parse_auth(p); let hi = p.get_hi_pos(); expect(p, token::SEMI); ret spanned(lo, hi, ast::cdir_auth(n, a)); - } else if (is_view_item(p)) { + } else if is_view_item(p) { let vi = parse_view_item(p); ret spanned(lo, vi.span.hi, ast::cdir_view_item(vi)); } else { ret p.fatal("expected crate directive"); } @@ -2534,10 +2513,10 @@ fn parse_crate_directives(p: &parser, term: token::token, expect_word(p, "mod"); } - let cdirs: [@ast::crate_directive] = ~[]; + let cdirs: [@ast::crate_directive] = []; while p.peek() != term { let cdir = @parse_crate_directive(p, first_outer_attr); - cdirs += ~[cdir]; + cdirs += [cdir]; } ret cdirs; } @@ -2551,7 +2530,7 @@ fn parse_crate_from_crate_file(input: &str, cfg: &ast::crate_cfg, let crate_attrs = leading_attrs.inner; let first_cdir_attr = leading_attrs.next; let cdirs = parse_crate_directives(p, token::EOF, first_cdir_attr); - let deps: [str] = ~[]; + let deps: [str] = []; let cx = @{p: p, mode: eval::mode_parse, @@ -2570,15 +2549,14 @@ fn parse_crate_from_crate_file(input: &str, cfg: &ast::crate_cfg, config: p.get_cfg()}); } -fn parse_crate_from_file(input: &str, cfg: &ast::crate_cfg, - sess: &parse_sess) -> @ast::crate { +fn parse_crate_from_file(input: &str, cfg: &ast::crate_cfg, sess: &parse_sess) + -> @ast::crate { if str::ends_with(input, ".rc") { parse_crate_from_crate_file(input, cfg, sess) } else if str::ends_with(input, ".rs") { parse_crate_from_source_file(input, cfg, sess) } else { - codemap::emit_error(none, - "unknown input file type: " + input, + codemap::emit_error(none, "unknown input file type: " + input, sess.cm); fail } diff --git a/src/comp/syntax/parse/token.rs b/src/comp/syntax/parse/token.rs index 574684dc234..c974dc915c4 100644 --- a/src/comp/syntax/parse/token.rs +++ b/src/comp/syntax/parse/token.rs @@ -116,6 +116,7 @@ fn to_str(r: lexer::reader, t: token) -> str { BINOP(op) { ret binop_to_str(op); } BINOPEQ(op) { ret binop_to_str(op) + "="; } + /* Structural symbols */ AT. { ret "@"; @@ -140,6 +141,7 @@ fn to_str(r: lexer::reader, t: token) -> str { POUND_LBRACE. { ret "#{"; } POUND_LT. { ret "#<"; } + /* Literals */ LIT_INT(i) { ret int::to_str(i, 10u); @@ -165,6 +167,7 @@ fn to_str(r: lexer::reader, t: token) -> str { } LIT_BOOL(b) { if b { ret "true"; } else { ret "false"; } } + /* Name components */ IDENT(s, _) { ret interner::get::<str>(*r.get_interner(), s); diff --git a/src/comp/syntax/print/pp.rs b/src/comp/syntax/print/pp.rs index bd67c552cbb..adeccd4150c 100644 --- a/src/comp/syntax/print/pp.rs +++ b/src/comp/syntax/print/pp.rs @@ -66,7 +66,7 @@ tag token { STRING(str, int); BREAK(break_t); BEGIN(begin_t); END; EOF; } fn tok_str(t: token) -> str { alt t { - STRING(s, len) { ret #fmt("STR(%s,%d)", s, len); } + STRING(s, len) { ret #fmt["STR(%s,%d)", s, len]; } BREAK(_) { ret "BREAK"; } BEGIN(_) { ret "BEGIN"; } END. { ret "END"; } @@ -84,7 +84,7 @@ fn buf_str(toks: &[mutable token], szs: &[mutable int], left: uint, while i != right && L != 0u { L -= 1u; if i != left { s += ", "; } - s += #fmt("%d=%s", szs.(i), tok_str(toks.(i))); + s += #fmt["%d=%s", szs[i], tok_str(toks[i])]; i += 1u; i %= n; } @@ -103,11 +103,11 @@ fn mk_printer(out: io::writer, linewidth: uint) -> printer { // fall behind. let n: uint = 3u * linewidth; - log #fmt("mk_printer %u", linewidth); + log #fmt["mk_printer %u", linewidth]; let token: [mutable token] = vec::init_elt_mut(EOF, n); let size: [mutable int] = vec::init_elt_mut(0, n); let scan_stack: [mutable uint] = vec::init_elt_mut(0u, n); - let print_stack: [print_stack_elt] = ~[]; + let print_stack: [print_stack_elt] = []; ret printer(out, n, linewidth as int, // margin linewidth as int, // space 0u, // left @@ -237,18 +237,18 @@ obj printer(out: io::writer, // buffered indentation to avoid writing trailing whitespace mutable pending_indentation: int) { - fn last_token() -> token { ret token.(right); } + fn last_token() -> token { ret token[right]; } // be very careful with this! - fn replace_last_token(t: token) { token.(right) = t; } + fn replace_last_token(t: token) { token[right] = t; } fn pretty_print(t: token) { - log #fmt("pp [%u,%u]", left, right); + log #fmt["pp [%u,%u]", left, right]; alt t { EOF. { if !scan_stack_empty { self.check_stack(0); - self.advance_left(token.(left), size.(left)); + self.advance_left(token[left], size[left]); } self.indent(0); } @@ -259,20 +259,20 @@ obj printer(out: io::writer, left = 0u; right = 0u; } else { self.advance_right(); } - log #fmt("pp BEGIN/buffer [%u,%u]", left, right); - token.(right) = t; - size.(right) = -right_total; + log #fmt["pp BEGIN/buffer [%u,%u]", left, right]; + token[right] = t; + size[right] = -right_total; self.scan_push(right); } END. { if scan_stack_empty { - log #fmt("pp END/print [%u,%u]", left, right); + log #fmt["pp END/print [%u,%u]", left, right]; self.print(t, 0); } else { - log #fmt("pp END/buffer [%u,%u]", left, right); + log #fmt["pp END/buffer [%u,%u]", left, right]; self.advance_right(); - token.(right) = t; - size.(right) = -1; + token[right] = t; + size[right] = -1; self.scan_push(right); } } @@ -283,22 +283,22 @@ obj printer(out: io::writer, left = 0u; right = 0u; } else { self.advance_right(); } - log #fmt("pp BREAK/buffer [%u,%u]", left, right); + log #fmt["pp BREAK/buffer [%u,%u]", left, right]; self.check_stack(0); self.scan_push(right); - token.(right) = t; - size.(right) = -right_total; + token[right] = t; + size[right] = -right_total; right_total += b.blank_space; } STRING(s, len) { if scan_stack_empty { - log #fmt("pp STRING/print [%u,%u]", left, right); + log #fmt["pp STRING/print [%u,%u]", left, right]; self.print(t, len); } else { - log #fmt("pp STRING/buffer [%u,%u]", left, right); + log #fmt["pp STRING/buffer [%u,%u]", left, right]; self.advance_right(); - token.(right) = t; - size.(right) = len; + token[right] = t; + size[right] = len; right_total += len; self.check_stream(); } @@ -306,43 +306,40 @@ obj printer(out: io::writer, } } fn check_stream() { - log #fmt("check_stream [%u, %u] with left_total=%d, right_total=%d", - left, right, left_total, right_total); + log #fmt["check_stream [%u, %u] with left_total=%d, right_total=%d", + left, right, left_total, right_total]; if right_total - left_total > space { - log #fmt("scan window is %d, longer than space on line (%d)", - right_total - left_total, space); + log #fmt["scan window is %d, longer than space on line (%d)", + right_total - left_total, space]; if !scan_stack_empty { - if left == scan_stack.(bottom) { - log #fmt("setting %u to infinity and popping", left); - size.(self.scan_pop_bottom()) = size_infinity; + if left == scan_stack[bottom] { + log #fmt["setting %u to infinity and popping", left]; + size[self.scan_pop_bottom()] = size_infinity; } } - self.advance_left(token.(left), size.(left)); + self.advance_left(token[left], size[left]); if left != right { self.check_stream(); } } } fn scan_push(x: uint) { - log #fmt("scan_push %u", x); + log #fmt["scan_push %u", x]; if scan_stack_empty { scan_stack_empty = false; } else { top += 1u; top %= buf_len; assert (top != bottom); } - scan_stack.(top) = x; + scan_stack[top] = x; } fn scan_pop() -> uint { assert (!scan_stack_empty); - let x = scan_stack.(top); + let x = scan_stack[top]; if top == bottom { scan_stack_empty = true; } else { top += buf_len - 1u; top %= buf_len; } ret x; } - fn scan_top() -> uint { - assert (!scan_stack_empty); - ret scan_stack.(top); - } + fn scan_top() -> uint { assert (!scan_stack_empty); ret scan_stack[top]; } fn scan_pop_bottom() -> uint { assert (!scan_stack_empty); - let x = scan_stack.(bottom); + let x = scan_stack[bottom]; if top == bottom { scan_stack_empty = true; } else { bottom += 1u; bottom %= buf_len; } @@ -354,7 +351,7 @@ obj printer(out: io::writer, assert (right != left); } fn advance_left(x: token, L: int) { - log #fmt("advnce_left [%u,%u], sizeof(%u)=%d", left, right, left, L); + log #fmt["advnce_left [%u,%u], sizeof(%u)=%d", left, right, left, L]; if L >= 0 { self.print(x, L); alt x { @@ -365,47 +362,47 @@ obj printer(out: io::writer, if left != right { left += 1u; left %= buf_len; - self.advance_left(token.(left), size.(left)); + self.advance_left(token[left], size[left]); } } } fn check_stack(k: int) { if !scan_stack_empty { let x = self.scan_top(); - alt token.(x) { + alt token[x] { BEGIN(b) { if k > 0 { - size.(self.scan_pop()) = size.(x) + right_total; + size[self.scan_pop()] = size[x] + right_total; self.check_stack(k - 1); } } END. { // paper says + not =, but that makes no sense. - size.(self.scan_pop()) = 1; + size[self.scan_pop()] = 1; self.check_stack(k + 1); } _ { - size.(self.scan_pop()) = size.(x) + right_total; + size[self.scan_pop()] = size[x] + right_total; if k > 0 { self.check_stack(k); } } } } } fn print_newline(amount: int) { - log #fmt("NEWLINE %d", amount); + log #fmt["NEWLINE %d", amount]; out.write_str("\n"); pending_indentation = 0; self.indent(amount); } fn indent(amount: int) { - log #fmt("INDENT %d", amount); + log #fmt["INDENT %d", amount]; pending_indentation += amount; } fn top() -> print_stack_elt { let n = vec::len(print_stack); let top: print_stack_elt = {offset: 0, pbreak: broken(inconsistent)}; - if n != 0u { top = print_stack.(n - 1u); } + if n != 0u { top = print_stack[n - 1u]; } ret top; } fn write_str(s: str) { @@ -416,18 +413,18 @@ obj printer(out: io::writer, out.write_str(s); } fn print(x: token, L: int) { - log #fmt("print %s %d (remaining line space=%d)", tok_str(x), L, - space); + log #fmt["print %s %d (remaining line space=%d)", tok_str(x), L, + space]; log buf_str(token, size, left, right, 6u); alt x { BEGIN(b) { if L > space { let col = margin - space + b.offset; - log #fmt("print BEGIN -> push broken block at col %d", col); - print_stack += ~[{offset: col, pbreak: broken(b.breaks)}]; + log #fmt["print BEGIN -> push broken block at col %d", col]; + print_stack += [{offset: col, pbreak: broken(b.breaks)}]; } else { log "print BEGIN -> push fitting block"; - print_stack += ~[{offset: 0, pbreak: fits}]; + print_stack += [{offset: 0, pbreak: fits}]; } } END. { diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs index 0e23928699e..c0e38a3b40e 100644 --- a/src/comp/syntax/print/pprust.rs +++ b/src/comp/syntax/print/pprust.rs @@ -32,7 +32,7 @@ tag ann_node { node_expr(ps, @ast::expr); node_pat(ps, @ast::pat); } -type pp_ann = {pre: fn(&ann_node) , post: fn(&ann_node) }; +type pp_ann = {pre: fn(&ann_node), post: fn(&ann_node)}; fn no_ann() -> pp_ann { fn ignore(_node: &ann_node) { } @@ -49,12 +49,12 @@ type ps = mutable boxes: [pp::breaks], ann: pp_ann}; -fn ibox(s: &ps, u: uint) { s.boxes += ~[pp::inconsistent]; pp::ibox(s.s, u); } +fn ibox(s: &ps, u: uint) { s.boxes += [pp::inconsistent]; pp::ibox(s.s, u); } fn end(s: &ps) { vec::pop(s.boxes); pp::end(s.s); } fn rust_printer(writer: io::writer) -> ps { - let boxes: [pp::breaks] = ~[]; + let boxes: [pp::breaks] = []; ret @{s: pp::mk_printer(writer, default_columns), cm: none::<codemap>, comments: none::<[lexer::cmnt]>, @@ -75,7 +75,7 @@ const default_columns: uint = 78u; // copy forward. fn print_crate(cm: &codemap, crate: @ast::crate, filename: str, in: io::reader, out: io::writer, ann: &pp_ann) { - let boxes: [pp::breaks] = ~[]; + let boxes: [pp::breaks] = []; let r = lexer::gather_comments_and_literals(cm, filename, in); let s = @{s: pp::mk_printer(out, default_columns), @@ -135,12 +135,9 @@ fn attribute_to_str(attr: &ast::attribute) -> str { be to_str(attr, print_attribute); } -fn cbox(s: &ps, u: uint) { s.boxes += ~[pp::consistent]; pp::cbox(s.s, u); } +fn cbox(s: &ps, u: uint) { s.boxes += [pp::consistent]; pp::cbox(s.s, u); } -fn box(s: &ps, u: uint, b: pp::breaks) { - s.boxes += ~[b]; - pp::box(s.s, u, b); -} +fn box(s: &ps, u: uint, b: pp::breaks) { s.boxes += [b]; pp::box(s.s, u, b); } fn nbsp(s: &ps) { word(s.s, " "); } @@ -175,22 +172,16 @@ fn bclose_(s: &ps, span: codemap::span, indented: uint) { fn bclose(s: &ps, span: codemap::span) { bclose_(s, span, indent_unit); } fn is_begin(s: &ps) -> bool { - alt s.s.last_token() { - pp::BEGIN(_) { true } - _ { false } - } + alt s.s.last_token() { pp::BEGIN(_) { true } _ { false } } } fn is_end(s: &ps) -> bool { - alt s.s.last_token() { - pp::END. { true } - _ { false } - } + alt s.s.last_token() { pp::END. { true } _ { false } } } fn is_bol(s: &ps) -> bool { ret s.s.last_token() == pp::EOF || - s.s.last_token() == pp::hardbreak_tok(); + s.s.last_token() == pp::hardbreak_tok(); } fn hardbreak_if_not_bol(s: &ps) { if !is_bol(s) { hardbreak(s.s); } } @@ -218,7 +209,7 @@ fn synth_comment(s: &ps, text: str) { word(s.s, "*/"); } -fn commasep<IN>(s: &ps, b: breaks, elts: &[IN], op: fn(&ps, &IN) ) { +fn commasep<IN>(s: &ps, b: breaks, elts: &[IN], op: fn(&ps, &IN)) { box(s, 0u, b); let first = true; for elt: IN in elts { @@ -229,8 +220,8 @@ fn commasep<IN>(s: &ps, b: breaks, elts: &[IN], op: fn(&ps, &IN) ) { } -fn commasep_cmnt<IN>(s: &ps, b: breaks, elts: &[IN], op: fn(&ps, &IN) , - get_span: fn(&IN) -> codemap::span ) { +fn commasep_cmnt<IN>(s: &ps, b: breaks, elts: &[IN], op: fn(&ps, &IN), + get_span: fn(&IN) -> codemap::span) { box(s, 0u, b); let len = vec::len::<IN>(elts); let i = 0u; @@ -241,7 +232,7 @@ fn commasep_cmnt<IN>(s: &ps, b: breaks, elts: &[IN], op: fn(&ps, &IN) , if i < len { word(s.s, ","); maybe_print_trailing_comment(s, get_span(elt), - some(get_span(elts.(i)).hi)); + some(get_span(elts[i]).hi)); space_if_not_bol(s); } } @@ -290,7 +281,7 @@ fn print_type(s: &ps, ty: &@ast::ty) { alt mt.mut { ast::mut. { word_space(s, "mutable"); } ast::maybe_mut. { word_space(s, "mutable?"); } - ast::imm. {} + ast::imm. { } } print_type(s, mt.ty); word(s.s, "]"); @@ -322,9 +313,9 @@ fn print_type(s: &ps, ty: &@ast::ty) { word(s.s, "}"); } ast::ty_tup(elts) { - popen(s); - commasep(s, inconsistent, elts, print_type); - pclose(s); + popen(s); + commasep(s, inconsistent, elts, print_type); + pclose(s); } ast::ty_fn(proto, inputs, output, cf, constrs) { print_ty_fn(s, proto, none::<str>, inputs, output, cf, constrs); @@ -371,6 +362,7 @@ fn print_native_item(s: &ps, item: &@ast::native_item) { } + ast::native_item_fn(lname, decl, typarams) { print_fn(s, decl, ast::proto_fn, item.ident, typarams, decl.constraints); @@ -457,8 +449,8 @@ fn print_item(s: &ps, item: &@ast::item) { ast::item_tag(variants, params) { let newtype = vec::len(variants) == 1u && - str::eq(item.ident, variants.(0).node.name) && - vec::len(variants.(0).node.args) == 1u; + str::eq(item.ident, variants[0].node.name) && + vec::len(variants[0].node.args) == 1u; if newtype { ibox(s, indent_unit); word_space(s, "tag"); @@ -468,7 +460,7 @@ fn print_item(s: &ps, item: &@ast::item) { space(s.s); if newtype { word_space(s, "="); - print_type(s, variants.(0).node.args.(0).ty); + print_type(s, variants[0].node.args[0].ty); word(s.s, ";"); end(s); } else { @@ -509,11 +501,11 @@ fn print_item(s: &ps, item: &@ast::item) { space(s.s); bopen(s); for meth: @ast::method in _obj.methods { - let typarams: [ast::ty_param] = ~[]; + let typarams: [ast::ty_param] = []; hardbreak_if_not_bol(s); maybe_print_comment(s, meth.span.lo); print_fn(s, meth.node.meth.decl, meth.node.meth.proto, - meth.node.ident, typarams, ~[]); + meth.node.ident, typarams, []); word(s.s, " "); print_block(s, meth.node.meth.body); } @@ -524,8 +516,8 @@ fn print_item(s: &ps, item: &@ast::item) { word(s.s, item.ident); print_type_params(s, tps); popen(s); - word_space(s, dt.decl.inputs.(0).ident + ":"); - print_type(s, dt.decl.inputs.(0).ty); + word_space(s, dt.decl.inputs[0].ident + ":"); + print_type(s, dt.decl.inputs[0].ty); pclose(s); space(s.s); print_block(s, dt.body); @@ -620,85 +612,77 @@ fn print_possibly_embedded_block(s: &ps, blk: &ast::blk, embedded: embed_type, // extra semi to make sure the output retains the same meaning. fn maybe_protect_block(s: &ps, last: &option::t<@ast::stmt>, next: &expr_or_stmt) { - let last_expr_is_block = alt last { - option::some(@{node: ast::stmt_expr(e, _), _}) { - alt e.node { - ast::expr_if(_ ,_ ,_) - | ast::expr_alt(_, _) - | ast::expr_block(_) { true } + let last_expr_is_block = + alt last { + option::some(@{node: ast::stmt_expr(e, _), _}) { + alt e.node { + ast::expr_if(_, _, _) | ast::expr_alt(_, _) | + ast::expr_block(_) { + true + } + _ { false } + } + true + } _ { false } - } - true - } - _ { false } - }; + }; if !last_expr_is_block { ret; } - let next_expr_is_ambig = alt next { - expr_(e) { expr_is_ambig(e) } - stmt_(@{node: ast::stmt_expr(e, _), _}) { - expr_is_ambig(e) - } - _ { false } - }; + let next_expr_is_ambig = + alt next { + expr_(e) { expr_is_ambig(e) } + stmt_(@{node: ast::stmt_expr(e, _), _}) { expr_is_ambig(e) } + _ { false } + }; - if last_expr_is_block && next_expr_is_ambig { - word(s.s, ";"); - } + if last_expr_is_block && next_expr_is_ambig { word(s.s, ";"); } fn expr_is_ambig(ex: @ast::expr) -> bool { - // We're going to walk the expression to the 'left' looking for - // various properties that might indicate ambiguity - - type env = @mutable bool; - let visitor = visit::mk_vt(@{ - visit_expr: visit_expr - with *visit::default_visitor() - }); - let env = @mutable false; - visit_expr(ex, env, visitor); - ret *env; - - fn visit_expr(ex: &@ast::expr, e: &env, v: &visit::vt<env>) { - assert *e == false; - - if expr_is_ambig(ex) { - *e = true; - ret; - } - - alt ex.node { - ast::expr_assign(x, _) { v.visit_expr(x, e, v); } - ast::expr_assign_op(_, x, _) { visit_expr(x, e, v); } - ast::expr_move(x, _) { v.visit_expr(x, e, v); } - ast::expr_field(x, _) { v.visit_expr(x, e, v); } - ast::expr_index(x, _) { v.visit_expr(x, e, v); } - ast::expr_binary(op, x, _) { - if need_parens(x, operator_prec(op)) { - *e = true; - ret; + // We're going to walk the expression to the 'left' looking for + // various properties that might indicate ambiguity + + type env = @mutable bool; + let visitor = + visit::mk_vt(@{visit_expr: visit_expr + with *visit::default_visitor()}); + let env = @mutable false; + visit_expr(ex, env, visitor); + ret *env; + + fn visit_expr(ex: &@ast::expr, e: &env, v: &visit::vt<env>) { + assert (*e == false); + + if expr_is_ambig(ex) { *e = true; ret; } + + alt ex.node { + ast::expr_assign(x, _) { v.visit_expr(x, e, v); } + ast::expr_assign_op(_, x, _) { visit_expr(x, e, v); } + ast::expr_move(x, _) { v.visit_expr(x, e, v); } + ast::expr_field(x, _) { v.visit_expr(x, e, v); } + ast::expr_index(x, _) { v.visit_expr(x, e, v); } + ast::expr_binary(op, x, _) { + if need_parens(x, operator_prec(op)) { *e = true; ret; } + v.visit_expr(x, e, v); } - v.visit_expr(x, e, v); - } - ast::expr_cast(x, _) { - if need_parens(x, parse::parser::as_prec) { - *e = true; - ret; + ast::expr_cast(x, _) { + if need_parens(x, parse::parser::as_prec) { + *e = true; + ret; + } } + ast::expr_ternary(x, _, _) { v.visit_expr(x, e, v); } + _ { } } - ast::expr_ternary(x, _, _) { v.visit_expr(x, e, v); } - _ { } - } - } + } - fn expr_is_ambig(ex: @ast::expr) -> bool { - alt ex.node { - ast::expr_unary(_, _) { true } - ast::expr_tup(_) { true } - _ { false } - } - } + fn expr_is_ambig(ex: @ast::expr) -> bool { + alt ex.node { + ast::expr_unary(_, _) { true } + ast::expr_tup(_) { true } + _ { false } + } + } } } } @@ -706,10 +690,8 @@ fn print_possibly_embedded_block(s: &ps, blk: &ast::blk, embedded: embed_type, // ret and fail, without arguments cannot appear is the discriminant of if, // alt, do, & while unambiguously without being parenthesized fn print_maybe_parens_discrim(s: &ps, e: &@ast::expr) { - let disambig = alt e.node { - ast::expr_ret(option::none.) { true } - _ { false } - }; + let disambig = + alt e.node { ast::expr_ret(option::none.) { true } _ { false } }; if disambig { popen(s) } print_expr(s, e); if disambig { pclose(s) } @@ -727,6 +709,7 @@ fn print_if(s: &ps, test: &@ast::expr, blk: &ast::blk, some(_else) { alt _else.node { + // "another else-if" ast::expr_if(i, t, e) { cbox(s, indent_unit - 1u); @@ -738,6 +721,7 @@ fn print_if(s: &ps, test: &@ast::expr, blk: &ast::blk, do_else(s, e); } + // "final else" ast::expr_block(b) { cbox(s, indent_unit - 1u); @@ -758,10 +742,7 @@ fn print_mac(s: &ps, m: &ast::mac) { ast::mac_invoc(path, arg, body) { word(s.s, "#"); print_path(s, path, false); - alt (arg.node) { - ast::expr_vec(_,_) {} - _ { word(s.s, " "); } - } + alt arg.node { ast::expr_vec(_, _) { } _ { word(s.s, " "); } } print_expr(s, arg); // FIXME: extension 'body' } @@ -930,6 +911,7 @@ fn print_expr(s: &ps, expr: &@ast::expr) { bclose_(s, expr.span, alt_indent_unit); } ast::expr_fn(f) { + // If the return type is the magic ty_infer, then we need to // pretty print as a lambda-block if f.decl.output.node == ast::ty_infer { @@ -939,11 +921,11 @@ fn print_expr(s: &ps, expr: &@ast::expr) { ibox(s, 0u); word(s.s, "{"); print_fn_block_args(s, f.decl); - print_possibly_embedded_block(s, f.body, - block_block_fn, indent_unit); + print_possibly_embedded_block(s, f.body, block_block_fn, + indent_unit); } else { head(s, proto_to_str(f.proto)); - print_fn_args_and_ret(s, f.decl, ~[]); + print_fn_args_and_ret(s, f.decl, []); space(s.s); print_block(s, f.body); } @@ -955,10 +937,7 @@ fn print_expr(s: &ps, expr: &@ast::expr) { ibox(s, 0u); print_block(s, blk); } - ast::expr_copy(e) { - word_space(s, "copy"); - print_expr(s, e); - } + ast::expr_copy(e) { word_space(s, "copy"); print_expr(s, e); } ast::expr_move(lhs, rhs) { print_expr(s, lhs); space(s.s); @@ -1070,11 +1049,11 @@ fn print_expr(s: &ps, expr: &@ast::expr) { // Methods for meth: @ast::method in anon_obj.methods { - let typarams: [ast::ty_param] = ~[]; + let typarams: [ast::ty_param] = []; hardbreak_if_not_bol(s); maybe_print_comment(s, meth.span.lo); print_fn(s, meth.node.meth.decl, meth.node.meth.proto, - meth.node.ident, typarams, ~[]); + meth.node.ident, typarams, []); word(s.s, " "); print_block(s, meth.node.meth.body); } @@ -1082,18 +1061,11 @@ fn print_expr(s: &ps, expr: &@ast::expr) { // With object alt anon_obj.inner_obj { none. { } - some(e) { - space(s.s); - word_space(s, "with"); - print_expr(s, e); - } + some(e) { space(s.s); word_space(s, "with"); print_expr(s, e); } } bclose(s, expr.span); } - ast::expr_uniq(expr) { - word(s.s, "~"); - print_expr(s, expr); - } + ast::expr_uniq(expr) { word(s.s, "~"); print_expr(s, expr); } } s.ann.post(ann_node); end(s); @@ -1224,7 +1196,7 @@ fn print_fn(s: &ps, decl: ast::fn_decl, proto: ast::proto, name: str, } fn print_fn_args_and_ret(s: &ps, decl: &ast::fn_decl, - constrs: [@ast::constr]) { + constrs: [@ast::constr]) { popen(s); fn print_arg(s: &ps, x: &ast::arg) { ibox(s, indent_unit); @@ -1270,7 +1242,7 @@ fn print_kind(s: &ps, kind: ast::kind) { alt kind { ast::kind_unique. { word(s.s, "~"); } ast::kind_shared. { word(s.s, "@"); } - _ { /* fallthrough */ } + _ {/* fallthrough */ } } } @@ -1320,7 +1292,7 @@ fn print_view_item(s: &ps, item: &@ast::view_item) { } ast::view_item_import(id, ids, _) { head(s, "import"); - if !str::eq(id, ids.(vec::len(ids) - 1u)) { + if !str::eq(id, ids[vec::len(ids) - 1u]) { word_space(s, id); word_space(s, "="); } @@ -1332,13 +1304,10 @@ fn print_view_item(s: &ps, item: &@ast::view_item) { } ast::view_item_import_from(mod_path, idents, _) { head(s, "import"); - for elt: str in mod_path { - word(s.s, elt); - word(s.s, "::"); - } + for elt: str in mod_path { word(s.s, elt); word(s.s, "::"); } word(s.s, "{"); commasep(s, inconsistent, idents, - fn(s: &ps, w: &ast::import_ident) { + fn (s: &ps, w: &ast::import_ident) { word(s.s, w.node.name) }); word(s.s, "}"); @@ -1354,8 +1323,7 @@ fn print_view_item(s: &ps, item: &@ast::view_item) { } ast::view_item_export(ids, _) { head(s, "export"); - commasep(s, inconsistent, ids, - fn(s: &ps, w: &str) { word(s.s, w) }); + commasep(s, inconsistent, ids, fn (s: &ps, w: &str) { word(s.s, w) }); } } word(s.s, ";"); @@ -1377,16 +1345,15 @@ fn operator_prec(op: ast::binop) -> int { fn need_parens(expr: &@ast::expr, outer_prec: int) -> bool { alt expr.node { - ast::expr_binary(op, _, _) { - operator_prec(op) < outer_prec - } + ast::expr_binary(op, _, _) { operator_prec(op) < outer_prec } ast::expr_cast(_, _) { parse::parser::as_prec < outer_prec } - ast::expr_ternary(_, _, _) { - parse::parser::ternary_prec < outer_prec - } + ast::expr_ternary(_, _, _) { parse::parser::ternary_prec < outer_prec } + // This may be too conservative in some cases - ast::expr_assign(_, _) { true } + ast::expr_assign(_, _) { + true + } ast::expr_move(_, _) { true } ast::expr_swap(_, _) { true } ast::expr_assign_op(_, _, _) { true } @@ -1485,7 +1452,7 @@ fn print_remaining_comments(s: &ps) { fn in_cbox(s: &ps) -> bool { let len = vec::len(s.boxes); if len == 0u { ret false; } - ret s.boxes.(len - 1u) == pp::consistent; + ret s.boxes[len - 1u] == pp::consistent; } fn print_literal(s: &ps, lit: &@ast::lit) { @@ -1502,8 +1469,9 @@ fn print_literal(s: &ps, lit: &@ast::lit) { print_string(s, st); } ast::lit_char(ch) { - word(s.s, "'" + escape_str( - str::unsafe_from_bytes(~[ch as u8]), '\'') + "'"); + word(s.s, + "'" + escape_str(str::unsafe_from_bytes([ch as u8]), '\'') + + "'"); } ast::lit_int(val) { word(s.s, int::str(val)); } ast::lit_uint(val) { word(s.s, uint::str(val) + "u"); } @@ -1530,7 +1498,7 @@ fn next_lit(s: &ps) -> option::t<lexer::lit> { alt s.literals { some(lits) { if s.cur_lit < vec::len(lits) { - ret some(lits.(s.cur_lit)); + ret some(lits[s.cur_lit]); } else { ret none::<lexer::lit>; } } _ { ret none::<lexer::lit>; } @@ -1556,7 +1524,7 @@ fn print_comment(s: &ps, cmnt: lexer::cmnt) { lexer::mixed. { assert (vec::len(cmnt.lines) == 1u); zerobreak(s.s); - word(s.s, cmnt.lines.(0)); + word(s.s, cmnt.lines[0]); zerobreak(s.s); } lexer::isolated. { @@ -1571,7 +1539,7 @@ fn print_comment(s: &ps, cmnt: lexer::cmnt) { lexer::trailing. { word(s.s, " "); if vec::len(cmnt.lines) == 1u { - word(s.s, cmnt.lines.(0)); + word(s.s, cmnt.lines[0]); hardbreak(s.s); } else { ibox(s, 0u); @@ -1584,10 +1552,11 @@ fn print_comment(s: &ps, cmnt: lexer::cmnt) { } lexer::blank_line. { // We need to do at least one, possibly two hardbreaks. - let is_semi = alt s.s.last_token() { - pp::STRING(s, _) { s == ";" } - _ { false } - }; + let is_semi = + alt s.s.last_token() { + pp::STRING(s, _) { s == ";" } + _ { false } + }; if is_semi || is_begin(s) || is_end(s) { hardbreak(s.s) } hardbreak(s.s); } @@ -1605,7 +1574,7 @@ fn escape_str(st: str, to_escape: char) -> str { let len = str::byte_len(st); let i = 0u; while i < len { - alt st.(i) as char { + alt st[i] as char { '\n' { out += "\\n"; } '\t' { out += "\\t"; } '\r' { out += "\\r"; } @@ -1622,7 +1591,7 @@ fn escape_str(st: str, to_escape: char) -> str { ret out; } -fn to_str<T>(t: &T, f: fn(&ps, &T) ) -> str { +fn to_str<T>(t: &T, f: fn(&ps, &T)) -> str { let writer = io::string_writer(); let s = rust_printer(writer.get_writer()); f(s, t); @@ -1634,7 +1603,7 @@ fn next_comment(s: &ps) -> option::t<lexer::cmnt> { alt s.comments { some(cmnts) { if s.cur_cmnt < vec::len(cmnts) { - ret some(cmnts.(s.cur_cmnt)); + ret some(cmnts[s.cur_cmnt]); } else { ret none::<lexer::cmnt>; } } _ { ret none::<lexer::cmnt>; } @@ -1643,8 +1612,8 @@ fn next_comment(s: &ps) -> option::t<lexer::cmnt> { // Removing the aliases from the type of f in the next two functions // triggers memory corruption, but I haven't isolated the bug yet. FIXME -fn constr_args_to_str<T>(f: &fn(&T) -> str , - args: &[@ast::sp_constr_arg<T>]) -> str { +fn constr_args_to_str<T>(f: &fn(&T) -> str, args: &[@ast::sp_constr_arg<T>]) + -> str { let comma = false; let s = "("; for a: @ast::sp_constr_arg<T> in args { @@ -1655,8 +1624,8 @@ fn constr_args_to_str<T>(f: &fn(&T) -> str , ret s; } -fn constr_arg_to_str<T>(f: &fn(&T) -> str, c: &ast::constr_arg_general_<T>) - -> str { +fn constr_arg_to_str<T>(f: &fn(&T) -> str, c: &ast::constr_arg_general_<T>) -> + str { alt c { ast::carg_base. { ret "*"; } ast::carg_ident(i) { ret f(i); } @@ -1686,7 +1655,7 @@ fn ast_ty_fn_constrs_str(constrs: &[@ast::constr]) -> str { } fn fn_arg_idx_to_str(decl: &ast::fn_decl, idx: &uint) -> str { - decl.inputs.(idx).ident + decl.inputs[idx].ident } fn ast_fn_constr_to_str(decl: &ast::fn_decl, c: &@ast::constr) -> str { @@ -1696,8 +1665,7 @@ fn ast_fn_constr_to_str(decl: &ast::fn_decl, c: &@ast::constr) -> str { } // FIXME: fix repeated code -fn ast_fn_constrs_str(decl: &ast::fn_decl, - constrs: &[@ast::constr]) -> str { +fn ast_fn_constrs_str(decl: &ast::fn_decl, constrs: &[@ast::constr]) -> str { let s = ""; let colon = true; for c: @ast::constr in constrs { @@ -1717,9 +1685,7 @@ fn proto_to_str(p: &ast::proto) -> str { } fn ty_constr_to_str(c: &@ast::ty_constr) -> str { - fn ty_constr_path_to_str(p: &ast::path) -> str { - "*." + path_to_str(p) - } + fn ty_constr_path_to_str(p: &ast::path) -> str { "*." + path_to_str(p) } ret path_to_str(c.node.path) + constr_args_to_str::<ast::path>(ty_constr_path_to_str, diff --git a/src/comp/syntax/util/interner.rs b/src/comp/syntax/util/interner.rs index 0b80bdd5bfd..31656886a45 100644 --- a/src/comp/syntax/util/interner.rs +++ b/src/comp/syntax/util/interner.rs @@ -18,7 +18,7 @@ type interner<T> = fn mk<@T>(hasher: hashfn<T>, eqer: eqfn<T>) -> interner<T> { let m = map::mk_hashmap::<T, uint>(hasher, eqer); - ret {map: m, mutable vect: ~[], hasher: hasher, eqer: eqer}; + ret {map: m, mutable vect: [], hasher: hasher, eqer: eqer}; } fn intern<@T>(itr: &interner<T>, val: &T) -> uint { @@ -27,13 +27,13 @@ fn intern<@T>(itr: &interner<T>, val: &T) -> uint { none. { let new_idx = vec::len::<T>(itr.vect); itr.map.insert(val, new_idx); - itr.vect += ~[val]; + itr.vect += [val]; ret new_idx; } } } -fn get<T>(itr: &interner<T>, idx: uint) -> T { ret itr.vect.(idx); } +fn get<T>(itr: &interner<T>, idx: uint) -> T { ret itr.vect[idx]; } -fn len<T>(itr : &interner<T>) -> uint { ret vec::len(itr.vect); } +fn len<T>(itr: &interner<T>) -> uint { ret vec::len(itr.vect); } diff --git a/src/comp/syntax/visit.rs b/src/comp/syntax/visit.rs index bd1064af843..350dfc3dd44 100644 --- a/src/comp/syntax/visit.rs +++ b/src/comp/syntax/visit.rs @@ -32,8 +32,7 @@ type visitor<E> = visit_expr: fn(&@expr, &E, &vt<E>), visit_ty: fn(&@ty, &E, &vt<E>), visit_constr: fn(&path, &span, node_id, &E, &vt<E>), - visit_fn: - fn(&_fn, &[ty_param], &span, &fn_ident, node_id, &E, &vt<E>) }; + visit_fn: fn(&_fn, &[ty_param], &span, &fn_ident, node_id, &E, &vt<E>)}; fn default_visitor<E>() -> visitor<E> { ret @{visit_mod: bind visit_mod::<E>(_, _, _, _), @@ -104,8 +103,8 @@ fn visit_item<E>(i: &@item, e: &E, v: &vt<E>) { item_obj(ob, _, _) { for f: obj_field in ob.fields { v.visit_ty(f.ty, e, v); } for m: @method in ob.methods { - v.visit_fn(m.node.meth, ~[], m.span, some(m.node.ident), - m.node.id, e, v); + v.visit_fn(m.node.meth, [], m.span, some(m.node.ident), m.node.id, + e, v); } } } @@ -132,9 +131,7 @@ fn visit_ty<E>(t: &@ty, e: &E, v: &vt<E>) { ty_rec(flds) { for f: ty_field in flds { v.visit_ty(f.node.mt.ty, e, v); } } - ty_tup(ts) { - for tt in ts { v.visit_ty(tt, e, v); } - } + ty_tup(ts) { for tt in ts { v.visit_ty(tt, e, v); } } ty_fn(_, args, out, _, constrs) { for a: ty_arg in args { v.visit_ty(a.node.ty, e, v); } for c: @constr in constrs { @@ -174,9 +171,7 @@ fn visit_pat<E>(p: &@pat, e: &E, v: &vt<E>) { pat_rec(fields, _) { for f: field_pat in fields { v.visit_pat(f.pat, e, v); } } - pat_tup(elts) { - for elt in elts { v.visit_pat(elt, e, v); } - } + pat_tup(elts) { for elt in elts { v.visit_pat(elt, e, v); } } pat_box(inner) { v.visit_pat(inner, e, v); } _ { } } @@ -249,9 +244,7 @@ fn visit_expr<E>(ex: &@expr, e: &E, v: &vt<E>) { for f: field in flds { v.visit_expr(f.node.expr, e, v); } visit_expr_opt(base, e, v); } - expr_tup(elts) { - for el in elts { v.visit_expr(el, e, v); } - } + expr_tup(elts) { for el in elts { v.visit_expr(el, e, v); } } expr_call(callee, args) { v.visit_expr(callee, e, v); visit_exprs(args, e, v); @@ -291,7 +284,7 @@ fn visit_expr<E>(ex: &@expr, e: &E, v: &vt<E>) { v.visit_expr(x, e, v); for a: arm in arms { v.visit_arm(a, e, v); } } - expr_fn(f) { v.visit_fn(f, ~[], ex.span, none, ex.id, e, v); } + expr_fn(f) { v.visit_fn(f, [], ex.span, none, ex.id, e, v); } expr_block(b) { v.visit_block(b, e, v); } expr_assign(a, b) { v.visit_expr(b, e, v); v.visit_expr(a, e, v); } expr_copy(a) { v.visit_expr(a, e, v); } @@ -328,8 +321,8 @@ fn visit_expr<E>(ex: &@expr, e: &E, v: &vt<E>) { some(ex) { v.visit_expr(ex, e, v); } } for m: @method in anon_obj.methods { - v.visit_fn(m.node.meth, ~[], m.span, some(m.node.ident), - m.node.id, e, v); + v.visit_fn(m.node.meth, [], m.span, some(m.node.ident), m.node.id, + e, v); } } expr_mac(mac) { visit_mac(mac, e, v); } @@ -348,20 +341,20 @@ fn visit_arm<E>(a: &arm, e: &E, v: &vt<E>) { type simple_visitor = // takes the components so that one function can be // generic over constr and ty_constr - @{visit_mod: fn(&_mod, &span) , - visit_view_item: fn(&@view_item) , - visit_native_item: fn(&@native_item) , - visit_item: fn(&@item) , - visit_local: fn(&@local) , - visit_block: fn(&ast::blk) , - visit_stmt: fn(&@stmt) , - visit_arm: fn(&arm) , - visit_pat: fn(&@pat) , - visit_decl: fn(&@decl) , - visit_expr: fn(&@expr) , - visit_ty: fn(&@ty) , - visit_constr: fn(&path, &span, node_id) , - visit_fn: fn(&_fn, &[ty_param], &span, &fn_ident, node_id) }; + @{visit_mod: fn(&_mod, &span), + visit_view_item: fn(&@view_item), + visit_native_item: fn(&@native_item), + visit_item: fn(&@item), + visit_local: fn(&@local), + visit_block: fn(&ast::blk), + visit_stmt: fn(&@stmt), + visit_arm: fn(&arm), + visit_pat: fn(&@pat), + visit_decl: fn(&@decl), + visit_expr: fn(&@expr), + visit_ty: fn(&@ty), + visit_constr: fn(&path, &span, node_id), + visit_fn: fn(&_fn, &[ty_param], &span, &fn_ident, node_id)}; fn default_simple_visitor() -> simple_visitor { ret @{visit_mod: fn (_m: &_mod, _sp: &span) { }, @@ -384,61 +377,61 @@ fn default_simple_visitor() -> simple_visitor { } fn mk_simple_visitor(v: &simple_visitor) -> vt<()> { - fn v_mod(f: fn(&_mod, &span) , m: &_mod, sp: &span, e: &(), v: &vt<()>) { + fn v_mod(f: fn(&_mod, &span), m: &_mod, sp: &span, e: &(), v: &vt<()>) { f(m, sp); visit_mod(m, sp, e, v); } - fn v_view_item(f: fn(&@view_item) , vi: &@view_item, e: &(), v: &vt<()>) { + fn v_view_item(f: fn(&@view_item), vi: &@view_item, e: &(), v: &vt<()>) { f(vi); visit_view_item(vi, e, v); } - fn v_native_item(f: fn(&@native_item) , ni: &@native_item, e: &(), + fn v_native_item(f: fn(&@native_item), ni: &@native_item, e: &(), v: &vt<()>) { f(ni); visit_native_item(ni, e, v); } - fn v_item(f: fn(&@item) , i: &@item, e: &(), v: &vt<()>) { + fn v_item(f: fn(&@item), i: &@item, e: &(), v: &vt<()>) { f(i); visit_item(i, e, v); } - fn v_local(f: fn(&@local) , l: &@local, e: &(), v: &vt<()>) { + fn v_local(f: fn(&@local), l: &@local, e: &(), v: &vt<()>) { f(l); visit_local(l, e, v); } - fn v_block(f: fn(&ast::blk) , bl: &ast::blk, e: &(), v: &vt<()>) { + fn v_block(f: fn(&ast::blk), bl: &ast::blk, e: &(), v: &vt<()>) { f(bl); visit_block(bl, e, v); } - fn v_stmt(f: fn(&@stmt) , st: &@stmt, e: &(), v: &vt<()>) { + fn v_stmt(f: fn(&@stmt), st: &@stmt, e: &(), v: &vt<()>) { f(st); visit_stmt(st, e, v); } - fn v_arm(f: fn(&arm) , a: &arm, e: &(), v: &vt<()>) { + fn v_arm(f: fn(&arm), a: &arm, e: &(), v: &vt<()>) { f(a); visit_arm(a, e, v); } - fn v_pat(f: fn(&@pat) , p: &@pat, e: &(), v: &vt<()>) { + fn v_pat(f: fn(&@pat), p: &@pat, e: &(), v: &vt<()>) { f(p); visit_pat(p, e, v); } - fn v_decl(f: fn(&@decl) , d: &@decl, e: &(), v: &vt<()>) { + fn v_decl(f: fn(&@decl), d: &@decl, e: &(), v: &vt<()>) { f(d); visit_decl(d, e, v); } - fn v_expr(f: fn(&@expr) , ex: &@expr, e: &(), v: &vt<()>) { + fn v_expr(f: fn(&@expr), ex: &@expr, e: &(), v: &vt<()>) { f(ex); visit_expr(ex, e, v); } - fn v_ty(f: fn(&@ty) , ty: &@ty, e: &(), v: &vt<()>) { + fn v_ty(f: fn(&@ty), ty: &@ty, e: &(), v: &vt<()>) { f(ty); visit_ty(ty, e, v); } - fn v_constr(f: fn(&path, &span, node_id) , pt: &path, sp: &span, + fn v_constr(f: fn(&path, &span, node_id), pt: &path, sp: &span, id: node_id, e: &(), v: &vt<()>) { f(pt, sp, id); visit_constr(pt, sp, id, e, v); } - fn v_fn(f: fn(&_fn, &[ty_param], &span, &fn_ident, node_id) , ff: &_fn, + fn v_fn(f: fn(&_fn, &[ty_param], &span, &fn_ident, node_id), ff: &_fn, tps: &[ty_param], sp: &span, ident: &fn_ident, id: node_id, e: &(), v: &vt<()>) { f(ff, tps, sp, ident, id); |
