diff options
| author | Josh Matthews <josh@joshmatthews.net> | 2011-07-13 15:19:59 -0400 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2011-07-16 15:56:31 -0700 |
| commit | 3ce43f37d2ba033ff7f4bfddff6edc59ff8aabc6 (patch) | |
| tree | 513ea9f06ae36077cd597e223c9e26413ccb0434 /src/comp/syntax/codemap.rs | |
| parent | a5ac8f16db58f586b868d8612e38f01bdf2dd97e (diff) | |
| download | rust-3ce43f37d2ba033ff7f4bfddff6edc59ff8aabc6.tar.gz rust-3ce43f37d2ba033ff7f4bfddff6edc59ff8aabc6.zip | |
Fix pre-existing problem with filemap line positions always starting at 0. Fix error line output to only retrieve up to the nearest newline.
Diffstat (limited to 'src/comp/syntax/codemap.rs')
| -rw-r--r-- | src/comp/syntax/codemap.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/comp/syntax/codemap.rs b/src/comp/syntax/codemap.rs index 1a627619bd3..4b6aa40327a 100644 --- a/src/comp/syntax/codemap.rs +++ b/src/comp/syntax/codemap.rs @@ -26,7 +26,7 @@ fn new_codemap() -> codemap { } fn new_filemap(filename filename, uint start_pos) -> filemap { - ret @rec(name=filename, start_pos=start_pos, mutable lines=~[0u]); + ret @rec(name=filename, start_pos=start_pos, mutable lines=[start_pos]); } fn next_line(filemap file, uint pos) { file.lines += ~[pos]; } @@ -170,10 +170,18 @@ 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.start_pos; let uint end; - if ((line as uint) + 1u >= ivec::len(fm.lines)) { - end = str::byte_len(file); - } else { + if (line as uint < ivec::len(fm.lines) - 1u) { end = fm.lines.(line + 1) - fm.start_pos; + } else { + // If we're not done parsing the file, we're at the limit of what's + // parsed. If we just slice the rest of the string, we'll print out + // the remainder of the file, which is undesirable. + end = str::byte_len(file); + auto rest = str::slice(file, begin, end); + auto newline = str::index(rest, '\n' as u8); + if (newline != -1) { + end = begin + (newline as uint); + } } ret str::slice(file, begin, end); } |
