Convert std::io to istrs. Issue #855
This commit is contained in:
parent
20178b9312
commit
fcc031c5b4
23 changed files with 203 additions and 160 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import std::vec;
|
||||
import std::uint;
|
||||
import std::str;
|
||||
import std::istr;
|
||||
import std::term;
|
||||
import std::io;
|
||||
import std::option;
|
||||
|
|
@ -108,13 +109,13 @@ fn emit_diagnostic(sp: &option::t<span>, msg: &str, kind: &str, color: u8,
|
|||
}
|
||||
none. { }
|
||||
}
|
||||
io::stdout().write_str(ss);
|
||||
io::stdout().write_str(istr::from_estr(ss));
|
||||
if term::color_supported() {
|
||||
term::fg(io::stdout().get_buf_writer(), color);
|
||||
}
|
||||
io::stdout().write_str(#fmt["%s:", kind]);
|
||||
io::stdout().write_str(istr::from_estr(#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(istr::from_estr(#fmt[" %s\n", msg]));
|
||||
|
||||
maybe_highlight_lines(sp, cm, maybe_lines);
|
||||
}
|
||||
|
|
@ -130,7 +131,8 @@ fn maybe_highlight_lines(sp: &option::t<span>, cm: &codemap,
|
|||
|
||||
// FIXME: reading in the entire file is the worst possible way to
|
||||
// get access to the necessary lines.
|
||||
let file = io::read_whole_file_str(lines.name);
|
||||
let file = istr::to_estr(
|
||||
io::read_whole_file_str(istr::from_estr(lines.name)));
|
||||
let fm = get_filemap(cm, lines.name);
|
||||
|
||||
// arbitrarily only print up to six lines of the error
|
||||
|
|
@ -143,18 +145,19 @@ 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(
|
||||
istr::from_estr(#fmt["%s:%u ", fm.name, line + 1u]));
|
||||
let s = get_line(fm, line as int, file);
|
||||
if !str::ends_with(s, "\n") { s += "\n"; }
|
||||
io::stdout().write_str(s);
|
||||
io::stdout().write_str(istr::from_estr(s));
|
||||
}
|
||||
if elided {
|
||||
let last_line = display_lines[vec::len(display_lines) - 1u];
|
||||
let s = #fmt["%s:%u ", fm.name, last_line + 1u];
|
||||
let indent = str::char_len(s);
|
||||
let out = "";
|
||||
while indent > 0u { out += " "; indent -= 1u; }
|
||||
out += "...\n";
|
||||
let out = ~"";
|
||||
while indent > 0u { out += ~" "; indent -= 1u; }
|
||||
out += ~"...\n";
|
||||
io::stdout().write_str(out);
|
||||
}
|
||||
|
||||
|
|
@ -180,7 +183,7 @@ fn maybe_highlight_lines(sp: &option::t<span>, cm: &codemap,
|
|||
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(istr::from_estr(s + "\n"));
|
||||
}
|
||||
}
|
||||
_ { }
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
import std::option;
|
||||
import base::*;
|
||||
import syntax::ast;
|
||||
import std::istr;
|
||||
|
||||
fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @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(
|
||||
istr::from_estr(print::pprust::expr_to_str(arg)));
|
||||
|
||||
//trivial expression
|
||||
ret @{id: cx.next_id(), node: ast::expr_rec([], option::none), span: sp};
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ type parser =
|
|||
fn new_parser_from_file(sess: parse_sess, cfg: ast::crate_cfg, path: str,
|
||||
chpos: uint, byte_pos: uint, ftype: file_type) ->
|
||||
parser {
|
||||
let src = io::read_whole_file_str(path);
|
||||
let src = istr::to_estr(io::read_whole_file_str(istr::from_estr(path)));
|
||||
let filemap = codemap::new_filemap(path, chpos, byte_pos);
|
||||
sess.cm.files += [filemap];
|
||||
let itr = @interner::mk(str::hash, str::eq);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
import std::io;
|
||||
import std::vec;
|
||||
import std::str;
|
||||
|
||||
import std::istr;
|
||||
|
||||
/*
|
||||
* This pretty-printer is a direct reimplementation of Philip Karlton's
|
||||
|
|
@ -391,7 +391,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);
|
||||
}
|
||||
|
|
@ -407,10 +407,10 @@ obj printer(out: io::writer,
|
|||
}
|
||||
fn write_str(s: str) {
|
||||
while pending_indentation > 0 {
|
||||
out.write_str(" ");
|
||||
out.write_str(~" ");
|
||||
pending_indentation -= 1;
|
||||
}
|
||||
out.write_str(s);
|
||||
out.write_str(istr::from_estr(s));
|
||||
}
|
||||
fn print(x: token, L: int) {
|
||||
log #fmt["print %s %d (remaining line space=%d)", tok_str(x), L,
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ fn fun_to_str(f: &ast::_fn, name: str, params: &[ast::ty_param]) -> str {
|
|||
let s = rust_printer(writer.get_writer());
|
||||
print_fn(s, f.decl, f.proto, name, params, f.decl.constraints);
|
||||
eof(s.s);
|
||||
ret writer.get_str();
|
||||
ret istr::to_estr(writer.get_str());
|
||||
}
|
||||
|
||||
fn block_to_str(blk: &ast::blk) -> str {
|
||||
|
|
@ -126,7 +126,7 @@ fn block_to_str(blk: &ast::blk) -> str {
|
|||
ibox(s, 0u);
|
||||
print_block(s, blk);
|
||||
eof(s.s);
|
||||
ret writer.get_str();
|
||||
ret istr::to_estr(writer.get_str());
|
||||
}
|
||||
|
||||
fn meta_item_to_str(mi: &ast::meta_item) -> str {
|
||||
|
|
@ -1621,7 +1621,7 @@ fn to_str<T>(t: &T, f: fn(&ps, &T)) -> str {
|
|||
let s = rust_printer(writer.get_writer());
|
||||
f(s, t);
|
||||
eof(s.s);
|
||||
ret writer.get_str();
|
||||
ret istr::to_estr(writer.get_str());
|
||||
}
|
||||
|
||||
fn next_comment(s: &ps) -> option::t<lexer::cmnt> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue