From 535780c4e42bdfe89be27cbabda9976971b96806 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Wed, 13 Jul 2011 10:18:40 -0400 Subject: [PATCH 1/3] Fix error line display slicing. --- src/comp/syntax/codemap.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/comp/syntax/codemap.rs b/src/comp/syntax/codemap.rs index 6df2f2422ad95..a50a5a0f71552 100644 --- a/src/comp/syntax/codemap.rs +++ b/src/comp/syntax/codemap.rs @@ -85,7 +85,7 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color, // get access to the necessary lines. auto rdr = io::file_reader(lines.name); auto file = str::unsafe_from_bytes(rdr.read_whole_stream()); - auto fm = codemap::get_filemap(cm, lines.name); + auto fm = get_filemap(cm, lines.name); // arbitrarily only print up to six lines of the error auto max_lines = 6u; @@ -98,7 +98,7 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color, // Print the offending lines for (uint line in display_lines) { io::stdout().write_str(#fmt("%s:%u ", fm.name, line + 1u)); - auto s = codemap::get_line(fm, line as int, file); + auto s = get_line(fm, line as int, file); if (!str::ends_with(s, "\n")) { s += "\n"; } @@ -116,7 +116,7 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color, // If there's one line at fault we can easily point to the problem if (vec::len(lines.lines) == 1u) { - auto lo = codemap::lookup_pos(cm, option::get(sp).lo); + auto lo = lookup_pos(cm, option::get(sp).lo); auto digits = 0u; auto num = lines.lines.(0) / 10u; @@ -129,7 +129,7 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color, while (left > 0u) { str::push_char(s, ' '); left -= 1u; } s += "^"; - auto hi = codemap::lookup_pos(cm, option::get(sp).hi); + auto hi = lookup_pos(cm, option::get(sp).hi); if (hi.col != lo.col) { // the ^ already takes up one space auto width = hi.col - lo.col - 1u; @@ -168,13 +168,14 @@ fn span_to_lines(span sp, codemap::codemap cm) -> @file_lines { } fn get_line(filemap fm, int line, &str file) -> str { + let uint begin = fm.lines.(line) - fm.lines.(0); let uint end; if ((line as uint) + 1u >= vec::len(fm.lines)) { end = str::byte_len(file); } else { - end = fm.lines.(line + 1); + end = fm.lines.(line + 1) - fm.lines.(0); } - ret str::slice(file, fm.lines.(line), end); + ret str::slice(file, begin, end); } fn get_filemap(codemap cm, str filename) -> filemap { From faab6c2d59c305b85fa4e846ba99df84b9f8e5ab Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Wed, 13 Jul 2011 10:26:46 -0400 Subject: [PATCH 2/3] Reenable error line printing. --- src/comp/syntax/codemap.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/comp/syntax/codemap.rs b/src/comp/syntax/codemap.rs index a50a5a0f71552..b5012ef978221 100644 --- a/src/comp/syntax/codemap.rs +++ b/src/comp/syntax/codemap.rs @@ -64,8 +64,7 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color, case (some(?ssp)) { ss = span_to_str(ssp, cm); - // FIXME: we're not able to look up lines read from .rc files yet. - // maybe_lines = some(span_to_lines(ssp, cm)); + maybe_lines = some(span_to_lines(ssp, cm)); } case (none) { } From 0d366b5ff6d64a70d9780b132125ac691f201053 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Wed, 13 Jul 2011 14:00:11 -0400 Subject: [PATCH 3/3] Use the actual start position of the file in the codemap rather than the position of the first newline. --- src/comp/syntax/codemap.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/comp/syntax/codemap.rs b/src/comp/syntax/codemap.rs index b5012ef978221..2a2cdf09c1c64 100644 --- a/src/comp/syntax/codemap.rs +++ b/src/comp/syntax/codemap.rs @@ -63,9 +63,7 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color, alt (sp) { case (some(?ssp)) { ss = span_to_str(ssp, cm); - maybe_lines = some(span_to_lines(ssp, cm)); - } case (none) { } } @@ -167,12 +165,12 @@ fn span_to_lines(span sp, codemap::codemap cm) -> @file_lines { } fn get_line(filemap fm, int line, &str file) -> str { - let uint begin = fm.lines.(line) - fm.lines.(0); + let uint begin = fm.lines.(line) - fm.start_pos; let uint end; if ((line as uint) + 1u >= vec::len(fm.lines)) { end = str::byte_len(file); } else { - end = fm.lines.(line + 1) - fm.lines.(0); + end = fm.lines.(line + 1) - fm.start_pos; } ret str::slice(file, begin, end); }