diff options
| author | Brian Anderson <banderson@mozilla.com> | 2011-09-02 15:34:58 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2011-09-02 22:11:42 -0700 |
| commit | 5c49e4f4e92997869de1f75f9089c9db7e7a6ebe (patch) | |
| tree | 947f6d58da06e589a0ab0627319917a9d2352a8c /src/comp/syntax | |
| parent | b5f905342337a3dc12bdc5dc6d98d3ecdf60439d (diff) | |
Reformat. Issue #855
Diffstat (limited to 'src/comp/syntax')
| -rw-r--r-- | src/comp/syntax/ast.rs | 28 | ||||
| -rw-r--r-- | src/comp/syntax/ast_util.rs | 84 | ||||
| -rw-r--r-- | src/comp/syntax/codemap.rs | 70 | ||||
| -rw-r--r-- | src/comp/syntax/ext/base.rs | 47 | ||||
| -rw-r--r-- | src/comp/syntax/ext/concat_idents.rs | 8 | ||||
| -rw-r--r-- | src/comp/syntax/ext/env.rs | 16 | ||||
| -rw-r--r-- | src/comp/syntax/ext/expand.rs | 11 | ||||
| -rw-r--r-- | src/comp/syntax/ext/fmt.rs | 113 | ||||
| -rw-r--r-- | src/comp/syntax/ext/ident_to_str.rs | 8 | ||||
| -rw-r--r-- | src/comp/syntax/ext/log_syntax.rs | 5 | ||||
| -rw-r--r-- | src/comp/syntax/ext/simplext.rs | 127 | ||||
| -rw-r--r-- | src/comp/syntax/parse/eval.rs | 41 | ||||
| -rw-r--r-- | src/comp/syntax/parse/lexer.rs | 139 | ||||
| -rw-r--r-- | src/comp/syntax/parse/parser.rs | 473 | ||||
| -rw-r--r-- | src/comp/syntax/parse/token.rs | 122 | ||||
| -rw-r--r-- | src/comp/syntax/print/pp.rs | 61 | ||||
| -rw-r--r-- | src/comp/syntax/print/pprust.rs | 553 |
17 files changed, 888 insertions, 1018 deletions
diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs index a6d04451ba1..84d9c28cfe1 100644 --- a/src/comp/syntax/ast.rs +++ b/src/comp/syntax/ast.rs @@ -6,7 +6,7 @@ import codemap::filename; type spanned<T> = {node: T, span: span}; -type ident = istr; +type ident = str; // Functions may or may not have names. type fn_ident = option::t<ident>; @@ -43,7 +43,7 @@ tag def { def_use(def_id); def_native_ty(def_id); def_native_fn(def_id); - def_upvar(def_id, @def, bool /* writable */); + def_upvar(def_id, @def, /* writable */bool); } // The set of meta_items that define the compilation environment of the crate, @@ -78,8 +78,8 @@ tag meta_item_ { type blk = spanned<blk_>; -type blk_ = {stmts: [@stmt], expr: option::t<@expr>, - id: node_id, rules: check_mode}; +type blk_ = + {stmts: [@stmt], expr: option::t<@expr>, id: node_id, rules: check_mode}; type pat = {id: node_id, node: pat_, span: span}; @@ -229,7 +229,7 @@ tag blk_sort { type mac = spanned<mac_>; tag mac_ { - mac_invoc(path, @expr, option::t<istr>); + mac_invoc(path, @expr, option::t<str>); mac_embed_type(@ty); mac_embed_block(blk); mac_ellipsis; @@ -238,13 +238,13 @@ tag mac_ { type lit = spanned<lit_>; tag lit_ { - lit_str(istr); + lit_str(str); lit_char(char); lit_int(int); lit_uint(uint); lit_mach_int(ty_mach, int); - lit_float(istr); - lit_mach_float(ty_mach, istr); + lit_float(str); + lit_mach_float(ty_mach, str); lit_nil; lit_bool(bool); } @@ -292,6 +292,7 @@ tag ty_ { 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. */ @@ -379,6 +380,7 @@ tag controlflow { noreturn; // functions with return type _|_ that always // raise an error or exit (i.e. never return to the caller) + return; // everything else } @@ -412,7 +414,7 @@ tag native_abi { } type native_mod = - {native_name: istr, + {native_name: str, abi: native_abi, view_items: [@view_item], items: [@native_item]}; @@ -467,9 +469,11 @@ tag item_ { item_tag([variant], [ty_param]); item_obj(_obj, [ty_param], /* constructor id */node_id); item_res(_fn, - /* dtor */ + + /* dtor */ node_id, - /* dtor id */ + + /* dtor id */ [ty_param], /* ctor id */ @@ -485,7 +489,7 @@ type native_item = tag native_item_ { native_item_ty; - native_item_fn(option::t<istr>, fn_decl, [ty_param]); + native_item_fn(option::t<str>, fn_decl, [ty_param]); } // diff --git a/src/comp/syntax/ast_util.rs b/src/comp/syntax/ast_util.rs index d82a2302be5..c5d769c1299 100644 --- a/src/comp/syntax/ast_util.rs +++ b/src/comp/syntax/ast_util.rs @@ -13,11 +13,9 @@ fn mk_sp(lo: uint, hi: uint) -> span { // make this a const, once the compiler supports it fn dummy_sp() -> span { ret mk_sp(0u, 0u); } -fn path_name(p: &path) -> istr { path_name_i(p.node.idents) } +fn path_name(p: &path) -> str { path_name_i(p.node.idents) } -fn path_name_i(idents: &[ident]) -> istr { - str::connect(idents, ~"::") -} +fn path_name_i(idents: &[ident]) -> str { str::connect(idents, "::") } fn local_def(id: node_id) -> def_id { ret {crate: local_crate, node: id}; } @@ -45,7 +43,7 @@ fn def_id_of_def(d: def) -> def_id { } } -type pat_id_map = std::map::hashmap<istr, node_id>; +type pat_id_map = std::map::hashmap<str, node_id>; // This is used because same-named variables in alternative patterns need to // use the node_id of their namesake in the first pattern. @@ -82,27 +80,27 @@ fn pat_binding_ids(pat: &@pat) -> [node_id] { ret found; } -fn binop_to_str(op: binop) -> istr { +fn binop_to_str(op: binop) -> str { alt op { - add. { ret ~"+"; } - sub. { ret ~"-"; } - mul. { ret ~"*"; } - div. { ret ~"/"; } - rem. { ret ~"%"; } - and. { ret ~"&&"; } - or. { ret ~"||"; } - bitxor. { ret ~"^"; } - bitand. { ret ~"&"; } - bitor. { ret ~"|"; } - lsl. { ret ~"<<"; } - lsr. { ret ~">>"; } - asr. { ret ~">>>"; } - eq. { ret ~"=="; } - lt. { ret ~"<"; } - le. { ret ~"<="; } - ne. { ret ~"!="; } - ge. { ret ~">="; } - gt. { ret ~">"; } + add. { ret "+"; } + sub. { ret "-"; } + mul. { ret "*"; } + div. { ret "/"; } + rem. { ret "%"; } + and. { ret "&&"; } + or. { ret "||"; } + bitxor. { ret "^"; } + bitand. { ret "&"; } + bitor. { ret "|"; } + lsl. { ret "<<"; } + lsr. { ret ">>"; } + asr. { ret ">>>"; } + eq. { ret "=="; } + lt. { ret "<"; } + le. { ret "<="; } + ne. { ret "!="; } + ge. { ret ">="; } + gt. { ret ">"; } } } @@ -110,12 +108,12 @@ pure fn lazy_binop(b: binop) -> bool { alt b { and. { true } or. { true } _ { false } } } -fn unop_to_str(op: unop) -> istr { +fn unop_to_str(op: unop) -> str { alt op { - box(mt) { if mt == mut { ret ~"@mutable "; } ret ~"@"; } - deref. { ret ~"*"; } - not. { ret ~"!"; } - neg. { ret ~"-"; } + box(mt) { if mt == mut { ret "@mutable "; } ret "@"; } + deref. { ret "*"; } + not. { ret "!"; } + neg. { ret "-"; } } } @@ -123,18 +121,18 @@ fn is_path(e: &@expr) -> bool { ret alt e.node { expr_path(_) { true } _ { false } }; } -fn ty_mach_to_str(tm: ty_mach) -> istr { +fn ty_mach_to_str(tm: ty_mach) -> str { alt tm { - ty_u8. { ret ~"u8"; } - ty_u16. { ret ~"u16"; } - ty_u32. { ret ~"u32"; } - ty_u64. { ret ~"u64"; } - ty_i8. { ret ~"i8"; } - ty_i16. { ret ~"i16"; } - ty_i32. { ret ~"i32"; } - ty_i64. { ret ~"i64"; } - ty_f32. { ret ~"f32"; } - ty_f64. { ret ~"f64"; } + ty_u8. { ret "u8"; } + ty_u16. { ret "u16"; } + ty_u32. { ret "u32"; } + ty_u64. { ret "u64"; } + ty_i8. { ret "i8"; } + ty_i16. { ret "i16"; } + ty_i32. { ret "i32"; } + ty_i64. { ret "i64"; } + ty_f32. { ret "f32"; } + ty_f64. { ret "f64"; } } } @@ -190,8 +188,8 @@ fn block_from_expr(e: @expr) -> blk { ret {node: blk_, span: e.span}; } -fn checked_blk(stmts1: [@stmt], expr1: option::t<@expr>, id1: node_id) - -> blk_ { +fn checked_blk(stmts1: [@stmt], expr1: option::t<@expr>, id1: node_id) -> + blk_ { ret {stmts: stmts1, expr: expr1, id: id1, rules: checked}; } diff --git a/src/comp/syntax/codemap.rs b/src/comp/syntax/codemap.rs index 42120906b78..edb414b4e9b 100644 --- a/src/comp/syntax/codemap.rs +++ b/src/comp/syntax/codemap.rs @@ -7,7 +7,7 @@ import std::option; import std::option::some; import std::option::none; -type filename = istr; +type filename = str; type file_pos = {ch: uint, byte: uint}; @@ -66,15 +66,16 @@ fn lookup_byte_pos(map: codemap, pos: uint) -> loc { } tag opt_span { - //hack (as opposed to option::t), to make `span` compile + + //hack (as opposed to option::t), to make `span` compile os_none; os_some(@span); } type span = {lo: uint, hi: uint, expanded_from: opt_span}; -fn span_to_str(sp: &span, cm: &codemap) -> istr { +fn span_to_str(sp: &span, cm: &codemap) -> str { let cur = sp; - let res = ~""; + let res = ""; let prev_file = none; while true { let lo = lookup_char_pos(cm, cur.lo); @@ -82,16 +83,14 @@ fn span_to_str(sp: &span, cm: &codemap) -> istr { res += #fmt["%s:%u:%u: %u:%u", if some(lo.filename) == prev_file { - ~"-" - } else { - lo.filename - }, lo.line, lo.col, hi.line, hi.col]; + "-" + } else { lo.filename }, lo.line, lo.col, hi.line, hi.col]; alt cur.expanded_from { os_none. { break; } os_some(new_sp) { cur = *new_sp; prev_file = some(lo.filename); - res += ~"<<"; + res += "<<"; } } } @@ -99,13 +98,13 @@ fn span_to_str(sp: &span, cm: &codemap) -> istr { ret res; } -fn emit_diagnostic(sp: &option::t<span>, msg: &istr, kind: &istr, color: u8, +fn emit_diagnostic(sp: &option::t<span>, msg: &str, kind: &str, color: u8, cm: &codemap) { - let ss = ~""; + let ss = ""; let maybe_lines: option::t<@file_lines> = none; alt sp { some(ssp) { - ss = span_to_str(ssp, cm) + ~" "; + ss = span_to_str(ssp, cm) + " "; maybe_lines = some(span_to_lines(ssp, cm)); } none. { } @@ -114,9 +113,9 @@ fn emit_diagnostic(sp: &option::t<span>, msg: &istr, kind: &istr, color: u8, if term::color_supported() { term::fg(io::stdout().get_buf_writer(), color); } - io::stdout().write_str(#fmt[~"%s:", kind]); + 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\n", msg]); maybe_highlight_lines(sp, cm, maybe_lines); } @@ -128,7 +127,7 @@ fn maybe_highlight_lines(sp: &option::t<span>, cm: &codemap, some(lines) { // If we're not looking at a real file then we can't re-open it to // pull out the lines - if lines.name == ~"-" { ret; } + if lines.name == "-" { ret; } // FIXME: reading in the entire file is the worst possible way to // get access to the necessary lines. @@ -145,19 +144,18 @@ 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"; } + 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 s = #fmt["%s:%u ", fm.name, last_line + 1u]; let indent = str::char_len(s); - let out = ~""; - while indent > 0u { out += ~" "; indent -= 1u; } - out += ~"...\n"; + let out = ""; + while indent > 0u { out += " "; indent -= 1u; } + out += "...\n"; io::stdout().write_str(out); } @@ -173,34 +171,34 @@ fn maybe_highlight_lines(sp: &option::t<span>, cm: &codemap, // indent past |name:## | and the 0-offset column location let left = str::char_len(fm.name) + digits + lo.col + 3u; - let s = ~""; + let s = ""; while left > 0u { str::push_char(s, ' '); left -= 1u; } - s += ~"^"; + s += "^"; let hi = lookup_char_pos(cm, option::get(sp).hi); if hi.col != lo.col { // the ^ already takes up one space let width = hi.col - lo.col - 1u; while width > 0u { str::push_char(s, '~'); width -= 1u; } } - io::stdout().write_str(s + ~"\n"); + io::stdout().write_str(s + "\n"); } } _ { } } } -fn emit_warning(sp: &option::t<span>, msg: &istr, cm: &codemap) { - emit_diagnostic(sp, msg, ~"warning", 11u8, cm); +fn emit_warning(sp: &option::t<span>, msg: &str, cm: &codemap) { + emit_diagnostic(sp, msg, "warning", 11u8, cm); } -fn emit_error(sp: &option::t<span>, msg: &istr, cm: &codemap) { - emit_diagnostic(sp, msg, ~"error", 9u8, cm); +fn emit_error(sp: &option::t<span>, msg: &str, cm: &codemap) { + emit_diagnostic(sp, msg, "error", 9u8, cm); } -fn emit_note(sp: &option::t<span>, msg: &istr, cm: &codemap) { - emit_diagnostic(sp, msg, ~"note", 10u8, cm); +fn emit_note(sp: &option::t<span>, msg: &str, cm: &codemap) { + emit_diagnostic(sp, msg, "note", 10u8, cm); } -type file_lines = {name: istr, lines: [uint]}; +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); @@ -212,7 +210,7 @@ fn span_to_lines(sp: span, cm: codemap::codemap) -> @file_lines { ret @{name: lo.filename, lines: lines}; } -fn get_line(fm: filemap, line: int, file: &istr) -> istr { +fn get_line(fm: filemap, line: int, file: &str) -> str { let begin: uint = fm.lines[line].byte - fm.start_pos.byte; let end: uint; if line as uint < vec::len(fm.lines) - 1u { @@ -229,10 +227,8 @@ fn get_line(fm: filemap, line: int, file: &istr) -> istr { ret str::slice(file, begin, end); } -fn get_filemap(cm: codemap, filename: istr) -> filemap { - for fm: filemap in cm.files { - if fm.name == filename { ret fm; } - } +fn get_filemap(cm: codemap, filename: str) -> filemap { + for fm: filemap in cm.files { if fm.name == filename { ret fm; } } //XXjdm the following triggers a mismatched type bug // (or expected function, found _|_) fail; // ("asking for " + filename + " which we don't know about"); diff --git a/src/comp/syntax/ext/base.rs b/src/comp/syntax/ext/base.rs index 2dcc43ef178..298f90237bc 100644 --- a/src/comp/syntax/ext/base.rs +++ b/src/comp/syntax/ext/base.rs @@ -8,10 +8,10 @@ import std::map::new_str_hash; import codemap; type syntax_expander = - fn(&ext_ctxt, span, @ast::expr, &option::t<istr>) -> @ast::expr; -type macro_def = {ident: istr, ext: syntax_extension}; + 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<istr>) -> macro_def; + fn(&ext_ctxt, span, @ast::expr, &option::t<str>) -> macro_def; tag syntax_extension { normal(syntax_expander); @@ -20,25 +20,25 @@ tag syntax_extension { // A temporary hard-coded map of methods for expanding syntax extension // AST nodes into full ASTs -fn syntax_expander_table() -> hashmap<istr, syntax_extension> { +fn syntax_expander_table() -> hashmap<str, syntax_extension> { let syntax_expanders = new_str_hash::<syntax_extension>(); - syntax_expanders.insert(~"fmt", normal(ext::fmt::expand_syntax_ext)); - syntax_expanders.insert(~"env", normal(ext::env::expand_syntax_ext)); - syntax_expanders.insert(~"macro", + syntax_expanders.insert("fmt", normal(ext::fmt::expand_syntax_ext)); + syntax_expanders.insert("env", normal(ext::env::expand_syntax_ext)); + syntax_expanders.insert("macro", macro_defining(ext::simplext::add_new_extension)); - syntax_expanders.insert(~"concat_idents", + syntax_expanders.insert("concat_idents", normal(ext::concat_idents::expand_syntax_ext)); - syntax_expanders.insert(~"ident_to_str", + syntax_expanders.insert("ident_to_str", normal(ext::ident_to_str::expand_syntax_ext)); - syntax_expanders.insert(~"log_syntax", + syntax_expanders.insert("log_syntax", normal(ext::log_syntax::expand_syntax_ext)); ret syntax_expanders; } obj ext_ctxt(sess: @session, - crate_file_name_hack: istr, + crate_file_name_hack: str, mutable backtrace: codemap::opt_span) { - fn crate_file_name() -> istr { ret crate_file_name_hack; } + fn crate_file_name() -> str { ret crate_file_name_hack; } fn session() -> @session { ret sess; } @@ -58,30 +58,27 @@ obj ext_ctxt(sess: @session, let tmp = pre; backtrace = tmp; } - _ { self.bug(~"tried to pop without a push"); } + _ { self.bug("tried to pop without a push"); } } } - fn span_fatal(sp: span, msg: istr) -> ! { + fn span_fatal(sp: span, msg: str) -> ! { self.print_backtrace(); sess.span_fatal(sp, msg); } - fn span_err(sp: span, msg: istr) { + fn span_err(sp: span, msg: str) { self.print_backtrace(); sess.span_err(sp, msg); } - fn span_unimpl(sp: span, msg: istr) -> ! { + fn span_unimpl(sp: span, msg: str) -> ! { self.print_backtrace(); sess.span_unimpl(sp, msg); } - fn span_bug(sp: span, msg: istr) -> ! { + fn span_bug(sp: span, msg: str) -> ! { self.print_backtrace(); sess.span_bug(sp, msg); } - fn bug(msg: istr) -> ! { - self.print_backtrace(); - sess.bug(msg); - } + fn bug(msg: str) -> ! { self.print_backtrace(); sess.bug(msg); } fn next_id() -> ast::node_id { ret sess.next_node_id(); } } @@ -96,11 +93,10 @@ fn mk_ctxt(sess: &session) -> ext_ctxt { // super-ugly and needs a better solution. let crate_file_name_hack = sess.get_codemap().files[0].name; - ret ext_ctxt(@sess, crate_file_name_hack, - codemap::os_none); + ret ext_ctxt(@sess, crate_file_name_hack, codemap::os_none); } -fn expr_to_str(cx: &ext_ctxt, expr: @ast::expr, error: &istr) -> istr { +fn expr_to_str(cx: &ext_ctxt, expr: @ast::expr, error: &str) -> str { alt expr.node { ast::expr_lit(l) { alt l.node { @@ -112,8 +108,7 @@ fn expr_to_str(cx: &ext_ctxt, expr: @ast::expr, error: &istr) -> istr { } } -fn expr_to_ident(cx: &ext_ctxt, expr: @ast::expr, - error: &istr) -> ast::ident { +fn expr_to_ident(cx: &ext_ctxt, expr: @ast::expr, error: &str) -> ast::ident { alt expr.node { ast::expr_path(p) { if vec::len(p.node.types) > 0u || vec::len(p.node.idents) != 1u { diff --git a/src/comp/syntax/ext/concat_idents.rs b/src/comp/syntax/ext/concat_idents.rs index f5ce004ea00..53ee6cb0397 100644 --- a/src/comp/syntax/ext/concat_idents.rs +++ b/src/comp/syntax/ext/concat_idents.rs @@ -3,17 +3,17 @@ import base::*; import syntax::ast; fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr, - _body: &option::t<istr>) -> @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 .") + cx.span_fatal(sp, "#concat_idents requires a vector argument .") } }; - let res: ast::ident = ~""; + let res: ast::ident = ""; for e: @ast::expr in args { - res += expr_to_ident(cx, e, ~"expected an ident"); + res += expr_to_ident(cx, e, "expected an ident"); } ret @{id: cx.next_id(), diff --git a/src/comp/syntax/ext/env.rs b/src/comp/syntax/ext/env.rs index 487b12d0bc2..081bfd80c1d 100644 --- a/src/comp/syntax/ext/env.rs +++ b/src/comp/syntax/ext/env.rs @@ -12,30 +12,28 @@ import base::*; export expand_syntax_ext; fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr, - _body: &option::t<istr>) -> @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 `[...]`.") + cx.span_fatal(sp, "#env requires arguments of the form `[...]`.") } }; if vec::len::<@ast::expr>(args) != 1u { - cx.span_fatal(sp, ~"malformed #env call"); + 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); - } + option::none. { ret make_new_str(cx, sp, ""); } + option::some(s) { ret make_new_str(cx, sp, s); } } } -fn make_new_str(cx: &ext_ctxt, sp: codemap::span, s: &istr) -> @ast::expr { +fn make_new_str(cx: &ext_ctxt, sp: codemap::span, s: &str) -> @ast::expr { ret make_new_lit(cx, sp, ast::lit_str(s)); } // diff --git a/src/comp/syntax/ext/expand.rs b/src/comp/syntax/ext/expand.rs index c2a3a201126..7037139bd93 100644 --- a/src/comp/syntax/ext/expand.rs +++ b/src/comp/syntax/ext/expand.rs @@ -15,7 +15,7 @@ import syntax::fold::*; import syntax::ext::base::*; -fn expand_expr(exts: &hashmap<istr, syntax_extension>, cx: &ext_ctxt, +fn expand_expr(exts: &hashmap<str, syntax_extension>, cx: &ext_ctxt, e: &expr_, fld: ast_fold, orig: &fn(&expr_, ast_fold) -> expr_) -> expr_ { ret alt e { @@ -27,8 +27,7 @@ fn expand_expr(exts: &hashmap<istr, syntax_extension>, cx: &ext_ctxt, alt exts.find(extname) { none. { cx.span_fatal(pth.span, - #fmt["macro undefined: '%s'", - extname]) + #fmt["macro undefined: '%s'", extname]) } some(normal(ext)) { let expanded = ext(cx, pth.span, args, body); @@ -42,14 +41,12 @@ fn expand_expr(exts: &hashmap<istr, 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); + exts.insert(named_extension.ident, named_extension.ext); ast::expr_rec([], none) } } } - _ { cx.span_bug(mac.span, ~"naked syntactic bit") } + _ { cx.span_bug(mac.span, "naked syntactic bit") } } } _ { orig(e, fld) } diff --git a/src/comp/syntax/ext/fmt.rs b/src/comp/syntax/ext/fmt.rs index 91a83b06267..aef3cc46902 100644 --- a/src/comp/syntax/ext/fmt.rs +++ b/src/comp/syntax/ext/fmt.rs @@ -16,26 +16,24 @@ import codemap::span; export expand_syntax_ext; fn expand_syntax_ext(cx: &ext_ctxt, sp: span, arg: @ast::expr, - _body: &option::t<istr>) -> @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 `[...]`.") + 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"); + cx.span_fatal(sp, "#fmt requires a format string"); } let fmt = expr_to_str(cx, args[0], - ~"first argument to #fmt must be a " - + ~"string literal."); + "first argument to #fmt must be a " + "string literal."); let fmtspan = args[0].span; log "Format string:"; log fmt; - fn parse_fmt_err_(cx: &ext_ctxt, sp: span, msg: &istr) -> ! { + fn parse_fmt_err_(cx: &ext_ctxt, sp: span, msg: &str) -> ! { cx.span_fatal(sp, msg); } let parse_fmt_err = bind parse_fmt_err_(cx, fmtspan, _); @@ -52,7 +50,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], let sp_lit = @{node: lit, span: sp}; ret @{id: cx.next_id(), node: ast::expr_lit(sp_lit), span: sp}; } - fn make_new_str(cx: &ext_ctxt, sp: span, s: &istr) -> @ast::expr { + fn make_new_str(cx: &ext_ctxt, sp: span, s: &str) -> @ast::expr { let lit = ast::lit_str(s); ret make_new_lit(cx, sp, lit); } @@ -103,14 +101,13 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], } fn make_path_vec(cx: &ext_ctxt, ident: &ast::ident) -> [ast::ident] { fn compiling_std(cx: &ext_ctxt) -> bool { - ret str::find(cx.crate_file_name(), ~"std.rc") >= 0; + 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: &istr) -> @ast::expr { + fn make_rt_path_expr(cx: &ext_ctxt, sp: span, ident: &str) -> @ast::expr { let path = make_path_vec(cx, ident); ret make_path_expr(cx, sp, path); } @@ -123,11 +120,11 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], for f: flag in flags { let fstr; alt f { - flag_left_justify. { fstr = ~"flag_left_justify"; } - flag_left_zero_pad. { fstr = ~"flag_left_zero_pad"; } - flag_space_for_sign. { fstr = ~"flag_space_for_sign"; } - flag_sign_always. { fstr = ~"flag_sign_always"; } - flag_alternate. { fstr = ~"flag_alternate"; } + flag_left_justify. { fstr = "flag_left_justify"; } + flag_left_zero_pad. { fstr = "flag_left_zero_pad"; } + flag_space_for_sign. { fstr = "flag_space_for_sign"; } + flag_sign_always. { fstr = "flag_sign_always"; } + flag_alternate. { fstr = "flag_alternate"; } } flagexprs += [make_rt_path_expr(cx, sp, fstr)]; } @@ -136,22 +133,22 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], // 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); } fn make_count(cx: &ext_ctxt, sp: span, cnt: &count) -> @ast::expr { alt cnt { count_implied. { - ret make_rt_path_expr(cx, sp, ~"count_implied"); + ret make_rt_path_expr(cx, sp, "count_implied"); } 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_path = make_path_vec(cx, "count_is"); let count_is_args = [count_lit]; ret make_call(cx, sp, count_is_path, count_is_args); } - _ { cx.span_unimpl(sp, ~"unimplemented #fmt conversion"); } + _ { cx.span_unimpl(sp, "unimplemented #fmt conversion"); } } } fn make_ty(cx: &ext_ctxt, sp: span, t: &ty) -> @ast::expr { @@ -159,13 +156,13 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], alt t { ty_hex(c) { alt c { - case_upper. { rt_type = ~"ty_hex_upper"; } - case_lower. { rt_type = ~"ty_hex_lower"; } + case_upper. { rt_type = "ty_hex_upper"; } + case_lower. { rt_type = "ty_hex_lower"; } } } - ty_bits. { rt_type = ~"ty_bits"; } - ty_octal. { rt_type = ~"ty_octal"; } - _ { rt_type = ~"ty_default"; } + ty_bits. { rt_type = "ty_bits"; } + ty_octal. { rt_type = "ty_octal"; } + _ { rt_type = "ty_default"; } } ret make_rt_path_expr(cx, sp, rt_type); } @@ -173,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,9 +182,9 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], ret make_conv_rec(cx, sp, rt_conv_flags, rt_conv_width, rt_conv_precision, rt_conv_ty); } - fn make_conv_call(cx: &ext_ctxt, sp: span, conv_type: &istr, - cnv: &conv, arg: @ast::expr) -> @ast::expr { - let fname = ~"conv_" + conv_type; + fn make_conv_call(cx: &ext_ctxt, sp: span, conv_type: &str, cnv: &conv, + arg: @ast::expr) -> @ast::expr { + 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]; @@ -205,7 +202,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], _ { ret false; } } } - let unsupported = ~"conversion not supported in #fmt string"; + let unsupported = "conversion not supported in #fmt string"; alt cnv.param { option::none. { } _ { cx.span_unimpl(sp, unsupported); } @@ -216,15 +213,15 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], flag_sign_always. { if !is_signed_type(cnv) { cx.span_fatal(sp, - ~"+ flag only valid in " + - ~"signed #fmt conversion"); + "+ flag only valid in " + + "signed #fmt conversion"); } } flag_space_for_sign. { if !is_signed_type(cnv) { cx.span_fatal(sp, - ~"space flag only valid in " + - ~"signed #fmt conversions"); + "space flag only valid in " + + "signed #fmt conversions"); } } flag_left_zero_pad. { } @@ -242,28 +239,26 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], _ { cx.span_unimpl(sp, unsupported); } } alt cnv.ty { - ty_str. { ret make_conv_call(cx, arg.span, ~"str", cnv, arg); } + ty_str. { ret make_conv_call(cx, arg.span, "str", cnv, arg); } ty_int(sign) { alt sign { - signed. { ret make_conv_call(cx, arg.span, ~"int", cnv, arg); } + signed. { ret make_conv_call(cx, arg.span, "int", cnv, arg); } unsigned. { - ret make_conv_call(cx, arg.span, ~"uint", cnv, arg); + ret make_conv_call(cx, arg.span, "uint", cnv, arg); } } } - ty_bool. { ret make_conv_call(cx, arg.span, ~"bool", cnv, arg); } - ty_char. { ret make_conv_call(cx, arg.span, ~"char", cnv, arg); } - ty_hex(_) { ret make_conv_call(cx, arg.span, ~"uint", cnv, arg); } - ty_bits. { ret make_conv_call(cx, arg.span, ~"uint", cnv, arg); } - ty_octal. { ret make_conv_call(cx, arg.span, ~"uint", cnv, arg); } + ty_bool. { ret make_conv_call(cx, arg.span, "bool", cnv, arg); } + ty_char. { ret make_conv_call(cx, arg.span, "char", cnv, arg); } + ty_hex(_) { ret make_conv_call(cx, arg.span, "uint", cnv, arg); } + ty_bits. { ret make_conv_call(cx, arg.span, "uint", cnv, arg); } + ty_octal. { ret make_conv_call(cx, arg.span, "uint", cnv, arg); } _ { cx.span_unimpl(sp, unsupported); } } } fn log_conv(c: conv) { alt c.param { - some(p) { - log ~"param: " + std::int::to_str(p, 10u); - } + some(p) { log "param: " + std::int::to_str(p, 10u); } _ { log "param: none"; } } for f: flag in c.flags { @@ -276,21 +271,17 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], } } alt c.width { - count_is(i) { log ~"width: count is " - + std::int::to_str(i, 10u); } + count_is(i) { log "width: count is " + std::int::to_str(i, 10u); } count_is_param(i) { - log ~"width: count is param " - + std::int::to_str(i, 10u); + log "width: count is param " + std::int::to_str(i, 10u); } count_is_next_param. { log "width: count is next param"; } count_implied. { log "width: count is implied"; } } alt c.precision { - count_is(i) { log ~"prec: count is " - + std::int::to_str(i, 10u); } + count_is(i) { log "prec: count is " + std::int::to_str(i, 10u); } count_is_param(i) { - log ~"prec: count is param " - + std::int::to_str(i, 10u); + log "prec: count is param " + std::int::to_str(i, 10u); } count_is_next_param. { log "prec: count is next param"; } count_implied. { log "prec: count is implied"; } @@ -317,7 +308,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], } let fmt_sp = args[0].span; let n = 0u; - let tmp_expr = make_new_str(cx, sp, ~""); + let tmp_expr = make_new_str(cx, sp, ""); let nargs = vec::len::<@ast::expr>(args); for pc: piece in pieces { alt pc { @@ -329,8 +320,8 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], n += 1u; if n >= nargs { cx.span_fatal(sp, - ~"not enough arguments to #fmt " + - ~"for the given format string"); + "not enough arguments to #fmt " + + "for the given format string"); } log "Building conversion:"; log_conv(conv); diff --git a/src/comp/syntax/ext/ident_to_str.rs b/src/comp/syntax/ext/ident_to_str.rs index f30d6932555..1cf015fcaf0 100644 --- a/src/comp/syntax/ext/ident_to_str.rs +++ b/src/comp/syntax/ext/ident_to_str.rs @@ -5,20 +5,20 @@ import base::*; import syntax::ast; fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr, - _body: &option::t<istr>) -> @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 .") + 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"); + cx.span_fatal(sp, "malformed #ident_to_str call"); } ret make_new_lit(cx, sp, ast::lit_str(expr_to_ident(cx, args[0u], - ~"expected an ident"))); + "expected an ident"))); } diff --git a/src/comp/syntax/ext/log_syntax.rs b/src/comp/syntax/ext/log_syntax.rs index a8fa657c20c..50e7e307bdc 100644 --- a/src/comp/syntax/ext/log_syntax.rs +++ b/src/comp/syntax/ext/log_syntax.rs @@ -4,11 +4,10 @@ import syntax::ast; import std::str; fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr, - _body: &option::t<istr>) -> @ast::expr { + _body: &option::t<str>) -> @ast::expr { cx.print_backtrace(); - std::io::stdout().write_line( - print::pprust::expr_to_str(arg)); + 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}; diff --git a/src/comp/syntax/ext/simplext.rs b/src/comp/syntax/ext/simplext.rs index 3496791ce6e..4e76ec0d787 100644 --- a/src/comp/syntax/ext/simplext.rs +++ b/src/comp/syntax/ext/simplext.rs @@ -57,29 +57,29 @@ tag matchable { } /* for when given an incompatible bit of AST */ -fn match_error(cx: &ext_ctxt, m: &matchable, expected: &istr) -> ! { +fn match_error(cx: &ext_ctxt, m: &matchable, expected: &str) -> ! { alt m { match_expr(x) { cx.span_fatal(x.span, - ~"this argument is an expr, expected " + expected); + "this argument is an expr, expected " + expected); } match_path(x) { cx.span_fatal(x.span, - ~"this argument is a path, expected " + expected); + "this argument is a path, expected " + expected); } match_ident(x) { cx.span_fatal(x.span, - ~"this argument is an ident, expected " + expected); + "this argument is an ident, expected " + expected); } match_ty(x) { cx.span_fatal(x.span, - ~"this argument is a type, expected " + expected); + "this argument is a type, expected " + expected); } match_block(x) { cx.span_fatal(x.span, - ~"this argument is a block, expected " + expected); + "this argument is a block, expected " + expected); } - match_exact. { cx.bug(~"what is a match_exact doing in a bindings?"); } + match_exact. { cx.bug("what is a match_exact doing in a bindings?"); } } } @@ -102,7 +102,7 @@ fn elts_to_ell(cx: &ext_ctxt, elts: &[@expr]) -> alt m.node { ast::mac_ellipsis. { if res != none { - cx.span_fatal(m.span, ~"only one ellipsis allowed"); + cx.span_fatal(m.span, "only one ellipsis allowed"); } res = some({pre: vec::slice(elts, 0u, idx - 1u), @@ -190,8 +190,7 @@ fn use_selectors_to_bind(b: &binders, e: @expr) -> option::t<bindings> { alt sel(match_expr(e)) { none. { ret none; } _ { } } } let never_mind: bool = false; - for each pair: @{key: ident, - val: selector} in b.real_binders.items() { + for each pair: @{key: ident, val: selector} in b.real_binders.items() { alt pair.val(match_expr(e)) { none. { never_mind = true; } some(mtc) { res.insert(pair.key, mtc); } @@ -252,8 +251,8 @@ fn follow_for_trans(cx: &ext_ctxt, mmaybe: &option::t<arb_depth<matchable>>, ret alt follow(m, idx_path) { seq(_, sp) { cx.span_fatal(sp, - ~"syntax matched under ... but not " + - ~"used that way.") + "syntax matched under ... but not " + + "used that way.") } leaf(m) { ret some(m) } } @@ -267,9 +266,7 @@ iter free_vars(b: &bindings, e: @expr) -> ident { let idents: hashmap<ident, ()> = new_str_hash::<()>(); fn mark_ident(i: &ident, _fld: ast_fold, b: &bindings, idents: &hashmap<ident, ()>) -> ident { - if b.contains_key(i) { - idents.insert(i, ()); - } + if b.contains_key(i) { idents.insert(i, ()); } ret i; } // using fold is a hack: we want visit, but it doesn't hit idents ) : @@ -309,13 +306,10 @@ fn transcribe_exprs(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], 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, + #fmt["'%s' occurs %u times, but ", fv, len] + + #fmt["'%s' occurs %u times", old_name, old_len]; - cx.span_fatal( - repeat_me.span, msg); + cx.span_fatal(repeat_me.span, msg); } } } @@ -325,8 +319,8 @@ fn transcribe_exprs(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], alt repeat { none. { cx.span_fatal(repeat_me.span, - ~"'...' surrounds an expression without any" + - ~" repeating syntax variables"); + "'...' surrounds an expression without any" + + " repeating syntax variables"); } some({rep_count: rc, _}) { /* Whew, we now know how how many times to repeat */ @@ -354,7 +348,7 @@ fn transcribe_ident(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], i: &ident, _fld: ast_fold) -> ident { ret alt follow_for_trans(cx, b.find(i), idx_path) { some(match_ident(a_id)) { a_id.node } - some(m) { match_error(cx, m, ~"an identifier") } + some(m) { match_error(cx, m, "an identifier") } none. { i } } } @@ -369,7 +363,7 @@ fn transcribe_path(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], {global: false, idents: [id.node], types: []} } some(match_path(a_pth)) { a_pth.node } - some(m) { match_error(cx, m, ~"a path") } + some(m) { match_error(cx, m, "a path") } none. { p } } } @@ -394,7 +388,7 @@ fn transcribe_expr(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], } some(match_path(a_pth)) { expr_path(a_pth) } some(match_expr(a_exp)) { a_exp.node } - some(m) { match_error(cx, m, ~"an expression") } + some(m) { match_error(cx, m, "an expression") } none. { orig(e, fld) } } } @@ -411,7 +405,7 @@ fn transcribe_type(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], some(id) { alt follow_for_trans(cx, b.find(id), idx_path) { some(match_ty(ty)) { ty.node } - some(m) { match_error(cx, m, ~"a type") } + some(m) { match_error(cx, m, "a type") } none. { orig(t, fld) } } } @@ -431,14 +425,14 @@ fn transcribe_block(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], 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) { + 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") + match_error(cx, m, "a block") } none. { orig(blk, fld) } } @@ -469,12 +463,12 @@ fn p_t_s_rec(cx: &ext_ctxt, m: &matchable, s: &selector, b: &binders) { if vec::len(post) > 0u { cx.span_unimpl(e.span, - ~"matching after `...` not yet supported"); + "matching after `...` not yet supported"); } } {pre: pre, rep: none., post: post} { if post != [] { - cx.bug(~"elts_to_ell provided an invalid result"); + cx.bug("elts_to_ell provided an invalid result"); } p_t_s_r_length(cx, vec::len(pre), false, s, b); p_t_s_r_actual_vector(cx, pre, false, s, b); @@ -483,6 +477,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); @@ -494,7 +489,7 @@ fn p_t_s_rec(cx: &ext_ctxt, m: &matchable, s: &selector, b: &binders) { match_expr(e) { if e == pat { some(leaf(match_exact)) } else { none } } - _ { cx.bug(~"broken traversal in p_t_s_r") } + _ { cx.bug("broken traversal in p_t_s_r") } } } b.literal_ast_matchers += [bind select(cx, _, e)]; @@ -530,14 +525,13 @@ fn p_t_s_r_path(cx: &ext_ctxt, p: &path, s: &selector, b: &binders) { fn select(cx: &ext_ctxt, m: &matchable) -> match_result { ret alt m { match_expr(e) { some(leaf(specialize_match(m))) } - _ { cx.bug(~"broken traversal in p_t_s_r") } + _ { cx.bug("broken traversal in p_t_s_r") } } } if b.real_binders.contains_key(p_id) { - cx.span_fatal(p.span, ~"duplicate binding identifier"); + cx.span_fatal(p.span, "duplicate binding identifier"); } - b.real_binders.insert(p_id, - compose_sels(s, bind select(cx, _))); + b.real_binders.insert(p_id, compose_sels(s, bind select(cx, _))); } none. { } } @@ -560,16 +554,15 @@ fn p_t_s_r_mac(cx: &ext_ctxt, mac: &ast::mac, s: &selector, b: &binders) { match_expr(e) { alt e.node { expr_mac(mac) { fn_m(mac) } _ { none } } } - _ { cx.bug(~"broken traversal in p_t_s_r") } + _ { cx.bug("broken traversal in p_t_s_r") } } } - fn no_des(cx: &ext_ctxt, sp: &span, syn: &istr) -> ! { - cx.span_fatal(sp, ~"destructuring " - + syn + ~" is not yet supported"); + fn no_des(cx: &ext_ctxt, sp: &span, syn: &str) -> ! { + cx.span_fatal(sp, "destructuring " + syn + " is not yet supported"); } alt mac.node { - ast::mac_ellipsis. { cx.span_fatal(mac.span, ~"misused `...`"); } - ast::mac_invoc(_, _, _) { no_des(cx, mac.span, ~"macro calls"); } + ast::mac_ellipsis. { cx.span_fatal(mac.span, "misused `...`"); } + ast::mac_invoc(_, _, _) { no_des(cx, mac.span, "macro calls"); } ast::mac_embed_type(ty) { alt ty.node { ast::ty_path(pth, _) { @@ -583,13 +576,12 @@ fn p_t_s_r_mac(cx: &ext_ctxt, mac: &ast::mac, s: &selector, b: &binders) { } } let final_step = bind select_pt_1(cx, _, select_pt_2); - b.real_binders.insert( - id, compose_sels(s, final_step)); + b.real_binders.insert(id, compose_sels(s, final_step)); } - none. { no_des(cx, pth.span, ~"under `#<>`"); } + none. { no_des(cx, pth.span, "under `#<>`"); } } } - _ { no_des(cx, ty.span, ~"under `#<>`"); } + _ { no_des(cx, ty.span, "under `#<>`"); } } } ast::mac_embed_block(blk) { @@ -604,10 +596,9 @@ fn p_t_s_r_mac(cx: &ext_ctxt, mac: &ast::mac, s: &selector, b: &binders) { } } let final_step = bind select_pt_1(cx, _, select_pt_2); - b.real_binders.insert(id, - compose_sels(s, final_step)); + b.real_binders.insert(id, compose_sels(s, final_step)); } - none. { no_des(cx, blk.span, ~"under `#{}`"); } + none. { no_des(cx, blk.span, "under `#{}`"); } } } } @@ -635,7 +626,7 @@ fn p_t_s_r_ellipses(cx: &ext_ctxt, repeat_me: @expr, offset: uint, _ { none } } } - _ { cx.bug(~"broken traversal in p_t_s_r") } + _ { cx.bug("broken traversal in p_t_s_r") } } } p_t_s_rec(cx, match_expr(repeat_me), @@ -680,7 +671,7 @@ fn p_t_s_r_actual_vector(cx: &ext_ctxt, elts: [@expr], _repeat_after: bool, _ { none } } } - _ { cx.bug(~"broken traversal in p_t_s_r") } + _ { cx.bug("broken traversal in p_t_s_r") } } } p_t_s_rec(cx, match_expr(elts[idx]), @@ -690,25 +681,25 @@ 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<istr>) -> base::macro_def { + _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 `[...]`.") + "#macro requires arguments of the form `[...]`.") } }; - let macro_name: option::t<istr> = none; + let macro_name: option::t<str> = none; let clauses: [@clause] = []; for arg: @expr in args { alt arg.node { expr_vec(elts, mut) { if vec::len(elts) != 2u { cx.span_fatal((*arg).span, - ~"extension clause must consist of [" + - ~"macro invocation, expansion body]"); + "extension clause must consist of [" + + "macro invocation, expansion body]"); } @@ -723,15 +714,15 @@ fn add_new_extension(cx: &ext_ctxt, sp: span, arg: @expr, some(other_id) { if id != other_id { cx.span_fatal(pth.span, - ~"macro name must be " + - ~"consistent"); + "macro name must be " + + "consistent"); } } } } none. { cx.span_fatal(pth.span, - ~"macro name must not be a path"); + "macro name must not be a path"); } } clauses += @@ -744,14 +735,14 @@ fn add_new_extension(cx: &ext_ctxt, sp: span, arg: @expr, } _ { cx.span_fatal(elts[0u].span, - ~"extension clause must" + - ~" start with a macro invocation."); + "extension clause must" + + " start with a macro invocation."); } } } _ { cx.span_fatal((*arg).span, - ~"extension must be [clause, " + ~" ...]"); + "extension must be [clause, " + " ...]"); } } } @@ -763,22 +754,22 @@ fn add_new_extension(cx: &ext_ctxt, sp: span, arg: @expr, some(id) { id } none. { cx.span_fatal(sp, - ~"macro definition must have " + - ~"at least one clause") + "macro definition must have " + + "at least one clause") } }, ext: normal(ext)}; fn generic_extension(cx: &ext_ctxt, sp: span, arg: @expr, - _body: &option::t<istr>, - clauses: [@clause]) -> @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) } none. { cont; } } } - cx.span_fatal(sp, ~"no clauses match macro invocation"); + cx.span_fatal(sp, "no clauses match macro invocation"); } } diff --git a/src/comp/syntax/parse/eval.rs b/src/comp/syntax/parse/eval.rs index ee7c5a3d338..6535ecfe586 100644 --- a/src/comp/syntax/parse/eval.rs +++ b/src/comp/syntax/parse/eval.rs @@ -19,15 +19,14 @@ tag eval_mode { mode_depend; mode_parse; } type ctx = @{p: parser, mode: eval_mode, - mutable deps: [istr], + mutable deps: [str], sess: parser::parse_sess, mutable chpos: uint, mutable byte_pos: uint, cfg: ast::crate_cfg}; fn eval_crate_directives(cx: ctx, cdirs: &[@ast::crate_directive], - prefix: &istr, - 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); @@ -35,34 +34,27 @@ fn eval_crate_directives(cx: ctx, cdirs: &[@ast::crate_directive], } fn eval_crate_directives_to_mod(cx: ctx, cdirs: &[@ast::crate_directive], - prefix: &istr) -> ast::_mod { + prefix: &str) -> ast::_mod { 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}; } -fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: &istr, +fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: &str, view_items: &mutable [@ast::view_item], items: &mutable [@ast::item]) { alt cdir.node { ast::cdir_src_mod(id, file_opt, attrs) { - let file_path = id + ~".rs"; - alt file_opt { - some(f) { - file_path = f; - } - none. { } - } - let full_path = if std::fs::path_is_absolute(file_path) { - file_path - } else { - prefix + std::fs::path_sep() + file_path - }; + let file_path = id + ".rs"; + alt file_opt { some(f) { file_path = f; } none. { } } + let full_path = + 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; } let p0 = - new_parser_from_file(cx.sess, cx.cfg, - full_path, cx.chpos, + new_parser_from_file(cx.sess, cx.cfg, full_path, cx.chpos, cx.byte_pos, SOURCE_FILE); let inner_attrs = parse_inner_attrs_and_next(p0); let mod_attrs = attrs + inner_attrs.inner; @@ -79,18 +71,11 @@ fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: &istr, } ast::cdir_dir_mod(id, dir_opt, cdirs, attrs) { let path = id; - alt dir_opt { - some(d) { - path = d; - } - none. { } - } + alt dir_opt { some(d) { path = d; } none. { } } let full_path = if std::fs::path_is_absolute(path) { path - } else { - prefix + std::fs::path_sep() + path - }; + } else { prefix + std::fs::path_sep() + path }; let m0 = eval_crate_directives_to_mod(cx, cdirs, full_path); let i = @{ident: id, diff --git a/src/comp/syntax/parse/lexer.rs b/src/comp/syntax/parse/lexer.rs index e479377f3d7..f0d5bfeb729 100644 --- a/src/comp/syntax/parse/lexer.rs +++ b/src/comp/syntax/parse/lexer.rs @@ -19,29 +19,29 @@ type reader = fn next() -> char; fn init(); fn bump(); - fn get_str_from(uint) -> istr; - fn get_interner() -> @interner::interner<istr>; + 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(&istr); + fn err(&str); }; -fn new_reader(cm: &codemap::codemap, src: &istr, filemap: codemap::filemap, - itr: @interner::interner<istr>) -> reader { +fn new_reader(cm: &codemap::codemap, src: &str, filemap: codemap::filemap, + itr: @interner::interner<str>) -> reader { obj reader(cm: codemap::codemap, - src: istr, + src: str, len: uint, mutable col: uint, mutable pos: uint, mutable ch: char, mutable chpos: uint, - mutable strs: [istr], + mutable strs: [str], fm: codemap::filemap, - itr: @interner::interner<istr>) { + itr: @interner::interner<str>) { fn is_eof() -> bool { ret ch == -1 as char; } - fn get_str_from(start: uint) -> istr { + fn get_str_from(start: uint) -> str { // I'm pretty skeptical about this subtraction. What if there's a // multi-byte character before the mark? ret str::slice(src, start - 1u, pos - 1u); @@ -74,16 +74,14 @@ fn new_reader(cm: &codemap::codemap, src: &istr, filemap: codemap::filemap, ch = next.ch; } else { ch = -1 as char; } } - fn get_interner() -> @interner::interner<istr> { ret itr; } + fn get_interner() -> @interner::interner<str> { ret itr; } fn get_col() -> uint { ret col; } fn get_filemap() -> codemap::filemap { ret fm; } - fn err(m: &istr) { - codemap::emit_error( - some(ast_util::mk_sp(chpos, chpos)), - m, cm); + fn err(m: &str) { + codemap::emit_error(some(ast_util::mk_sp(chpos, chpos)), m, cm); } } - let strs: [istr] = []; + let strs: [str] = []; let rd = reader(cm, src, str::byte_len(src), 0u, 0u, -1 as char, filemap.start_pos.ch, strs, filemap, itr); @@ -148,9 +146,7 @@ fn consume_any_line_comment(rdr: &reader) { fn consume_block_comment(rdr: &reader) { let level: int = 1; while level > 0 { - if rdr.is_eof() { - rdr.err(~"unterminated block comment"); fail; - } + if rdr.is_eof() { rdr.err("unterminated block comment"); fail; } if rdr.curr() == '/' && rdr.next() == '*' { rdr.bump(); rdr.bump(); @@ -168,15 +164,15 @@ fn consume_block_comment(rdr: &reader) { be consume_whitespace_and_comments(rdr); } -fn digits_to_string(s: &istr) -> int { +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); } ret accum_int; } -fn scan_exponent(rdr: &reader) -> option::t<istr> { +fn scan_exponent(rdr: &reader) -> option::t<str> { let c = rdr.curr(); - let rslt = ~""; + let rslt = ""; if c == 'e' || c == 'E' { rslt += str::unsafe_from_bytes([c as u8]); rdr.bump(); @@ -188,13 +184,13 @@ fn scan_exponent(rdr: &reader) -> option::t<istr> { let exponent = scan_dec_digits(rdr); if str::byte_len(exponent) > 0u { ret some(rslt + exponent); - } else { rdr.err(~"scan_exponent: bad fp literal"); fail; } - } else { ret none::<istr>; } + } else { rdr.err("scan_exponent: bad fp literal"); fail; } + } else { ret none::<str>; } } -fn scan_dec_digits(rdr: &reader) -> istr { +fn scan_dec_digits(rdr: &reader) -> str { let c = rdr.curr(); - let rslt: istr = ~""; + let rslt: str = ""; while is_dec_digit(c) || c == '_' { if c != '_' { rslt += str::unsafe_from_bytes([c as u8]); } rdr.bump(); @@ -205,7 +201,7 @@ fn scan_dec_digits(rdr: &reader) -> istr { fn scan_number(c: char, rdr: &reader) -> token::token { let accum_int = 0; - let dec_str: istr = ~""; + let dec_str: str = ""; let is_dec_integer: bool = false; let n = rdr.next(); if c == '0' && n == 'x' { @@ -276,7 +272,7 @@ fn scan_number(c: char, rdr: &reader) -> token::token { rdr.bump(); let dec_part = scan_dec_digits(rdr); - let float_str = dec_str + ~"." + dec_part; + let float_str = dec_str + "." + dec_part; c = rdr.curr(); let exponent_str = scan_exponent(rdr); alt exponent_str { some(s) { float_str += s; } none. { } } @@ -302,17 +298,15 @@ fn scan_number(c: char, rdr: &reader) -> token::token { } } else { - ret token::LIT_FLOAT(interner::intern::<istr>( - *rdr.get_interner(), - float_str)); + ret token::LIT_FLOAT(interner::intern::<str>(*rdr.get_interner(), + float_str)); } } let maybe_exponent = scan_exponent(rdr); alt maybe_exponent { some(s) { - ret token::LIT_FLOAT(interner::intern::<istr>( - *rdr.get_interner(), - dec_str + s)); + ret token::LIT_FLOAT(interner::intern::<str>(*rdr.get_interner(), + dec_str + s)); } none. { ret token::LIT_INT(accum_int); } } @@ -324,8 +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; @@ -344,7 +337,7 @@ fn next_token(rdr: &reader) -> {tok: token::token, chpos: uint, bpos: uint} { } fn next_token_inner(rdr: &reader) -> token::token { - let accum_str = ~""; + let accum_str = ""; let c = rdr.curr(); if is_alpha(c) || c == '_' { while is_alnum(c) || c == '_' { @@ -352,11 +345,10 @@ fn next_token_inner(rdr: &reader) -> token::token { rdr.bump(); c = rdr.curr(); } - if str::eq(accum_str, ~"_") { ret token::UNDERSCORE; } + if str::eq(accum_str, "_") { ret token::UNDERSCORE; } let is_mod_name = c == ':' && rdr.next() == ':'; - ret token::IDENT(interner::intern::<istr>( - *rdr.get_interner(), - accum_str), is_mod_name); + ret token::IDENT(interner::intern::<str>(*rdr.get_interner(), + accum_str), is_mod_name); } if is_dec_digit(c) { ret scan_number(c, rdr); } fn binop(rdr: &reader, op: token::binop) -> token::token { @@ -369,6 +361,7 @@ fn next_token_inner(rdr: &reader) -> token::token { alt c { + // One-byte tokens. '?' { rdr.bump(); @@ -408,6 +401,7 @@ fn next_token_inner(rdr: &reader) -> token::token { } + // Multi-byte tokens. '=' { rdr.bump(); @@ -468,15 +462,13 @@ 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; } } } if rdr.curr() != '\'' { - rdr.err(~"unterminated character constant"); + rdr.err("unterminated character constant"); fail; } rdr.bump(); // advance curr past token @@ -509,9 +501,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; } } @@ -520,9 +510,8 @@ fn next_token_inner(rdr: &reader) -> token::token { } } rdr.bump(); - ret token::LIT_STR(interner::intern::<istr>( - *rdr.get_interner(), - accum_str)); + ret token::LIT_STR(interner::intern::<str>(*rdr.get_interner(), + accum_str)); } '-' { if rdr.next() == '>' { @@ -549,11 +538,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; } } } @@ -564,10 +549,10 @@ tag cmnt_style { blank_line; // Just a manual blank line "\n\n", for layout } -type cmnt = {style: cmnt_style, lines: [istr], pos: uint}; +type cmnt = {style: cmnt_style, lines: [str], pos: uint}; -fn read_to_eol(rdr: &reader) -> istr { - let val = ~""; +fn read_to_eol(rdr: &reader) -> str { + let val = ""; while rdr.curr() != '\n' && !rdr.is_eof() { str::push_char(val, rdr.curr()); rdr.bump(); @@ -576,7 +561,7 @@ fn read_to_eol(rdr: &reader) -> istr { ret val; } -fn read_one_line_comment(rdr: &reader) -> istr { +fn read_one_line_comment(rdr: &reader) -> str { let val = read_to_eol(rdr); assert (val[0] == '/' as u8 && val[1] == '/' as u8); ret val; @@ -594,7 +579,7 @@ fn consume_non_eol_whitespace(rdr: &reader) { fn push_blank_line_comment(rdr: &reader, comments: &mutable [cmnt]) { log ">>> blank-line comment"; - let v: [istr] = []; + let v: [str] = []; comments += [{style: blank_line, lines: v, pos: rdr.get_chpos()}]; } @@ -611,7 +596,7 @@ 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: [istr] = []; + let lines: [str] = []; while rdr.curr() == '/' && rdr.next() == '/' { let line = read_one_line_comment(rdr); log line; @@ -624,52 +609,52 @@ fn read_line_comments(rdr: &reader, code_to_the_left: bool) -> cmnt { pos: p}; } -fn all_whitespace(s: &istr, begin: uint, end: uint) -> bool { +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; } ret true; } -fn trim_whitespace_prefix_and_push_line(lines: &mutable [istr], s: &istr, +fn trim_whitespace_prefix_and_push_line(lines: &mutable [str], s: &str, col: uint) { let s1; if all_whitespace(s, 0u, col) { if col < str::byte_len(s) { s1 = str::slice(s, col, str::byte_len(s)); - } else { s1 = ~""; } + } else { s1 = ""; } } else { s1 = s; } - log ~"pushing line: " + s1; + log "pushing line: " + 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: [istr] = []; + let lines: [str] = []; let col: uint = rdr.get_col(); rdr.bump(); rdr.bump(); - let curr_line = ~"/*"; + let curr_line = "/*"; let level: int = 1; while level > 0 { log #fmt["=== block comment level %d", level]; - if rdr.is_eof() { rdr.err(~"unterminated block comment"); fail; } + if rdr.is_eof() { rdr.err("unterminated block comment"); fail; } if rdr.curr() == '\n' { trim_whitespace_prefix_and_push_line(lines, curr_line, col); - curr_line = ~""; + curr_line = ""; rdr.bump(); } else { str::push_char(curr_line, rdr.curr()); if rdr.curr() == '/' && rdr.next() == '*' { rdr.bump(); rdr.bump(); - curr_line += ~"*"; + curr_line += "*"; level += 1; } else { if rdr.curr() == '*' && rdr.next() == '/' { rdr.bump(); rdr.bump(); - curr_line += ~"/"; + curr_line += "/"; level -= 1; } else { rdr.bump(); } } @@ -717,16 +702,14 @@ fn is_lit(t: &token::token) -> bool { } } -type lit = {lit: istr, pos: uint}; +type lit = {lit: str, pos: uint}; -fn gather_comments_and_literals(cm: &codemap::codemap, path: &istr, +fn gather_comments_and_literals(cm: &codemap::codemap, path: &str, srdr: io::reader) -> {cmnts: [cmnt], lits: [lit]} { let src = str::unsafe_from_bytes(srdr.read_whole_stream()); - let itr = @interner::mk::<istr>(str::hash, str::eq); - let rdr = new_reader(cm, src, - codemap::new_filemap( - path, 0u, 0u), itr); + 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 first_read: bool = true; @@ -748,7 +731,7 @@ fn gather_comments_and_literals(cm: &codemap::codemap, path: &istr, if is_lit(tok.tok) { literals += [{lit: rdr.get_str_from(tok.bpos), pos: tok.chpos}]; } - log ~"tok: " + token::to_str(rdr, tok.tok); + log "tok: " + token::to_str(rdr, tok.tok); first_read = false; } ret {cmnts: comments, lits: literals}; diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index 7be1d78d730..6c40115ecda 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -37,8 +37,8 @@ type parser = fn bump(); fn swap(token::token, uint, uint); fn look_ahead(uint) -> token::token; - fn fatal(&istr) -> ! ; - fn warn(&istr); + fn fatal(&str) -> ! ; + fn warn(&str); fn restrict(restriction); fn get_restriction() -> restriction; fn get_file_type() -> file_type; @@ -49,22 +49,21 @@ type parser = fn get_last_lo_pos() -> uint; fn get_last_hi_pos() -> uint; fn get_prec_table() -> @[op_spec]; - fn get_str(token::str_num) -> istr; + fn get_str(token::str_num) -> str; fn get_reader() -> lexer::reader; fn get_filemap() -> codemap::filemap; - fn get_bad_expr_words() -> hashmap<istr, ()>; + 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: &istr, +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); + let filemap = codemap::new_filemap(path, chpos, byte_pos); sess.cm.files += [filemap]; let itr = @interner::mk(str::hash, str::eq); let rdr = lexer::new_reader(sess.cm, src, filemap, itr); @@ -83,7 +82,7 @@ fn new_parser(sess: parse_sess, cfg: &ast::crate_cfg, rdr: lexer::reader, mutable restr: restriction, rdr: lexer::reader, precs: @[op_spec], - bad_words: hashmap<istr, ()>) { + bad_words: hashmap<str, ()>) { fn peek() -> token::token { ret tok; } fn bump() { last_tok_span = tok_span; @@ -109,14 +108,12 @@ fn new_parser(sess: parse_sess, cfg: &ast::crate_cfg, rdr: lexer::reader, } ret buffer[distance - 1u].tok; } - fn fatal(m: &istr) -> ! { - codemap::emit_error(some(self.get_span()), - m, sess.cm); + fn fatal(m: &str) -> ! { + codemap::emit_error(some(self.get_span()), m, sess.cm); fail; } - fn warn(m: &istr) { - codemap::emit_warning(some(self.get_span()), - m, sess.cm); + fn warn(m: &str) { + codemap::emit_warning(some(self.get_span()), m, sess.cm); } fn restrict(r: restriction) { restr = r; } fn get_restriction() -> restriction { ret restr; } @@ -128,12 +125,12 @@ fn new_parser(sess: parse_sess, cfg: &ast::crate_cfg, rdr: lexer::reader, fn get_file_type() -> file_type { ret ftype; } fn get_cfg() -> ast::crate_cfg { ret cfg; } fn get_prec_table() -> @[op_spec] { ret precs; } - fn get_str(i: token::str_num) -> istr { + fn get_str(i: token::str_num) -> str { ret interner::get(*rdr.get_interner(), i); } fn get_reader() -> lexer::reader { ret rdr; } fn get_filemap() -> codemap::filemap { ret rdr.get_filemap(); } - fn get_bad_expr_words() -> hashmap<istr, ()> { ret bad_words; } + fn get_bad_expr_words() -> hashmap<str, ()> { ret bad_words; } fn get_chpos() -> uint { ret rdr.get_chpos(); } fn get_byte_pos() -> uint { ret rdr.get_byte_pos(); } fn get_id() -> node_id { ret next_node_id(sess); } @@ -148,48 +145,48 @@ fn new_parser(sess: parse_sess, cfg: &ast::crate_cfg, rdr: lexer::reader, // These are the words that shouldn't be allowed as value identifiers, // because, if used at the start of a line, they will cause the line to be // interpreted as a specific kind of statement, which would be confusing. -fn bad_expr_word_table() -> hashmap<istr, ()> { +fn bad_expr_word_table() -> hashmap<str, ()> { let words = new_str_hash(); - words.insert(~"mod", ()); - words.insert(~"if", ()); - words.insert(~"else", ()); - words.insert(~"while", ()); - words.insert(~"do", ()); - words.insert(~"alt", ()); - words.insert(~"for", ()); - words.insert(~"each", ()); - words.insert(~"break", ()); - words.insert(~"cont", ()); - words.insert(~"put", ()); - words.insert(~"ret", ()); - words.insert(~"be", ()); - words.insert(~"fail", ()); - words.insert(~"type", ()); - words.insert(~"resource", ()); - words.insert(~"check", ()); - words.insert(~"assert", ()); - words.insert(~"claim", ()); - words.insert(~"prove", ()); - words.insert(~"native", ()); - words.insert(~"fn", ()); - words.insert(~"lambda", ()); - words.insert(~"pure", ()); - words.insert(~"iter", ()); - words.insert(~"block", ()); - words.insert(~"import", ()); - words.insert(~"export", ()); - words.insert(~"let", ()); - words.insert(~"const", ()); - words.insert(~"log", ()); - words.insert(~"log_err", ()); - words.insert(~"tag", ()); - words.insert(~"obj", ()); - words.insert(~"copy", ()); + words.insert("mod", ()); + words.insert("if", ()); + words.insert("else", ()); + words.insert("while", ()); + words.insert("do", ()); + words.insert("alt", ()); + words.insert("for", ()); + words.insert("each", ()); + words.insert("break", ()); + words.insert("cont", ()); + words.insert("put", ()); + words.insert("ret", ()); + words.insert("be", ()); + words.insert("fail", ()); + words.insert("type", ()); + words.insert("resource", ()); + words.insert("check", ()); + words.insert("assert", ()); + words.insert("claim", ()); + words.insert("prove", ()); + words.insert("native", ()); + words.insert("fn", ()); + words.insert("lambda", ()); + words.insert("pure", ()); + words.insert("iter", ()); + words.insert("block", ()); + words.insert("import", ()); + words.insert("export", ()); + words.insert("let", ()); + words.insert("const", ()); + words.insert("log", ()); + words.insert("log_err", ()); + words.insert("tag", ()); + words.insert("obj", ()); + words.insert("copy", ()); ret words; } fn unexpected(p: &parser, t: token::token) -> ! { - let s: istr = ~"unexpected token: "; + let s: str = "unexpected token: "; s += token::to_str(p.get_reader(), t); p.fatal(s); } @@ -198,9 +195,9 @@ fn expect(p: &parser, t: token::token) { if p.peek() == t { p.bump(); } else { - let s: istr = ~"expecting "; + let s: str = "expecting "; s += token::to_str(p.get_reader(), t); - s += ~", found "; + s += ", found "; s += token::to_str(p.get_reader(), p.peek()); p.fatal(s); } @@ -214,9 +211,9 @@ fn expect_gt(p: &parser) { } else if p.peek() == token::BINOP(token::ASR) { p.swap(token::BINOP(token::LSR), p.get_lo_pos() + 1u, p.get_hi_pos()); } else { - let s: istr = ~"expecting "; + let s: str = "expecting "; s += token::to_str(p.get_reader(), token::GT); - s += ~", found "; + s += ", found "; s += token::to_str(p.get_reader(), p.peek()); p.fatal(s); } @@ -228,11 +225,8 @@ fn spanned<@T>(lo: uint, hi: uint, node: &T) -> spanned<T> { fn parse_ident(p: &parser) -> ast::ident { alt p.peek() { - token::IDENT(i, _) { - p.bump(); - ret p.get_str(i); - } - _ { p.fatal(~"expecting ident"); } + token::IDENT(i, _) { p.bump(); ret p.get_str(i); } + _ { p.fatal("expecting ident"); } } } @@ -245,14 +239,14 @@ fn eat(p: &parser, tok: &token::token) -> bool { ret if p.peek() == tok { p.bump(); true } else { false }; } -fn is_word(p: &parser, word: &istr) -> bool { +fn is_word(p: &parser, word: &str) -> bool { ret alt p.peek() { token::IDENT(sid, false) { str::eq(word, p.get_str(sid)) } _ { false } }; } -fn eat_word(p: &parser, word: &istr) -> bool { +fn eat_word(p: &parser, word: &str) -> bool { alt p.peek() { token::IDENT(sid, false) { if str::eq(word, p.get_str(sid)) { @@ -264,10 +258,10 @@ fn eat_word(p: &parser, word: &istr) -> bool { } } -fn expect_word(p: &parser, word: &istr) { +fn expect_word(p: &parser, word: &str) { if !eat_word(p, word) { - p.fatal(~"expecting " + word + ~", found " + - token::to_str(p.get_reader(), p.peek())); + p.fatal("expecting " + word + ", found " + + token::to_str(p.get_reader(), p.peek())); } } @@ -276,7 +270,7 @@ fn check_bad_word(p: &parser) { token::IDENT(sid, false) { let w = p.get_str(sid); if p.get_bad_expr_words().contains_key(w) { - p.fatal(~"found " + w + ~" in expression position"); + p.fatal("found " + w + " in expression position"); } } _ { } @@ -294,7 +288,7 @@ fn parse_ty_fn(proto: ast::proto, p: &parser) -> ast::ty_ { let mode = ast::val; if p.peek() == token::BINOP(token::AND) { p.bump(); - mode = ast::alias(eat_word(p, ~"mutable")); + mode = ast::alias(eat_word(p, "mutable")); } let t = parse_ty(p, false); ret spanned(lo, t.span.hi, {mode: mode, ty: t}); @@ -323,11 +317,11 @@ fn parse_ty_fn(proto: ast::proto, p: &parser) -> ast::ty_ { } fn parse_proto(p: &parser) -> ast::proto { - if eat_word(p, ~"iter") { + 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 { unexpected(p, p.peek()); } } @@ -377,8 +371,7 @@ fn parse_ty_field(p: &parser) -> ast::ty_field { fn ident_index(p: &parser, args: &[ast::arg], i: &ast::ident) -> uint { let j = 0u; for a: ast::arg in args { if a.ident == i { ret j; } j += 1u; } - p.fatal(~"Unbound variable " + - i + ~" in constraint arg"); + p.fatal("Unbound variable " + i + " in constraint arg"); } fn parse_type_constr_arg(p: &parser) -> @ast::ty_constr_arg { @@ -467,7 +460,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"); } } } @@ -484,43 +477,43 @@ fn parse_ty(p: &parser, colons_before_params: bool) -> @ast::ty { let t: ast::ty_; // FIXME: do something with this - if eat_word(p, ~"bool") { + 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_istr; - } 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, "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 { p.bump(); @@ -567,19 +560,19 @@ fn parse_ty(p: &parser, colons_before_params: bool) -> @ast::ty { 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") { - p.warn(~"ignoring deprecated 'mutable' type constructor"); + } 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; @@ -587,13 +580,13 @@ fn parse_ty(p: &parser, colons_before_params: bool) -> @ast::ty { let path = parse_path(p); t = ast::ty_path(path, p.get_id()); hi = path.span.hi; - } else { p.fatal(~"expecting type"); } + } else { p.fatal("expecting type"); } ret parse_ty_postfix(t, p, colons_before_params); } fn parse_arg_mode(p: &parser) -> ast::mode { if eat(p, token::BINOP(token::AND)) { - ast::alias(eat_word(p, ~"mutable")) + ast::alias(eat_word(p, "mutable")) } else if eat(p, token::BINOP(token::MINUS)) { ast::move } else { ast::val } @@ -685,9 +678,9 @@ fn parse_seq<T>(bra: token::token, ket: token::token, fn parse_lit(p: &parser) -> ast::lit { let sp = p.get_span(); let lit: ast::lit_ = ast::lit_nil; - if eat_word(p, ~"true") { + 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() { @@ -706,10 +699,7 @@ fn parse_lit(p: &parser) -> ast::lit { lit = ast::lit_mach_float(tm, p.get_str(s)); } token::LIT_CHAR(c) { p.bump(); lit = ast::lit_char(c); } - token::LIT_STR(s) { - p.bump(); - lit = ast::lit_str(p.get_str(s)); - } + token::LIT_STR(s) { p.bump(); lit = ast::lit_str(p.get_str(s)); } token::LPAREN. { p.bump(); expect(p, token::RPAREN); @@ -777,7 +767,7 @@ fn parse_path_and_ty_param_substs(p: &parser) -> ast::path { } fn parse_mutability(p: &parser) -> ast::mutability { - if eat_word(p, ~"mutable") { + if eat_word(p, "mutable") { if p.peek() == token::QUES { p.bump(); ret ast::maybe_mut; } ret ast::mut; } @@ -825,12 +815,12 @@ fn parse_bottom_expr(p: &parser) -> @ast::expr { } else { ret mk_expr(p, lo, hi, ast::expr_tup(es)); } } else if p.peek() == token::LBRACE { p.bump(); - if is_word(p, ~"mutable") || + if is_word(p, "mutable") || is_plain_ident(p) && p.look_ahead(1u) == 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; } + if eat_word(p, "with") { base = some(parse_expr(p)); break; } expect(p, token::COMMA); fields += [parse_field(p, token::COLON)]; } @@ -843,27 +833,27 @@ fn parse_bottom_expr(p: &parser) -> @ast::expr { let blk = parse_block_tail(p, lo, ast::checked); 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, "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 eat_word(p, ~"unchecked") { + } else if eat_word(p, "unchecked") { expect(p, token::LBRACE); let blk = parse_block_tail(p, lo, ast::unchecked); ret mk_expr(p, blk.span.lo, blk.span.hi, ast::expr_block(blk)); @@ -894,14 +884,12 @@ fn parse_bottom_expr(p: &parser) -> @ast::expr { token::LIT_STR(s) { let sp = p.get_span(); p.bump(); - let lit = - @{node: ast::lit_str(p.get_str(s)), - span: sp}; + let lit = @{node: ast::lit_str(p.get_str(s)), span: sp}; ex = ast::expr_lit(lit); } _ { 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 @@ -916,7 +904,7 @@ fn parse_bottom_expr(p: &parser) -> @ast::expr { let inner_obj: option::t<@ast::expr> = none; expect(p, token::LBRACE); while p.peek() != token::RBRACE { - if eat_word(p, ~"with") { + if eat_word(p, "with") { inner_obj = some(parse_expr(p)); } else { meths += [parse_method(p)]; } } @@ -930,7 +918,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() { @@ -947,25 +935,25 @@ fn parse_bottom_expr(p: &parser) -> @ast::expr { 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. */ @@ -973,7 +961,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 */ @@ -981,19 +969,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); } _ { @@ -1002,19 +990,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_util::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 { p.fatal("Non-call expression in tail call"); } + } 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); @@ -1024,8 +1012,8 @@ fn parse_bottom_expr(p: &parser) -> @ast::expr { 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") { + 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; @@ -1047,7 +1035,7 @@ fn parse_syntax_ext(p: &parser) -> @ast::expr { fn parse_syntax_ext_naked(p: &parser, lo: uint) -> @ast::expr { let pth = parse_path(p); if vec::len(pth.node.idents) == 0u { - p.fatal(~"expected a syntax expander name"); + p.fatal("expected a syntax expander name"); } //temporary for a backwards-compatible cycle: let es = @@ -1105,9 +1093,7 @@ fn parse_dot_or_call_expr_with(p: &parser, e: @ast::expr) -> @ast::expr { token::IDENT(i, _) { hi = p.get_hi_pos(); p.bump(); - e = mk_expr(p, lo, hi, - ast::expr_field( - e, p.get_str(i))); + e = mk_expr(p, lo, hi, ast::expr_field(e, p.get_str(i))); } t { unexpected(p, t); } } @@ -1119,8 +1105,8 @@ fn parse_dot_or_call_expr_with(p: &parser, e: @ast::expr) -> @ast::expr { } fn parse_prefix_expr(p: &parser) -> @ast::expr { - if eat_word(p, ~"mutable") { - p.warn(~"ignoring deprecated 'mutable' prefix operator"); + if eat_word(p, "mutable") { + p.warn("ignoring deprecated 'mutable' prefix operator"); } let lo = p.get_lo_pos(); let hi = p.get_hi_pos(); @@ -1223,7 +1209,7 @@ fn parse_more_binops(p: &parser, lhs: @ast::expr, min_prec: int) -> ret parse_more_binops(p, bin, min_prec); } } - if as_prec > min_prec && eat_word(p, ~"as") { + if as_prec > min_prec && eat_word(p, "as") { let rhs = parse_ty(p, true); let _as = mk_expr(p, lhs.span.lo, rhs.span.hi, ast::expr_cast(lhs, rhs)); @@ -1286,7 +1272,7 @@ fn parse_if_expr_1(p: &parser) -> let thn = parse_block(p); let els: option::t<@ast::expr> = none; let hi = thn.span.hi; - if eat_word(p, ~"else") { + if eat_word(p, "else") { let elexpr = parse_else_expr(p); els = some(elexpr); hi = elexpr.span.hi; @@ -1295,7 +1281,7 @@ fn parse_if_expr_1(p: &parser) -> } fn parse_if_expr(p: &parser) -> @ast::expr { - if eat_word(p, ~"check") { + if eat_word(p, "check") { let q = parse_if_expr_1(p); ret mk_expr(p, q.lo, q.hi, ast::expr_if_check(q.cond, q.then, q.els)); } else { @@ -1321,7 +1307,7 @@ fn parse_fn_block_expr(p: &parser) -> @ast::expr { } fn parse_else_expr(p: &parser) -> @ast::expr { - if eat_word(p, ~"if") { + if eat_word(p, "if") { ret parse_if_expr(p); } else { let blk = parse_block(p); @@ -1331,9 +1317,9 @@ fn parse_else_expr(p: &parser) -> @ast::expr { fn parse_for_expr(p: &parser) -> @ast::expr { let lo = p.get_last_lo_pos(); - let is_each = eat_word(p, ~"each"); + let is_each = eat_word(p, "each"); let decl = parse_local(p, false); - expect_word(p, ~"in"); + expect_word(p, "in"); let seq = parse_expr(p); let body = parse_block(p); let hi = body.span.hi; @@ -1353,7 +1339,7 @@ fn parse_while_expr(p: &parser) -> @ast::expr { fn parse_do_while_expr(p: &parser) -> @ast::expr { let lo = p.get_last_lo_pos(); let body = parse_block(p); - expect_word(p, ~"while"); + expect_word(p, "while"); let cond = parse_expr(p); let hi = cond.span.hi; ret mk_expr(p, lo, hi, ast::expr_do_while(body, cond)); @@ -1367,9 +1353,7 @@ fn parse_alt_expr(p: &parser) -> @ast::expr { while p.peek() != token::RBRACE { let pats = parse_pats(p); let guard = none; - if eat_word(p, ~"when") { - guard = some(parse_expr(p)); - } + if eat_word(p, "when") { guard = some(parse_expr(p)); } let blk = parse_block(p); arms += [{pats: pats, guard: guard, body: blk}]; } @@ -1402,6 +1386,7 @@ fn parse_initializer(p: &parser) -> option::t<ast::initializer> { } + // Now that the the channel is the first argument to receive, // combining it with an initializer doesn't really make sense. // case (token::RECV) { @@ -1447,8 +1432,8 @@ fn parse_pat(p: &parser) -> @ast::pat { if p.peek() == token::UNDERSCORE { p.bump(); if p.peek() != token::RBRACE { - p.fatal(~"expecting }, found " + - token::to_str(p.get_reader(), p.peek())); + p.fatal("expecting }, found " + + token::to_str(p.get_reader(), p.peek())); } etc = true; break; @@ -1461,8 +1446,7 @@ fn parse_pat(p: &parser) -> @ast::pat { subpat = parse_pat(p); } else { if p.get_bad_expr_words().contains_key(fieldname) { - p.fatal(~"found " + fieldname - + ~" in binding position"); + p.fatal("found " + fieldname + " in binding position"); } subpat = @{id: p.get_id(), @@ -1501,17 +1485,15 @@ fn parse_pat(p: &parser) -> @ast::pat { token::LIT_STR(s) { let sp = p.get_span(); p.bump(); - let lit = - @{node: ast::lit_str(p.get_str(s)), - span: sp}; + let lit = @{node: ast::lit_str(p.get_str(s)), span: sp}; hi = lit.span.hi; pat = ast::pat_lit(lit); } - _ { p.fatal(~"expected string literal"); } + _ { p.fatal("expected string literal"); } } } tok { - if !is_ident(tok) || is_word(p, ~"true") || is_word(p, ~"false") { + if !is_ident(tok) || is_word(p, "true") || is_word(p, "false") { let lit = parse_lit(p); hi = lit.span.hi; pat = ast::pat_lit(@lit); @@ -1580,7 +1562,7 @@ fn parse_crate_stmt(p: &parser) -> @ast::stmt { fn parse_source_stmt(p: &parser) -> @ast::stmt { let lo = p.get_lo_pos(); - if eat_word(p, ~"let") { + if eat_word(p, "let") { let decl = parse_let(p); ret @spanned(lo, decl.span.hi, ast::stmt_decl(decl, p.get_id())); } else { @@ -1600,7 +1582,7 @@ fn parse_source_stmt(p: &parser) -> @ast::stmt { if vec::len(item_attrs) > 0u { alt maybe_item { some(_) {/* fallthrough */ } - _ { ret p.fatal(~"expected item"); } + _ { ret p.fatal("expected item"); } } } @@ -1616,7 +1598,7 @@ fn parse_source_stmt(p: &parser) -> @ast::stmt { let e = parse_expr(p); ret @spanned(lo, e.span.hi, ast::stmt_expr(e, p.get_id())); } - _ { p.fatal(~"expected statement"); } + _ { p.fatal("expected statement"); } } } } @@ -1677,6 +1659,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; @@ -1686,10 +1669,9 @@ fn stmt_ends_with_semi(stmt: &ast::stmt) -> bool { fn parse_block(p: &parser) -> ast::blk { let lo = p.get_lo_pos(); - if eat_word(p, ~"unchecked") { + if eat_word(p, "unchecked") { be parse_block_tail(p, lo, ast::unchecked); - } - else { + } else { expect(p, token::LBRACE); be parse_block_tail(p, lo, ast::checked); } @@ -1716,8 +1698,8 @@ fn parse_block_tail(p: &parser, lo: uint, s: ast::check_mode) -> ast::blk { token::RBRACE. { expr = some(e); } t { if stmt_ends_with_semi(*stmt) { - p.fatal(~"expected ';' or '}' after " + - ~"expression but found " + + p.fatal("expected ';' or '}' after " + + "expression but found " + token::to_str(p.get_reader(), t)); } stmts += [stmt]; @@ -1935,7 +1917,7 @@ fn parse_mod_items(p: &parser, term: token::token, alt parse_item(p, attrs) { some(i) { items += [i]; } _ { - p.fatal(~"expected item but found " + + p.fatal("expected item but found " + token::to_str(p.get_reader(), p.peek())); } } @@ -1985,10 +1967,7 @@ fn parse_item_native_fn(p: &parser, attrs: &[ast::attribute]) -> let t = parse_fn_header(p); let decl = parse_fn_decl(p, ast::impure_fn, ast::il_normal); let link_name = none; - if p.peek() == token::EQ { - p.bump(); - link_name = some(parse_str(p)); - } + if p.peek() == token::EQ { p.bump(); link_name = some(parse_str(p)); } let hi = p.get_hi_pos(); expect(p, token::SEMI); ret @{ident: t.ident, @@ -2000,15 +1979,14 @@ fn parse_item_native_fn(p: &parser, attrs: &[ast::attribute]) -> fn parse_native_item(p: &parser, attrs: &[ast::attribute]) -> @ast::native_item { - if eat_word(p, ~"type") { + 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: &istr, - abi: ast::native_abi, +fn parse_native_mod_items(p: &parser, native_name: &str, abi: ast::native_abi, first_item_attrs: &[ast::attribute]) -> ast::native_mod { // Shouldn't be any view items since we've already parsed an item attr @@ -2032,20 +2010,20 @@ fn parse_native_mod_items(p: &parser, native_name: &istr, fn parse_item_native_mod(p: &parser, attrs: &[ast::attribute]) -> @ast::item { let lo = p.get_last_lo_pos(); let abi = ast::native_abi_cdecl; - if !is_word(p, ~"mod") { + if !is_word(p, "mod") { let t = parse_str(p); - if str::eq(t, ~"cdecl") { - } else if str::eq(t, ~"rust") { + if str::eq(t, "cdecl") { + } 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); } + } else { p.fatal("unsupported abi: " + t); } } - expect_word(p, ~"mod"); + expect_word(p, "mod"); let id = parse_ident(p); let native_name; if p.peek() == token::EQ { @@ -2087,8 +2065,7 @@ fn parse_item_tag(p: &parser, attrs: &[ast::attribute]) -> @ast::item { // Newtype syntax if p.peek() == token::EQ { if p.get_bad_expr_words().contains_key(id) { - p.fatal(~"found " + id - + ~" in tag constructor position"); + p.fatal("found " + id + " in tag constructor position"); } p.bump(); let ty = parse_ty(p, false); @@ -2125,13 +2102,12 @@ 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()}; + let vr = {name: p.get_str(name), args: args, id: p.get_id()}; variants += [spanned(vlo, vhi, vr)]; } token::RBRACE. {/* empty */ } _ { - p.fatal(~"expected name of variant or '}' but found " + + p.fatal("expected name of variant or '}' but found " + token::to_str(p.get_reader(), tok)); } } @@ -2142,42 +2118,42 @@ fn parse_item_tag(p: &parser, attrs: &[ast::attribute]) -> @ast::item { } fn parse_auth(p: &parser) -> ast::_auth { - if eat_word(p, ~"unsafe") { + if eat_word(p, "unsafe") { ret ast::auth_unsafe; } else { unexpected(p, p.peek()); } } fn parse_item(p: &parser, attrs: &[ast::attribute]) -> option::t<@ast::item> { - if eat_word(p, ~"const") { + if eat_word(p, "const") { ret some(parse_item_const(p, attrs)); - } else if eat_word(p, ~"inline") { - expect_word(p, ~"fn"); + } 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, ~"pure") { - expect_word(p, ~"fn"); + } else if eat_word(p, "pure") { + expect_word(p, "fn"); 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, "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") { + 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; } } @@ -2297,18 +2273,19 @@ fn parse_rest_import_name(p: &parser, first: &ast::ident, 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"); + p.fatal("cannot path into import list"); } p.bump(); } - _ { p.fatal(~"expecting '::' or ';'"); } + _ { p.fatal("expecting '::' or ';'"); } } alt p.peek() { token::IDENT(_, _) { identifiers += [parse_ident(p)]; } + //the lexer can't tell the different kinds of stars apart ) : token::BINOP(token::STAR.) { glob = true; @@ -2316,6 +2293,7 @@ fn parse_rest_import_name(p: &parser, first: &ast::ident, } + token::LBRACE. { fn parse_import_ident(p: &parser) -> ast::import_ident { let lo = p.get_lo_pos(); @@ -2327,22 +2305,23 @@ fn parse_rest_import_name(p: &parser, first: &ast::ident, 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"); + 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"); + p.fatal("can't rename import list"); } ret ast::view_item_import(i, identifiers, p.get_id()); } @@ -2367,10 +2346,9 @@ fn parse_full_import_name(p: &parser, def_ident: &ast::ident) -> alt p.peek() { token::IDENT(i, _) { p.bump(); - ret parse_rest_import_name( - p, p.get_str(i), some(def_ident)); + ret parse_rest_import_name(p, p.get_str(i), some(def_ident)); } - _ { p.fatal(~"expecting an identifier"); } + _ { p.fatal("expecting an identifier"); } } } @@ -2383,13 +2361,10 @@ fn parse_import(p: &parser) -> ast::view_item_ { p.bump(); ret parse_full_import_name(p, p.get_str(i)); } - _ { - ret parse_rest_import_name( - p, p.get_str(i), none); - } + _ { ret parse_rest_import_name(p, p.get_str(i), none); } } } - _ { p.fatal(~"expecting an identifier"); } + _ { p.fatal("expecting an identifier"); } } } @@ -2403,11 +2378,11 @@ fn parse_export(p: &parser) -> ast::view_item_ { fn parse_view_item(p: &parser) -> @ast::view_item { let lo = p.get_lo_pos(); let the_item = - if eat_word(p, ~"use") { + 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); @@ -2417,8 +2392,8 @@ fn is_view_item(p: &parser) -> bool { alt p.peek() { token::IDENT(sid, false) { let st = p.get_str(sid); - ret str::eq(st, ~"use") || str::eq(st, ~"import") || - str::eq(st, ~"export"); + ret str::eq(st, "use") || str::eq(st, "import") || + str::eq(st, "export"); } _ { ret false; } } @@ -2436,21 +2411,19 @@ fn parse_native_view(p: &parser) -> [@ast::view_item] { ret items; } -fn parse_crate_from_source_file(input: &istr, cfg: &ast::crate_cfg, +fn parse_crate_from_source_file(input: &str, cfg: &ast::crate_cfg, sess: &parse_sess) -> @ast::crate { let p = new_parser_from_file(sess, cfg, input, 0u, 0u, SOURCE_FILE); ret parse_crate_mod(p, cfg); } -fn parse_crate_from_source_str(name: &istr, source: &istr, - cfg: &ast::crate_cfg, +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]; let itr = @interner::mk(str::hash, str::eq); - let rdr = lexer::new_reader(sess.cm, source, - filemap, itr); + let rdr = lexer::new_reader(sess.cm, source, filemap, itr); let p = new_parser(sess, cfg, rdr, ftype); ret parse_crate_mod(p, cfg); } @@ -2468,7 +2441,7 @@ fn parse_crate_mod(p: &parser, _cfg: &ast::crate_cfg) -> @ast::crate { config: p.get_cfg()}); } -fn parse_str(p: &parser) -> istr { +fn parse_str(p: &parser) -> str { alt p.peek() { token::LIT_STR(s) { p.bump(); ret p.get_str(s); } _ { fail; } @@ -2489,8 +2462,8 @@ fn parse_crate_directive(p: &parser, first_outer_attr: &[ast::attribute]) -> let expect_mod = vec::len(outer_attrs) > 0u; let lo = p.get_lo_pos(); - if expect_mod || is_word(p, ~"mod") { - expect_word(p, ~"mod"); + if expect_mod || is_word(p, "mod") { + expect_word(p, "mod"); let id = parse_ident(p); let file_opt = alt p.peek() { @@ -2500,6 +2473,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(); @@ -2508,6 +2482,7 @@ fn parse_crate_directive(p: &parser, first_outer_attr: &[ast::attribute]) -> } + // mod x = "foo_dir" { ...directives... } token::LBRACE. { p.bump(); @@ -2523,7 +2498,7 @@ 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); @@ -2533,7 +2508,7 @@ fn parse_crate_directive(p: &parser, first_outer_attr: &[ast::attribute]) -> } 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"); } + } else { ret p.fatal("expected crate directive"); } } fn parse_crate_directives(p: &parser, term: token::token, @@ -2544,7 +2519,7 @@ fn parse_crate_directives(p: &parser, term: token::token, // seeing the terminator next, so if we do see it then fail the same way // parse_crate_directive would if vec::len(first_outer_attr) > 0u && p.peek() == term { - expect_word(p, ~"mod"); + expect_word(p, "mod"); } let cdirs: [@ast::crate_directive] = []; @@ -2555,17 +2530,16 @@ fn parse_crate_directives(p: &parser, term: token::token, ret cdirs; } -fn parse_crate_from_crate_file(input: &istr, cfg: &ast::crate_cfg, +fn parse_crate_from_crate_file(input: &str, cfg: &ast::crate_cfg, sess: &parse_sess) -> @ast::crate { let p = new_parser_from_file(sess, cfg, input, 0u, 0u, CRATE_FILE); let lo = p.get_lo_pos(); - let prefix = - std::fs::dirname(p.get_filemap().name); + let prefix = std::fs::dirname(p.get_filemap().name); let leading_attrs = parse_inner_attrs_and_next(p); 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: [istr] = []; + let deps: [str] = []; let cx = @{p: p, mode: eval::mode_parse, @@ -2584,15 +2558,14 @@ fn parse_crate_from_crate_file(input: &istr, cfg: &ast::crate_cfg, config: p.get_cfg()}); } -fn parse_crate_from_file(input: &istr, cfg: &ast::crate_cfg, - sess: &parse_sess) -> @ast::crate { - if str::ends_with(input, ~".rc") { +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") { + } 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 24d2a3b9a6f..153f5236c4b 100644 --- a/src/comp/syntax/parse/token.rs +++ b/src/comp/syntax/parse/token.rs @@ -84,62 +84,64 @@ tag token { EOF; } -fn binop_to_str(o: binop) -> istr { +fn binop_to_str(o: binop) -> str { alt o { - PLUS. { ret ~"+"; } - MINUS. { ret ~"-"; } - STAR. { ret ~"*"; } - SLASH. { ret ~"/"; } - PERCENT. { ret ~"%"; } - CARET. { ret ~"^"; } - AND. { ret ~"&"; } - OR. { ret ~"|"; } - LSL. { ret ~"<<"; } - LSR. { ret ~">>"; } - ASR. { ret ~">>>"; } + PLUS. { ret "+"; } + MINUS. { ret "-"; } + STAR. { ret "*"; } + SLASH. { ret "/"; } + PERCENT. { ret "%"; } + CARET. { ret "^"; } + AND. { ret "&"; } + OR. { ret "|"; } + LSL. { ret "<<"; } + LSR. { ret ">>"; } + ASR. { ret ">>>"; } } } -fn to_str(r: lexer::reader, t: token) -> istr { +fn to_str(r: lexer::reader, t: token) -> str { alt t { - EQ. { ret ~"="; } - LT. { ret ~"<"; } - LE. { ret ~"<="; } - EQEQ. { ret ~"=="; } - NE. { ret ~"!="; } - GE. { ret ~">="; } - GT. { ret ~">"; } - NOT. { ret ~"!"; } - TILDE. { ret ~"~"; } - OROR. { ret ~"||"; } - ANDAND. { ret ~"&&"; } + EQ. { ret "="; } + LT. { ret "<"; } + LE. { ret "<="; } + EQEQ. { ret "=="; } + NE. { ret "!="; } + GE. { ret ">="; } + GT. { ret ">"; } + NOT. { ret "!"; } + TILDE. { ret "~"; } + OROR. { ret "||"; } + ANDAND. { ret "&&"; } BINOP(op) { ret binop_to_str(op); } - BINOPEQ(op) { ret binop_to_str(op) + ~"="; } + BINOPEQ(op) { ret binop_to_str(op) + "="; } + /* Structural symbols */ AT. { - ret ~"@"; + ret "@"; } - DOT. { ret ~"."; } - ELLIPSIS. { ret ~"..."; } - COMMA. { ret ~","; } - SEMI. { ret ~";"; } - COLON. { ret ~":"; } - MOD_SEP. { ret ~"::"; } - QUES. { ret ~"?"; } - RARROW. { ret ~"->"; } - LARROW. { ret ~"<-"; } - DARROW. { ret ~"<->"; } - LPAREN. { ret ~"("; } - RPAREN. { ret ~")"; } - LBRACKET. { ret ~"["; } - RBRACKET. { ret ~"]"; } - LBRACE. { ret ~"{"; } - RBRACE. { ret ~"}"; } - POUND. { ret ~"#"; } - POUND_LBRACE. { ret ~"#{"; } - POUND_LT. { ret ~"#<"; } + DOT. { ret "."; } + ELLIPSIS. { ret "..."; } + COMMA. { ret ","; } + SEMI. { ret ";"; } + COLON. { ret ":"; } + MOD_SEP. { ret "::"; } + QUES. { ret "?"; } + RARROW. { ret "->"; } + LARROW. { ret "<-"; } + DARROW. { ret "<->"; } + LPAREN. { ret "("; } + RPAREN. { ret ")"; } + LBRACKET. { ret "["; } + RBRACKET. { ret "]"; } + LBRACE. { ret "{"; } + RBRACE. { ret "}"; } + POUND. { ret "#"; } + POUND_LBRACE. { ret "#{"; } + POUND_LT. { ret "#<"; } + /* Literals */ @@ -148,39 +150,35 @@ fn to_str(r: lexer::reader, t: token) -> istr { } LIT_UINT(u) { ret uint::to_str(u, 10u); } LIT_MACH_INT(tm, i) { - ret int::to_str(i, 10u) + ~"_" + ty_mach_to_str(tm); + ret int::to_str(i, 10u) + "_" + ty_mach_to_str(tm); } LIT_MACH_FLOAT(tm, s) { - ret interner::get::<istr>( - *r.get_interner(), s) + ~"_" + - ty_mach_to_str(tm); - } - LIT_FLOAT(s) { - ret interner::get::<istr>(*r.get_interner(), s); + ret interner::get::<str>(*r.get_interner(), s) + "_" + + ty_mach_to_str(tm); } + LIT_FLOAT(s) { ret interner::get::<str>(*r.get_interner(), s); } LIT_STR(s) { // FIXME: escape. - ret ~"\"" + - interner::get::<istr>(*r.get_interner(), s) - + ~"\""; + ret "\"" + interner::get::<str>(*r.get_interner(), s) + "\""; } LIT_CHAR(c) { // FIXME: escape. - let tmp = ~"'"; + let tmp = "'"; str::push_char(tmp, c); str::push_byte(tmp, '\'' as u8); ret tmp; } - LIT_BOOL(b) { if b { ret ~"true"; } else { ret ~"false"; } } + LIT_BOOL(b) { if b { ret "true"; } else { ret "false"; } } + /* Name components */ IDENT(s, _) { - ret interner::get::<istr>(*r.get_interner(), s); + ret interner::get::<str>(*r.get_interner(), s); } - IDX(i) { ret ~"_" + int::to_str(i, 10u); } - UNDERSCORE. { ret ~"_"; } - BRACEQUOTE(_) { ret ~"<bracequote>"; } - EOF. { ret ~"<eof>"; } + IDX(i) { ret "_" + int::to_str(i, 10u); } + UNDERSCORE. { ret "_"; } + BRACEQUOTE(_) { ret "<bracequote>"; } + EOF. { ret "<eof>"; } } } diff --git a/src/comp/syntax/print/pp.rs b/src/comp/syntax/print/pp.rs index ef92672435a..fad670fbefb 100644 --- a/src/comp/syntax/print/pp.rs +++ b/src/comp/syntax/print/pp.rs @@ -61,35 +61,33 @@ type break_t = {offset: int, blank_space: int}; type begin_t = {offset: int, breaks: breaks}; -tag token { STRING(istr, int); BREAK(break_t); BEGIN(begin_t); END; EOF; } +tag token { STRING(str, int); BREAK(break_t); BEGIN(begin_t); END; EOF; } -fn tok_str(t: token) -> istr { +fn tok_str(t: token) -> str { alt t { - STRING(s, len) { - ret #fmt[~"STR(%s,%d)", s, len]; - } - BREAK(_) { ret ~"BREAK"; } - BEGIN(_) { ret ~"BEGIN"; } - END. { ret ~"END"; } - EOF. { ret ~"EOF"; } + STRING(s, len) { ret #fmt["STR(%s,%d)", s, len]; } + BREAK(_) { ret "BREAK"; } + BEGIN(_) { ret "BEGIN"; } + END. { ret "END"; } + EOF. { ret "EOF"; } } } fn buf_str(toks: &[mutable token], szs: &[mutable int], left: uint, - right: uint, lim: uint) -> istr { + right: uint, lim: uint) -> str { let n = vec::len(toks); assert (n == vec::len(szs)); let i = left; let L = lim; - let s = ~"["; + let s = "["; while i != right && L != 0u { L -= 1u; - if i != left { s += ~", "; } - s += #fmt[~"%d=%s", szs[i], tok_str(toks[i])]; + if i != left { s += ", "; } + s += #fmt["%d=%s", szs[i], tok_str(toks[i])]; i += 1u; i %= n; } - s += ~"]"; + s += "]"; ret s; } @@ -104,7 +102,7 @@ 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); @@ -244,7 +242,7 @@ obj printer(out: io::writer, 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 { @@ -260,17 +258,17 @@ obj printer(out: io::writer, left = 0u; right = 0u; } else { self.advance_right(); } - log #fmt[~"pp BEGIN/buffer [%u,%u]", left, right]; + 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; @@ -284,7 +282,7 @@ 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; @@ -293,10 +291,10 @@ obj printer(out: io::writer, } 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; @@ -307,10 +305,10 @@ obj printer(out: io::writer, } } fn check_stream() { - log #fmt[~"check_stream [%u, %u] with left_total=%d, right_total=%d", + 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)", + 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] { @@ -392,7 +390,7 @@ obj printer(out: io::writer, } fn print_newline(amount: int) { log #fmt["NEWLINE %d", amount]; - out.write_str(~"\n"); + out.write_str("\n"); pending_indentation = 0; self.indent(amount); } @@ -406,16 +404,15 @@ obj printer(out: io::writer, if n != 0u { top = print_stack[n - 1u]; } ret top; } - fn write_str(s: &istr) { + fn write_str(s: &str) { while pending_indentation > 0 { - out.write_str(~" "); + out.write_str(" "); pending_indentation -= 1; } out.write_str(s); } fn print(x: token, L: int) { - log #fmt["print %s %d (remaining line space=%d)", - tok_str(x), L, + log #fmt["print %s %d (remaining line space=%d)", tok_str(x), L, space]; log buf_str(token, size, left, right, 6u); alt x { @@ -495,15 +492,15 @@ fn end(p: printer) { p.pretty_print(END); } fn eof(p: printer) { p.pretty_print(EOF); } -fn word(p: printer, wrd: &istr) { +fn word(p: printer, wrd: &str) { p.pretty_print(STRING(wrd, str::char_len(wrd) as int)); } -fn huge_word(p: printer, wrd: &istr) { +fn huge_word(p: printer, wrd: &str) { p.pretty_print(STRING(wrd, size_infinity)); } -fn zero_word(p: printer, wrd: &istr) { p.pretty_print(STRING(wrd, 0)); } +fn zero_word(p: printer, wrd: &str) { p.pretty_print(STRING(wrd, 0)); } fn spaces(p: printer, n: uint) { break_offset(p, n, 0); } diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs index 257404e7f65..33704b0e07c 100644 --- a/src/comp/syntax/print/pprust.rs +++ b/src/comp/syntax/print/pprust.rs @@ -74,11 +74,10 @@ const default_columns: uint = 78u; // Requires you to pass an input filename and reader so that // it can scan the input text for comments and literals to // copy forward. -fn print_crate(cm: &codemap, crate: @ast::crate, filename: &istr, +fn print_crate(cm: &codemap, crate: @ast::crate, filename: &str, in: io::reader, out: io::writer, ann: &pp_ann) { let boxes: [pp::breaks] = []; - let r = lexer::gather_comments_and_literals( - cm, filename, in); + let r = lexer::gather_comments_and_literals(cm, filename, in); let s = @{s: pp::mk_printer(out, default_columns), cm: some(cm), @@ -93,22 +92,22 @@ fn print_crate(cm: &codemap, crate: @ast::crate, filename: &istr, eof(s.s); } -fn ty_to_str(ty: &@ast::ty) -> istr { be to_str(ty, print_type); } +fn ty_to_str(ty: &@ast::ty) -> str { be to_str(ty, print_type); } -fn pat_to_str(pat: &@ast::pat) -> istr { be to_str(pat, print_pat); } +fn pat_to_str(pat: &@ast::pat) -> str { be to_str(pat, print_pat); } -fn expr_to_str(e: &@ast::expr) -> istr { be to_str(e, print_expr); } +fn expr_to_str(e: &@ast::expr) -> str { be to_str(e, print_expr); } -fn stmt_to_str(s: &ast::stmt) -> istr { be to_str(s, print_stmt); } +fn stmt_to_str(s: &ast::stmt) -> str { be to_str(s, print_stmt); } -fn item_to_str(i: &@ast::item) -> istr { be to_str(i, print_item); } +fn item_to_str(i: &@ast::item) -> str { be to_str(i, print_item); } -fn path_to_str(p: &ast::path) -> istr { +fn path_to_str(p: &ast::path) -> str { be to_str(p, bind print_path(_, _, false)); } -fn fun_to_str(f: &ast::_fn, name: &ast::ident, - params: &[ast::ty_param]) -> istr { +fn fun_to_str(f: &ast::_fn, name: &ast::ident, params: &[ast::ty_param]) -> + str { let writer = io::string_writer(); let s = rust_printer(writer.get_writer()); print_fn(s, f.decl, f.proto, name, params, f.decl.constraints); @@ -116,7 +115,7 @@ fn fun_to_str(f: &ast::_fn, name: &ast::ident, ret writer.get_str(); } -fn block_to_str(blk: &ast::blk) -> istr { +fn block_to_str(blk: &ast::blk) -> str { let writer = io::string_writer(); let s = rust_printer(writer.get_writer()); // containing cbox, will be closed by print-block at } @@ -130,11 +129,11 @@ fn block_to_str(blk: &ast::blk) -> istr { ret writer.get_str(); } -fn meta_item_to_str(mi: &ast::meta_item) -> istr { +fn meta_item_to_str(mi: &ast::meta_item) -> str { ret to_str(@mi, print_meta_item); } -fn attribute_to_str(attr: &ast::attribute) -> istr { +fn attribute_to_str(attr: &ast::attribute) -> str { be to_str(attr, print_attribute); } @@ -142,17 +141,17 @@ 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 nbsp(s: &ps) { word(s.s, ~" "); } +fn nbsp(s: &ps) { word(s.s, " "); } -fn word_nbsp(s: &ps, w: &istr) { word(s.s, w); nbsp(s); } +fn word_nbsp(s: &ps, w: &str) { word(s.s, w); nbsp(s); } -fn word_space(s: &ps, w: &istr) { word(s.s, w); space(s.s); } +fn word_space(s: &ps, w: &str) { word(s.s, w); space(s.s); } -fn popen(s: &ps) { word(s.s, ~"("); } +fn popen(s: &ps) { word(s.s, "("); } -fn pclose(s: &ps) { word(s.s, ~")"); } +fn pclose(s: &ps) { word(s.s, ")"); } -fn head(s: &ps, w: &istr) { +fn head(s: &ps, w: &str) { // outer-box is consistent cbox(s, indent_unit); // head-box is inconsistent @@ -162,14 +161,14 @@ fn head(s: &ps, w: &istr) { } fn bopen(s: &ps) { - word(s.s, ~"{"); + word(s.s, "{"); end(s); // close the head-box } fn bclose_(s: &ps, span: codemap::span, indented: uint) { maybe_print_comment(s, span.hi); break_offset_if_not_bol(s, 1u, -(indented as int)); - word(s.s, ~"}"); + word(s.s, "}"); end(s); // close the outer-box } fn bclose(s: &ps, span: codemap::span) { bclose_(s, span, indent_unit); } @@ -204,19 +203,19 @@ fn break_offset_if_not_bol(s: &ps, n: uint, off: int) { // Synthesizes a comment that was not textually present in the original source // file. -fn synth_comment(s: &ps, text: &istr) { - word(s.s, ~"/*"); +fn synth_comment(s: &ps, text: &str) { + word(s.s, "/*"); space(s.s); word(s.s, text); space(s.s); - word(s.s, ~"*/"); + word(s.s, "*/"); } 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 { - if first { first = false; } else { word_space(s, ~","); } + if first { first = false; } else { word_space(s, ","); } op(s, elt); } end(s); @@ -233,7 +232,7 @@ fn commasep_cmnt<IN>(s: &ps, b: breaks, elts: &[IN], op: fn(&ps, &IN), op(s, elt); i += 1u; if i < len { - word(s.s, ~","); + word(s.s, ","); maybe_print_trailing_comment(s, get_span(elt), some(get_span(elts[i]).hi)); space_if_not_bol(s); @@ -268,53 +267,51 @@ fn print_type(s: &ps, ty: &@ast::ty) { maybe_print_comment(s, ty.span.lo); ibox(s, 0u); alt ty.node { - ast::ty_nil. { word(s.s, ~"()"); } - ast::ty_bool. { word(s.s, ~"bool"); } - ast::ty_bot. { word(s.s, ~"!"); } - ast::ty_int. { word(s.s, ~"int"); } - ast::ty_uint. { word(s.s, ~"uint"); } - ast::ty_float. { word(s.s, ~"float"); } - ast::ty_machine(tm) { - word(s.s, ast_util::ty_mach_to_str(tm)); - } - ast::ty_char. { word(s.s, ~"char"); } - ast::ty_istr. { word(s.s, ~"str"); } - ast::ty_box(mt) { word(s.s, ~"@"); print_mt(s, mt); } + ast::ty_nil. { word(s.s, "()"); } + ast::ty_bool. { word(s.s, "bool"); } + ast::ty_bot. { word(s.s, "!"); } + ast::ty_int. { word(s.s, "int"); } + ast::ty_uint. { word(s.s, "uint"); } + ast::ty_float. { word(s.s, "float"); } + ast::ty_machine(tm) { word(s.s, ast_util::ty_mach_to_str(tm)); } + ast::ty_char. { word(s.s, "char"); } + ast::ty_istr. { word(s.s, "str"); } + ast::ty_box(mt) { word(s.s, "@"); print_mt(s, mt); } ast::ty_vec(mt) { - word(s.s, ~"["); + word(s.s, "["); alt mt.mut { - ast::mut. { word_space(s, ~"mutable"); } - ast::maybe_mut. { word_space(s, ~"mutable?"); } + ast::mut. { word_space(s, "mutable"); } + ast::maybe_mut. { word_space(s, "mutable?"); } ast::imm. { } } print_type(s, mt.ty); - word(s.s, ~"]"); + word(s.s, "]"); } - ast::ty_ptr(mt) { word(s.s, ~"*"); print_mt(s, mt); } - ast::ty_task. { word(s.s, ~"task"); } + ast::ty_ptr(mt) { word(s.s, "*"); print_mt(s, mt); } + ast::ty_task. { word(s.s, "task"); } ast::ty_port(t) { - word(s.s, ~"port<"); + word(s.s, "port<"); print_type(s, t); - word(s.s, ~">"); + word(s.s, ">"); } ast::ty_chan(t) { - word(s.s, ~"chan<"); + word(s.s, "chan<"); print_type(s, t); - word(s.s, ~">"); + word(s.s, ">"); } ast::ty_rec(fields) { - word(s.s, ~"{"); + word(s.s, "{"); fn print_field(s: &ps, f: &ast::ty_field) { cbox(s, indent_unit); print_mutability(s, f.node.mt.mut); word(s.s, f.node.ident); - word_space(s, ~":"); + word_space(s, ":"); print_type(s, f.node.mt.ty); end(s); } fn get_span(f: &ast::ty_field) -> codemap::span { ret f.span; } commasep_cmnt(s, consistent, fields, print_field, get_span); - word(s.s, ~"}"); + word(s.s, "}"); } ast::ty_tup(elts) { popen(s); @@ -322,10 +319,10 @@ fn print_type(s: &ps, ty: &@ast::ty) { pclose(s); } ast::ty_fn(proto, inputs, output, cf, constrs) { - print_ty_fn(s, proto, none::<istr>, inputs, output, cf, constrs); + print_ty_fn(s, proto, none::<str>, inputs, output, cf, constrs); } ast::ty_obj(methods) { - head(s, ~"obj"); + head(s, "obj"); bopen(s); for m: ast::ty_method in methods { hardbreak_if_not_bol(s); @@ -333,13 +330,13 @@ fn print_type(s: &ps, ty: &@ast::ty) { maybe_print_comment(s, m.span.lo); print_ty_fn(s, m.node.proto, some(m.node.ident), m.node.inputs, m.node.output, m.node.cf, m.node.constrs); - word(s.s, ~";"); + word(s.s, ";"); end(s); } bclose(s, ty.span); } ast::ty_path(path, _) { print_path(s, path, false); } - ast::ty_type. { word(s.s, ~"type"); } + ast::ty_type. { word(s.s, "type"); } ast::ty_constr(t, cs) { print_type(s, t); space(s.s); @@ -357,29 +354,26 @@ fn print_native_item(s: &ps, item: &@ast::native_item) { ast::native_item_ty. { ibox(s, indent_unit); ibox(s, 0u); - word_nbsp(s, ~"type"); + word_nbsp(s, "type"); word(s.s, item.ident); end(s); // end the inner ibox - word(s.s, ~";"); + word(s.s, ";"); end(s); // end the outer ibox } + ast::native_item_fn(lname, decl, typarams) { print_fn(s, decl, ast::proto_fn, item.ident, typarams, decl.constraints); alt lname { none. { } - some(ss) { - space(s.s); - word_space(s, ~"="); - print_string(s, ss); - } + some(ss) { space(s.s); word_space(s, "="); print_string(s, ss); } } end(s); // end head-ibox - word(s.s, ~";"); + word(s.s, ";"); end(s); // end the outer fn box } } @@ -393,46 +387,46 @@ fn print_item(s: &ps, item: &@ast::item) { s.ann.pre(ann_node); alt item.node { ast::item_const(ty, expr) { - head(s, ~"const"); - word_space(s, item.ident + ~":"); + head(s, "const"); + word_space(s, item.ident + ":"); print_type(s, ty); space(s.s); end(s); // end the head-ibox - word_space(s, ~"="); + word_space(s, "="); print_expr(s, expr); - word(s.s, ~";"); + word(s.s, ";"); end(s); // end the outer cbox } ast::item_fn(_fn, typarams) { print_fn(s, _fn.decl, _fn.proto, item.ident, typarams, _fn.decl.constraints); - word(s.s, ~" "); + word(s.s, " "); print_block(s, _fn.body); } ast::item_mod(_mod) { - head(s, ~"mod"); + head(s, "mod"); word_nbsp(s, item.ident); bopen(s); print_mod(s, _mod, item.attrs); bclose(s, item.span); } ast::item_native_mod(nmod) { - head(s, ~"native"); + head(s, "native"); alt nmod.abi { - ast::native_abi_llvm. { word_nbsp(s, ~"\"llvm\""); } - ast::native_abi_rust. { word_nbsp(s, ~"\"rust\""); } - ast::native_abi_cdecl. { word_nbsp(s, ~"\"cdecl\""); } + ast::native_abi_llvm. { word_nbsp(s, "\"llvm\""); } + ast::native_abi_rust. { word_nbsp(s, "\"rust\""); } + ast::native_abi_cdecl. { word_nbsp(s, "\"cdecl\""); } ast::native_abi_rust_intrinsic. { - word_nbsp(s, ~"\"rust-intrinsic\""); + word_nbsp(s, "\"rust-intrinsic\""); } - ast::native_abi_x86stdcall. { word_nbsp(s, ~"\"x86stdcall\""); } + ast::native_abi_x86stdcall. { word_nbsp(s, "\"x86stdcall\""); } } - word_nbsp(s, ~"mod"); + word_nbsp(s, "mod"); word_nbsp(s, item.ident); if !str::eq(nmod.native_name, item.ident) { - word_space(s, ~"="); + word_space(s, "="); print_string(s, nmod.native_name); nbsp(s); } @@ -443,15 +437,15 @@ fn print_item(s: &ps, item: &@ast::item) { ast::item_ty(ty, params) { ibox(s, indent_unit); ibox(s, 0u); - word_nbsp(s, ~"type"); + word_nbsp(s, "type"); word(s.s, item.ident); print_type_params(s, params); end(s); // end the inner ibox space(s.s); - word_space(s, ~"="); + word_space(s, "="); print_type(s, ty); - word(s.s, ~";"); + word(s.s, ";"); end(s); // end the outer ibox } ast::item_tag(variants, params) { @@ -461,15 +455,15 @@ fn print_item(s: &ps, item: &@ast::item) { vec::len(variants[0].node.args) == 1u; if newtype { ibox(s, indent_unit); - word_space(s, ~"tag"); - } else { head(s, ~"tag"); } + word_space(s, "tag"); + } else { head(s, "tag"); } word(s.s, item.ident); print_type_params(s, params); space(s.s); if newtype { - word_space(s, ~"="); + word_space(s, "="); print_type(s, variants[0].node.args[0].ty); - word(s.s, ~";"); + word(s.s, ";"); end(s); } else { bopen(s); @@ -485,21 +479,21 @@ fn print_item(s: &ps, item: &@ast::item) { commasep(s, consistent, v.node.args, print_variant_arg); pclose(s); } - word(s.s, ~";"); + word(s.s, ";"); maybe_print_trailing_comment(s, v.span, none::<uint>); } bclose(s, item.span); } } ast::item_obj(_obj, params, _) { - head(s, ~"obj"); + head(s, "obj"); word(s.s, item.ident); print_type_params(s, params); popen(s); fn print_field(s: &ps, field: &ast::obj_field) { ibox(s, indent_unit); print_mutability(s, field.mut); - word_space(s, field.ident + ~":"); + word_space(s, field.ident + ":"); print_type(s, field.ty); end(s); } @@ -514,17 +508,17 @@ fn print_item(s: &ps, item: &@ast::item) { maybe_print_comment(s, meth.span.lo); print_fn(s, meth.node.meth.decl, meth.node.meth.proto, meth.node.ident, typarams, []); - word(s.s, ~" "); + word(s.s, " "); print_block(s, meth.node.meth.body); } bclose(s, item.span); } ast::item_res(dt, dt_id, tps, ct_id) { - head(s, ~"resource"); + head(s, "resource"); word(s.s, item.ident); print_type_params(s, tps); popen(s); - word_space(s, dt.decl.inputs[0].ident + ~":"); + word_space(s, dt.decl.inputs[0].ident + ":"); print_type(s, dt.decl.inputs[0].ty); pclose(s); space(s.s); @@ -551,7 +545,7 @@ fn print_inner_attributes(s: &ps, attrs: &[ast::attribute]) { alt attr.node.style { ast::attr_inner. { print_attribute(s, attr); - word(s.s, ~";"); + word(s.s, ";"); count += 1; } _ {/* fallthrough */ } @@ -563,9 +557,9 @@ fn print_inner_attributes(s: &ps, attrs: &[ast::attribute]) { fn print_attribute(s: &ps, attr: &ast::attribute) { hardbreak_if_not_bol(s); maybe_print_comment(s, attr.span.lo); - word(s.s, ~"#["); + word(s.s, "#["); print_meta_item(s, @attr.node.value); - word(s.s, ~"]"); + word(s.s, "]"); } fn print_stmt(s: &ps, st: &ast::stmt) { @@ -574,7 +568,7 @@ fn print_stmt(s: &ps, st: &ast::stmt) { ast::stmt_decl(decl, _) { print_decl(s, decl); } ast::stmt_expr(expr, _) { space_if_not_bol(s); print_expr(s, expr); } } - if parse::parser::stmt_ends_with_semi(st) { word(s.s, ~";"); } + if parse::parser::stmt_ends_with_semi(st) { word(s.s, ";"); } maybe_print_trailing_comment(s, st.span, none::<uint>); } @@ -586,16 +580,13 @@ tag embed_type { block_macro; block_block_fn; block_normal; } fn print_possibly_embedded_block(s: &ps, blk: &ast::blk, embedded: embed_type, indented: uint) { - alt blk.node.rules { - ast::unchecked. { word(s.s, ~"unchecked"); } - _ {} - } + alt blk.node.rules { ast::unchecked. { word(s.s, "unchecked"); } _ { } } maybe_print_comment(s, blk.span.lo); let ann_node = node_block(s, blk); s.ann.pre(ann_node); alt embedded { - block_macro. { word(s.s, ~"#{"); end(s); } + block_macro. { word(s.s, "#{"); end(s); } block_block_fn. { end(s); } block_normal. { bopen(s); } } @@ -649,7 +640,7 @@ fn print_possibly_embedded_block(s: &ps, blk: &ast::blk, embedded: embed_type, _ { 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 @@ -712,8 +703,8 @@ fn print_maybe_parens_discrim(s: &ps, e: &@ast::expr) { fn print_if(s: &ps, test: &@ast::expr, blk: &ast::blk, elseopt: &option::t<@ast::expr>, chk: bool) { - head(s, ~"if"); - if chk { word_nbsp(s, ~"check"); } + head(s, "if"); + if chk { word_nbsp(s, "check"); } print_maybe_parens_discrim(s, test); space(s.s); print_block(s, blk); @@ -723,11 +714,12 @@ fn print_if(s: &ps, test: &@ast::expr, blk: &ast::blk, alt _else.node { + // "another else-if" ast::expr_if(i, t, e) { cbox(s, indent_unit - 1u); ibox(s, 0u); - word(s.s, ~" else if "); + word(s.s, " else if "); print_expr(s, i); space(s.s); print_block(s, t); @@ -735,11 +727,12 @@ fn print_if(s: &ps, test: &@ast::expr, blk: &ast::blk, } + // "final else" ast::expr_block(b) { cbox(s, indent_unit - 1u); ibox(s, 0u); - word(s.s, ~" else "); + word(s.s, " else "); print_block(s, b); } } @@ -753,21 +746,21 @@ fn print_if(s: &ps, test: &@ast::expr, blk: &ast::blk, fn print_mac(s: &ps, m: &ast::mac) { alt m.node { ast::mac_invoc(path, arg, body) { - word(s.s, ~"#"); + 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' } ast::mac_embed_type(ty) { - word(s.s, ~"#<"); + word(s.s, "#<"); print_type(s, ty); - word(s.s, ~">"); + word(s.s, ">"); } ast::mac_embed_block(blk) { print_possibly_embedded_block(s, blk, block_normal, indent_unit); } - ast::mac_ellipsis. { word(s.s, ~"..."); } + ast::mac_ellipsis. { word(s.s, "..."); } } } @@ -779,38 +772,38 @@ fn print_expr(s: &ps, expr: &@ast::expr) { alt expr.node { ast::expr_vec(exprs, mut) { ibox(s, indent_unit); - word(s.s, ~"["); + word(s.s, "["); if mut == ast::mut { - word(s.s, ~"mutable"); + word(s.s, "mutable"); if vec::len(exprs) > 0u { nbsp(s); } } commasep_exprs(s, inconsistent, exprs); - word(s.s, ~"]"); + word(s.s, "]"); end(s); } ast::expr_rec(fields, wth) { fn print_field(s: &ps, field: &ast::field) { ibox(s, indent_unit); - if field.node.mut == ast::mut { word_nbsp(s, ~"mutable"); } + if field.node.mut == ast::mut { word_nbsp(s, "mutable"); } word(s.s, field.node.ident); - word_space(s, ~":"); + word_space(s, ":"); print_expr(s, field.node.expr); end(s); } fn get_span(field: &ast::field) -> codemap::span { ret field.span; } - word(s.s, ~"{"); + word(s.s, "{"); commasep_cmnt(s, consistent, fields, print_field, get_span); alt wth { some(expr) { if vec::len(fields) > 0u { space(s.s); } ibox(s, indent_unit); - word_space(s, ~"with"); + word_space(s, "with"); print_expr(s, expr); end(s); } _ { } } - word(s.s, ~"}"); + word(s.s, "}"); } ast::expr_tup(exprs) { popen(s); @@ -824,17 +817,17 @@ fn print_expr(s: &ps, expr: &@ast::expr) { pclose(s); } ast::expr_self_method(ident) { - word(s.s, ~"self."); + word(s.s, "self."); print_ident(s, ident); } ast::expr_bind(func, args) { fn print_opt(s: &ps, expr: &option::t<@ast::expr>) { alt expr { some(expr) { print_expr(s, expr); } - _ { word(s.s, ~"_"); } + _ { word(s.s, "_"); } } } - word_nbsp(s, ~"bind"); + word_nbsp(s, "bind"); print_expr(s, func); popen(s); commasep(s, inconsistent, args, print_opt); @@ -855,7 +848,7 @@ fn print_expr(s: &ps, expr: &@ast::expr) { ast::expr_cast(expr, ty) { print_maybe_parens(s, expr, parse::parser::as_prec); space(s.s); - word_space(s, ~"as"); + word_space(s, "as"); print_type(s, ty); } ast::expr_if(test, blk, elseopt) { @@ -867,42 +860,42 @@ fn print_expr(s: &ps, expr: &@ast::expr) { ast::expr_ternary(test, then, els) { print_expr(s, test); space(s.s); - word_space(s, ~"?"); + word_space(s, "?"); print_expr(s, then); space(s.s); - word_space(s, ~":"); + word_space(s, ":"); print_expr(s, els); } ast::expr_while(test, blk) { - head(s, ~"while"); + head(s, "while"); print_maybe_parens_discrim(s, test); space(s.s); print_block(s, blk); } ast::expr_for(decl, expr, blk) { - head(s, ~"for"); + head(s, "for"); print_for_decl(s, decl, expr); space(s.s); print_block(s, blk); } ast::expr_for_each(decl, expr, blk) { - head(s, ~"for each"); + head(s, "for each"); print_for_decl(s, decl, expr); space(s.s); print_block(s, blk); } ast::expr_do_while(blk, expr) { - head(s, ~"do"); + head(s, "do"); space(s.s); print_block(s, blk); space(s.s); - word_space(s, ~"while"); + word_space(s, "while"); print_expr(s, expr); } ast::expr_alt(expr, arms) { cbox(s, alt_indent_unit); ibox(s, 4u); - word_nbsp(s, ~"alt"); + word_nbsp(s, "alt"); print_maybe_parens_discrim(s, expr); space(s.s); bopen(s); @@ -914,17 +907,13 @@ fn print_expr(s: &ps, expr: &@ast::expr) { for p: @ast::pat in arm.pats { if first { first = false; - } else { space(s.s); word_space(s, ~"|"); } + } else { space(s.s); word_space(s, "|"); } print_pat(s, p); } space(s.s); alt arm.guard { - some(e) { - word_space(s, ~"when"); - print_expr(s, e); - space(s.s); - } - none. {} + some(e) { word_space(s, "when"); print_expr(s, e); space(s.s); } + none. { } } print_possibly_embedded_block(s, arm.body, block_normal, alt_indent_unit); @@ -940,7 +929,7 @@ fn print_expr(s: &ps, expr: &@ast::expr) { cbox(s, indent_unit); // head-box, will be closed by print-block at start ibox(s, 0u); - word(s.s, ~"{"); + word(s.s, "{"); print_fn_block_args(s, f.decl); print_possibly_embedded_block(s, f.body, block_block_fn, indent_unit); @@ -958,102 +947,100 @@ 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); - word_space(s, ~"<-"); + word_space(s, "<-"); print_expr(s, rhs); } ast::expr_assign(lhs, rhs) { print_expr(s, lhs); space(s.s); - word_space(s, ~"="); + word_space(s, "="); print_expr(s, rhs); } ast::expr_swap(lhs, rhs) { print_expr(s, lhs); space(s.s); - word_space(s, ~"<->"); + word_space(s, "<->"); print_expr(s, rhs); } ast::expr_assign_op(op, lhs, rhs) { print_expr(s, lhs); space(s.s); word(s.s, ast_util::binop_to_str(op)); - word_space(s, ~"="); + word_space(s, "="); print_expr(s, rhs); } ast::expr_field(expr, id) { print_expr_parens_if_unary(s, expr); - word(s.s, ~"."); + word(s.s, "."); word(s.s, id); } ast::expr_index(expr, index) { print_expr_parens_if_unary(s, expr); - word(s.s, ~"["); + word(s.s, "["); print_expr(s, index); - word(s.s, ~"]"); + word(s.s, "]"); } ast::expr_path(path) { print_path(s, path, true); } ast::expr_fail(maybe_fail_val) { - word(s.s, ~"fail"); + word(s.s, "fail"); alt maybe_fail_val { - some(expr) { word(s.s, ~" "); print_expr(s, expr); } + some(expr) { word(s.s, " "); print_expr(s, expr); } _ { } } } - ast::expr_break. { word(s.s, ~"break"); } - ast::expr_cont. { word(s.s, ~"cont"); } + ast::expr_break. { word(s.s, "break"); } + ast::expr_cont. { word(s.s, "cont"); } ast::expr_ret(result) { - word(s.s, ~"ret"); + word(s.s, "ret"); alt result { - some(expr) { word(s.s, ~" "); print_expr(s, expr); } + some(expr) { word(s.s, " "); print_expr(s, expr); } _ { } } } ast::expr_put(result) { - word(s.s, ~"put"); + word(s.s, "put"); alt result { - some(expr) { word(s.s, ~" "); print_expr(s, expr); } + some(expr) { word(s.s, " "); print_expr(s, expr); } _ { } } } - ast::expr_be(result) { word_nbsp(s, ~"be"); print_expr(s, result); } + ast::expr_be(result) { word_nbsp(s, "be"); print_expr(s, result); } ast::expr_log(lvl, expr) { - alt lvl { - 1 { word_nbsp(s, ~"log"); } 0 { word_nbsp(s, ~"log_err"); } - } + alt lvl { 1 { word_nbsp(s, "log"); } 0 { word_nbsp(s, "log_err"); } } print_expr(s, expr); } ast::expr_check(m, expr) { alt m { - ast::unchecked. { word_nbsp(s, ~"claim"); } - ast::checked. { word_nbsp(s, ~"check"); } + ast::unchecked. { word_nbsp(s, "claim"); } + ast::checked. { word_nbsp(s, "check"); } } popen(s); print_expr(s, expr); pclose(s); } ast::expr_assert(expr) { - word_nbsp(s, ~"assert"); + word_nbsp(s, "assert"); popen(s); print_expr(s, expr); pclose(s); } ast::expr_mac(m) { print_mac(s, m); } ast::expr_anon_obj(anon_obj) { - head(s, ~"obj"); + head(s, "obj"); // Fields popen(s); fn print_field(s: &ps, field: &ast::anon_obj_field) { ibox(s, indent_unit); print_mutability(s, field.mut); - word_space(s, field.ident + ~":"); + word_space(s, field.ident + ":"); print_type(s, field.ty); space(s.s); - word_space(s, ~"="); + word_space(s, "="); print_expr(s, field.expr); end(s); } @@ -1077,18 +1064,18 @@ fn print_expr(s: &ps, expr: &@ast::expr) { maybe_print_comment(s, meth.span.lo); print_fn(s, meth.node.meth.decl, meth.node.meth.proto, meth.node.ident, typarams, []); - word(s.s, ~" "); + word(s.s, " "); print_block(s, meth.node.meth.body); } // 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); @@ -1105,7 +1092,7 @@ fn print_local_decl(s: &ps, loc: &@ast::local) { print_pat(s, loc.node.pat); alt loc.node.ty.node { ast::ty_infer. { } - _ { word_space(s, ~":"); print_type(s, loc.node.ty); } + _ { word_space(s, ":"); print_type(s, loc.node.ty); } } } @@ -1115,7 +1102,7 @@ fn print_decl(s: &ps, decl: &@ast::decl) { ast::decl_local(locs) { space_if_not_bol(s); ibox(s, indent_unit); - word_nbsp(s, ~"let"); + word_nbsp(s, "let"); fn print_local(s: &ps, loc: &@ast::local) { ibox(s, indent_unit); print_local_decl(s, loc); @@ -1124,8 +1111,8 @@ fn print_decl(s: &ps, decl: &@ast::decl) { some(init) { nbsp(s); alt init.op { - ast::init_assign. { word_space(s, ~"="); } - ast::init_move. { word_space(s, ~"<-"); } + ast::init_assign. { word_space(s, "="); } + ast::init_move. { word_space(s, "<-"); } } print_expr(s, init.expr); } @@ -1139,30 +1126,28 @@ fn print_decl(s: &ps, decl: &@ast::decl) { } } -fn print_ident(s: &ps, ident: &ast::ident) { - word(s.s, ident); -} +fn print_ident(s: &ps, ident: &ast::ident) { word(s.s, ident); } fn print_for_decl(s: &ps, loc: &@ast::local, coll: &@ast::expr) { print_local_decl(s, loc); space(s.s); - word_space(s, ~"in"); + word_space(s, "in"); print_expr(s, coll); } fn print_path(s: &ps, path: &ast::path, colons_before_params: bool) { maybe_print_comment(s, path.span.lo); - if path.node.global { word(s.s, ~"::"); } + if path.node.global { word(s.s, "::"); } let first = true; for id: ast::ident in path.node.idents { - if first { first = false; } else { word(s.s, ~"::"); } + if first { first = false; } else { word(s.s, "::"); } word(s.s, id); } if vec::len(path.node.types) > 0u { - if colons_before_params { word(s.s, ~"::"); } - word(s.s, ~"<"); + if colons_before_params { word(s.s, "::"); } + word(s.s, "<"); commasep(s, inconsistent, path.node.types, print_type); - word(s.s, ~">"); + word(s.s, ">"); } } @@ -1171,7 +1156,7 @@ fn print_pat(s: &ps, pat: &@ast::pat) { let ann_node = node_pat(s, pat); s.ann.pre(ann_node); alt pat.node { - ast::pat_wild. { word(s.s, ~"_"); } + ast::pat_wild. { word(s.s, "_"); } ast::pat_bind(id) { word(s.s, id); } ast::pat_lit(lit) { print_literal(s, lit); } ast::pat_tag(path, args) { @@ -1180,31 +1165,31 @@ fn print_pat(s: &ps, pat: &@ast::pat) { popen(s); commasep(s, inconsistent, args, print_pat); pclose(s); - } else { word(s.s, ~"."); } + } else { word(s.s, "."); } } ast::pat_rec(fields, etc) { - word(s.s, ~"{"); + word(s.s, "{"); fn print_field(s: &ps, f: &ast::field_pat) { cbox(s, indent_unit); word(s.s, f.ident); - word_space(s, ~":"); + word_space(s, ":"); print_pat(s, f.pat); end(s); } fn get_span(f: &ast::field_pat) -> codemap::span { ret f.pat.span; } commasep_cmnt(s, consistent, fields, print_field, get_span); if etc { - if vec::len(fields) != 0u { word_space(s, ~","); } - word(s.s, ~"_"); + if vec::len(fields) != 0u { word_space(s, ","); } + word(s.s, "_"); } - word(s.s, ~"}"); + word(s.s, "}"); } ast::pat_tup(elts) { popen(s); commasep(s, inconsistent, elts, print_pat); pclose(s); } - ast::pat_box(inner) { word(s.s, ~"@"); print_pat(s, inner); } + ast::pat_box(inner) { word(s.s, "@"); print_pat(s, inner); } } s.ann.post(ann_node); } @@ -1213,7 +1198,7 @@ fn print_fn(s: &ps, decl: ast::fn_decl, proto: ast::proto, name: &ast::ident, typarams: &[ast::ty_param], constrs: [@ast::constr]) { alt decl.purity { ast::impure_fn. { head(s, proto_to_str(proto)); } - _ { head(s, ~"pure fn"); } + _ { head(s, "pure fn"); } } word(s.s, name); print_type_params(s, typarams); @@ -1225,7 +1210,7 @@ fn print_fn_args_and_ret(s: &ps, decl: &ast::fn_decl, popen(s); fn print_arg(s: &ps, x: &ast::arg) { ibox(s, indent_unit); - word_space(s, x.ident + ~":"); + word_space(s, x.ident + ":"); print_alias(s, x.mode); print_type(s, x.ty); end(s); @@ -1236,13 +1221,13 @@ fn print_fn_args_and_ret(s: &ps, decl: &ast::fn_decl, maybe_print_comment(s, decl.output.span.lo); if decl.output.node != ast::ty_nil { space_if_not_bol(s); - word_space(s, ~"->"); + word_space(s, "->"); print_type(s, decl.output); } } fn print_fn_block_args(s: &ps, decl: &ast::fn_decl) { - word(s.s, ~"|"); + word(s.s, "|"); fn print_arg(s: &ps, x: &ast::arg) { ibox(s, indent_unit); print_alias(s, x.mode); @@ -1250,36 +1235,36 @@ fn print_fn_block_args(s: &ps, decl: &ast::fn_decl) { end(s); } commasep(s, inconsistent, decl.inputs, print_arg); - word(s.s, ~"|"); + word(s.s, "|"); maybe_print_comment(s, decl.output.span.lo); } fn print_alias(s: &ps, m: ast::mode) { alt m { - ast::alias(true) { word_space(s, ~"&mutable"); } - ast::alias(false) { word(s.s, ~"&"); } - ast::move. { word(s.s, ~"-"); } + ast::alias(true) { word_space(s, "&mutable"); } + ast::alias(false) { word(s.s, "&"); } + ast::move. { word(s.s, "-"); } ast::val. { } } } fn print_kind(s: &ps, kind: ast::kind) { alt kind { - ast::kind_unique. { word(s.s, ~"~"); } - ast::kind_shared. { word(s.s, ~"@"); } + ast::kind_unique. { word(s.s, "~"); } + ast::kind_shared. { word(s.s, "@"); } _ {/* fallthrough */ } } } fn print_type_params(s: &ps, params: &[ast::ty_param]) { if vec::len(params) > 0u { - word(s.s, ~"<"); + word(s.s, "<"); fn printParam(s: &ps, param: &ast::ty_param) { print_kind(s, param.kind); word(s.s, param.ident); } commasep(s, inconsistent, params, printParam); - word(s.s, ~">"); + word(s.s, ">"); } } @@ -1289,7 +1274,7 @@ fn print_meta_item(s: &ps, item: &@ast::meta_item) { ast::meta_word(name) { word(s.s, name); } ast::meta_name_value(name, value) { word_space(s, name); - word_space(s, ~"="); + word_space(s, "="); print_literal(s, @value); } ast::meta_list(name, items) { @@ -1307,7 +1292,7 @@ fn print_view_item(s: &ps, item: &@ast::view_item) { maybe_print_comment(s, item.span.lo); alt item.node { ast::view_item_use(id, mta, _) { - head(s, ~"use"); + head(s, "use"); word(s.s, id); if vec::len(mta) > 0u { popen(s); @@ -1316,47 +1301,43 @@ fn print_view_item(s: &ps, item: &@ast::view_item) { } } ast::view_item_import(id, ids, _) { - head(s, ~"import"); + head(s, "import"); if !str::eq(id, ids[vec::len(ids) - 1u]) { word_space(s, id); - word_space(s, ~"="); + word_space(s, "="); } let first = true; for elt: ast::ident in ids { - if first { first = false; } else { word(s.s, ~"::"); } + if first { first = false; } else { word(s.s, "::"); } word(s.s, elt); } } ast::view_item_import_from(mod_path, idents, _) { - head(s, ~"import"); - for elt: ast::ident in mod_path { - word(s.s, elt); word(s.s, ~"::"); - } - word(s.s, ~"{"); + head(s, "import"); + for elt: ast::ident in mod_path { word(s.s, elt); word(s.s, "::"); } + word(s.s, "{"); commasep(s, inconsistent, idents, fn (s: &ps, w: &ast::import_ident) { word(s.s, w.node.name) }); - word(s.s, ~"}"); + word(s.s, "}"); } ast::view_item_import_glob(ids, _) { - head(s, ~"import"); + head(s, "import"); let first = true; for elt: ast::ident in ids { - if first { first = false; } else { word(s.s, ~"::"); } + if first { first = false; } else { word(s.s, "::"); } word(s.s, elt); } - word(s.s, ~"::*"); + word(s.s, "::*"); } ast::view_item_export(ids, _) { - head(s, ~"export"); + head(s, "export"); commasep(s, inconsistent, ids, - fn (s: &ps, w: &ast::ident) { - word(s.s, w) - }); + fn (s: &ps, w: &ast::ident) { word(s.s, w) }); } } - word(s.s, ~";"); + word(s.s, ";"); end(s); // end inner head-block end(s); // end outer head-block @@ -1380,6 +1361,7 @@ fn need_parens(expr: &@ast::expr, outer_prec: int) -> bool { ast::expr_ternary(_, _, _) { parse::parser::ternary_prec < outer_prec } + // This may be too conservative in some cases ast::expr_assign(_, _) { true @@ -1406,8 +1388,8 @@ fn print_maybe_parens(s: &ps, expr: &@ast::expr, outer_prec: int) { fn print_mutability(s: &ps, mut: &ast::mutability) { alt mut { - ast::mut. { word_nbsp(s, ~"mutable"); } - ast::maybe_mut. { word_nbsp(s, ~"mutable?"); } + ast::mut. { word_nbsp(s, "mutable"); } + ast::maybe_mut. { word_nbsp(s, "mutable?"); } ast::imm. {/* nothing */ } } } @@ -1422,13 +1404,7 @@ fn print_ty_fn(s: &ps, proto: &ast::proto, id: &option::t<ast::ident>, cf: &ast::controlflow, constrs: &[@ast::constr]) { ibox(s, indent_unit); word(s.s, proto_to_str(proto)); - alt id { - some(id) { - word(s.s, ~" "); - word(s.s, id); - } - _ { } - } + alt id { some(id) { word(s.s, " "); word(s.s, id); } _ { } } zerobreak(s.s); popen(s); fn print_arg(s: &ps, input: &ast::ty_arg) { @@ -1441,10 +1417,10 @@ fn print_ty_fn(s: &ps, proto: &ast::proto, id: &option::t<ast::ident>, if output.node != ast::ty_nil { space_if_not_bol(s); ibox(s, indent_unit); - word_space(s, ~"->"); + word_space(s, "->"); alt cf { ast::return. { print_type(s, output); } - ast::noreturn. { word_nbsp(s, ~"!"); } + ast::noreturn. { word_nbsp(s, "!"); } } end(s); } @@ -1495,25 +1471,19 @@ fn print_literal(s: &ps, lit: &@ast::lit) { maybe_print_comment(s, lit.span.lo); alt next_lit(s) { some(lt) { - if lt.pos == lit.span.lo { - word(s.s, lt.lit); - s.cur_lit += 1u; - ret; - } + if lt.pos == lit.span.lo { word(s.s, lt.lit); s.cur_lit += 1u; ret; } } _ { } } alt lit.node { - ast::lit_str(st) { - print_string(s, st); - } + ast::lit_str(st) { print_string(s, st); } ast::lit_char(ch) { word(s.s, - ~"'" + escape_str(str::unsafe_from_bytes([ch as u8]), '\'') + - ~"'"); + "'" + 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"); } + ast::lit_uint(val) { word(s.s, uint::str(val) + "u"); } ast::lit_float(fstr) { word(s.s, fstr); } ast::lit_mach_int(mach, val) { word(s.s, int::str(val as int)); @@ -1524,14 +1494,14 @@ fn print_literal(s: &ps, lit: &@ast::lit) { word(s.s, val); word(s.s, ast_util::ty_mach_to_str(mach)); } - ast::lit_nil. { word(s.s, ~"()"); } + ast::lit_nil. { word(s.s, "()"); } ast::lit_bool(val) { - if val { word(s.s, ~"true"); } else { word(s.s, ~"false"); } + if val { word(s.s, "true"); } else { word(s.s, "false"); } } } } -fn lit_to_str(l: &@ast::lit) -> istr { be to_str(l, print_literal); } +fn lit_to_str(l: &@ast::lit) -> str { be to_str(l, print_literal); } fn next_lit(s: &ps) -> option::t<lexer::lit> { alt s.literals { @@ -1568,26 +1538,22 @@ fn print_comment(s: &ps, cmnt: lexer::cmnt) { } lexer::isolated. { pprust::hardbreak_if_not_bol(s); - for line: istr in cmnt.lines { + for line: str in cmnt.lines { // Don't print empty lines because they will end up as trailing // whitespace - if str::is_not_empty(line) { - word(s.s, line); - } + if str::is_not_empty(line) { word(s.s, line); } hardbreak(s.s); } } lexer::trailing. { - word(s.s, ~" "); + word(s.s, " "); if vec::len(cmnt.lines) == 1u { word(s.s, cmnt.lines[0]); hardbreak(s.s); } else { ibox(s, 0u); - for line: istr in cmnt.lines { - if str::is_not_empty(line) { - word(s.s, line); - } + for line: str in cmnt.lines { + if str::is_not_empty(line) { word(s.s, line); } hardbreak(s.s); } end(s); @@ -1597,7 +1563,7 @@ fn print_comment(s: &ps, cmnt: lexer::cmnt) { // We need to do at least one, possibly two hardbreaks. let is_semi = alt s.s.last_token() { - pp::STRING(s, _) { s == ~";" } + pp::STRING(s, _) { s == ";" } _ { false } }; if is_semi || is_begin(s) || is_end(s) { hardbreak(s.s) } @@ -1606,24 +1572,24 @@ fn print_comment(s: &ps, cmnt: lexer::cmnt) { } } -fn print_string(s: &ps, st: &istr) { - word(s.s, ~"\""); +fn print_string(s: &ps, st: &str) { + word(s.s, "\""); word(s.s, escape_str(st, '"')); - word(s.s, ~"\""); + word(s.s, "\""); } -fn escape_str(st: &istr, to_escape: char) -> istr { - let out: istr = ~""; +fn escape_str(st: &str, to_escape: char) -> str { + let out: str = ""; let len = str::byte_len(st); let i = 0u; while i < len { alt st[i] as char { - '\n' { out += ~"\\n"; } - '\t' { out += ~"\\t"; } - '\r' { out += ~"\\r"; } - '\\' { out += ~"\\\\"; } + '\n' { out += "\\n"; } + '\t' { out += "\\t"; } + '\r' { out += "\\r"; } + '\\' { out += "\\\\"; } cur { - if cur == to_escape { out += ~"\\"; } + if cur == to_escape { out += "\\"; } // FIXME some (or all?) non-ascii things should be escaped str::push_char(out, cur); @@ -1634,7 +1600,7 @@ fn escape_str(st: &istr, to_escape: char) -> istr { ret out; } -fn to_str<T>(t: &T, f: fn(&ps, &T)) -> istr { +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); @@ -1655,23 +1621,22 @@ 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) -> istr, args: &[@ast::sp_constr_arg<T>]) - -> istr { +fn constr_args_to_str<T>(f: &fn(&T) -> str, args: &[@ast::sp_constr_arg<T>]) + -> str { let comma = false; - let s = ~"("; + let s = "("; for a: @ast::sp_constr_arg<T> in args { - if comma { s += ~", "; } else { comma = true; } + if comma { s += ", "; } else { comma = true; } s += constr_arg_to_str::<T>(f, a.node); } - s += ~")"; + s += ")"; ret s; } -fn constr_arg_to_str<T>(f: &fn(&T) -> istr, - c: &ast::constr_arg_general_<T>) -> - istr { +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_base. { ret "*"; } ast::carg_ident(i) { ret f(i); } ast::carg_lit(l) { ret lit_to_str(l); } } @@ -1680,56 +1645,56 @@ fn constr_arg_to_str<T>(f: &fn(&T) -> istr, // needed b/c constr_args_to_str needs // something that takes an alias // (argh) -fn uint_to_str(i: &uint) -> istr { ret uint::str(i); } +fn uint_to_str(i: &uint) -> str { ret uint::str(i); } -fn ast_ty_fn_constr_to_str(c: &@ast::constr) -> istr { +fn ast_ty_fn_constr_to_str(c: &@ast::constr) -> str { ret path_to_str(c.node.path) + constr_args_to_str(uint_to_str, c.node.args); } // FIXME: fix repeated code -fn ast_ty_fn_constrs_str(constrs: &[@ast::constr]) -> istr { - let s = ~""; +fn ast_ty_fn_constrs_str(constrs: &[@ast::constr]) -> str { + let s = ""; let colon = true; for c: @ast::constr in constrs { - if colon { s += ~" : "; colon = false; } else { s += ~", "; } + if colon { s += " : "; colon = false; } else { s += ", "; } s += ast_ty_fn_constr_to_str(c); } ret s; } -fn fn_arg_idx_to_str(decl: &ast::fn_decl, idx: &uint) -> istr { +fn fn_arg_idx_to_str(decl: &ast::fn_decl, idx: &uint) -> str { decl.inputs[idx].ident } -fn ast_fn_constr_to_str(decl: &ast::fn_decl, c: &@ast::constr) -> istr { +fn ast_fn_constr_to_str(decl: &ast::fn_decl, c: &@ast::constr) -> str { let arg_to_str = bind fn_arg_idx_to_str(decl, _); ret path_to_str(c.node.path) + constr_args_to_str(arg_to_str, c.node.args); } // FIXME: fix repeated code -fn ast_fn_constrs_str(decl: &ast::fn_decl, constrs: &[@ast::constr]) -> istr { - let s = ~""; +fn ast_fn_constrs_str(decl: &ast::fn_decl, constrs: &[@ast::constr]) -> str { + let s = ""; let colon = true; for c: @ast::constr in constrs { - if colon { s += ~" : "; colon = false; } else { s += ~", "; } + if colon { s += " : "; colon = false; } else { s += ", "; } s += ast_fn_constr_to_str(decl, c); } ret s; } -fn proto_to_str(p: &ast::proto) -> istr { +fn proto_to_str(p: &ast::proto) -> str { ret alt p { - ast::proto_fn. { ~"fn" } - ast::proto_iter. { ~"iter" } - ast::proto_block. { ~"block" } - ast::proto_closure. { ~"lambda" } + ast::proto_fn. { "fn" } + ast::proto_iter. { "iter" } + ast::proto_block. { "block" } + ast::proto_closure. { "lambda" } }; } -fn ty_constr_to_str(c: &@ast::ty_constr) -> istr { - fn ty_constr_path_to_str(p: &ast::path) -> istr { ~"*." + path_to_str(p) } +fn ty_constr_to_str(c: &@ast::ty_constr) -> str { + 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, @@ -1737,11 +1702,11 @@ fn ty_constr_to_str(c: &@ast::ty_constr) -> istr { } -fn ast_ty_constrs_str(constrs: &[@ast::ty_constr]) -> istr { - let s = ~""; +fn ast_ty_constrs_str(constrs: &[@ast::ty_constr]) -> str { + let s = ""; let colon = true; for c: @ast::ty_constr in constrs { - if colon { s += ~" : "; colon = false; } else { s += ~", "; } + if colon { s += " : "; colon = false; } else { s += ", "; } s += ty_constr_to_str(c); } ret s; |
