Fix bad line printing for parse errors
The code that extracted lines from partially-parsed files was broken. Closes #1848
This commit is contained in:
parent
6627890f6b
commit
9ff5ba085d
3 changed files with 20 additions and 12 deletions
|
@ -204,8 +204,7 @@ fn highlight_lines(cm: codemap::codemap, sp: span,
|
||||||
// Print the offending lines
|
// Print the offending lines
|
||||||
for line: uint in display_lines {
|
for line: uint in display_lines {
|
||||||
io::stderr().write_str(#fmt["%s:%u ", fm.name, line + 1u]);
|
io::stderr().write_str(#fmt["%s:%u ", fm.name, line + 1u]);
|
||||||
let s = codemap::get_line(fm, line as int);
|
let s = codemap::get_line(fm, line as int) + "\n";
|
||||||
if !str::ends_with(s, "\n") { s += "\n"; }
|
|
||||||
io::stderr().write_str(s);
|
io::stderr().write_str(s);
|
||||||
}
|
}
|
||||||
if elided {
|
if elided {
|
||||||
|
|
|
@ -157,16 +157,11 @@ fn span_to_lines(sp: span, cm: codemap::codemap) -> @file_lines {
|
||||||
|
|
||||||
fn get_line(fm: filemap, line: int) -> str unsafe {
|
fn get_line(fm: filemap, line: int) -> str unsafe {
|
||||||
let begin: uint = fm.lines[line].byte - fm.start_pos.byte;
|
let begin: uint = fm.lines[line].byte - fm.start_pos.byte;
|
||||||
let end: uint;
|
let end = alt str::byte_index(*fm.src, '\n' as u8, begin) {
|
||||||
if line as uint < vec::len(fm.lines) - 1u {
|
some(e) { e }
|
||||||
end = fm.lines[line + 1].byte - fm.start_pos.byte;
|
none { str::len(*fm.src) }
|
||||||
ret str::unsafe::slice_bytes(*fm.src, begin, end);
|
};
|
||||||
} else {
|
str::unsafe::slice_bytes(*fm.src, begin, end)
|
||||||
// If we're not done parsing the file, we're at the limit of what's
|
|
||||||
// parsed. If we just slice the rest of the string, we'll print out
|
|
||||||
// the remainder of the file, which is undesirable.
|
|
||||||
ret str::splitn_char(*fm.src, '\n', 1u)[0];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lookup_byte_offset(cm: codemap::codemap, chpos: uint)
|
fn lookup_byte_offset(cm: codemap::codemap, chpos: uint)
|
||||||
|
|
|
@ -68,6 +68,7 @@ export
|
||||||
|
|
||||||
// Searching
|
// Searching
|
||||||
index,
|
index,
|
||||||
|
byte_index,
|
||||||
rindex,
|
rindex,
|
||||||
find,
|
find,
|
||||||
find_bytes,
|
find_bytes,
|
||||||
|
@ -852,6 +853,19 @@ fn index(ss: str, cc: char) -> option<uint> {
|
||||||
ret option::none;
|
ret option::none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function: byte_index
|
||||||
|
//
|
||||||
|
// Returns the index of the first matching byte
|
||||||
|
// (as option some/none)
|
||||||
|
fn byte_index(s: str, b: u8, start: uint) -> option<uint> {
|
||||||
|
let i = start, l = len_bytes(s);
|
||||||
|
while i < l {
|
||||||
|
if s[i] == b { ret some(i); }
|
||||||
|
i += 1u;
|
||||||
|
}
|
||||||
|
ret none;
|
||||||
|
}
|
||||||
|
|
||||||
// Function: rindex
|
// Function: rindex
|
||||||
//
|
//
|
||||||
// Returns the index of the first matching char
|
// Returns the index of the first matching char
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue