Skip to content

Commit 4a0b1a6

Browse files
jdmbrson
authored andcommitted
---
yaml --- r: 3960 b: refs/heads/master c: 3ce43f3 h: refs/heads/master v: v3
1 parent 681efcd commit 4a0b1a6

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: a5ac8f16db58f586b868d8612e38f01bdf2dd97e
2+
refs/heads/master: 3ce43f37d2ba033ff7f4bfddff6edc59ff8aabc6

trunk/src/comp/syntax/codemap.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn new_codemap() -> codemap {
2626
}
2727

2828
fn new_filemap(filename filename, uint start_pos) -> filemap {
29-
ret @rec(name=filename, start_pos=start_pos, mutable lines=~[0u]);
29+
ret @rec(name=filename, start_pos=start_pos, mutable lines=[start_pos]);
3030
}
3131

3232
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 {
170170
fn get_line(filemap fm, int line, &str file) -> str {
171171
let uint begin = fm.lines.(line) - fm.start_pos;
172172
let uint end;
173-
if ((line as uint) + 1u >= ivec::len(fm.lines)) {
174-
end = str::byte_len(file);
175-
} else {
173+
if (line as uint < ivec::len(fm.lines) - 1u) {
176174
end = fm.lines.(line + 1) - fm.start_pos;
175+
} else {
176+
// If we're not done parsing the file, we're at the limit of what's
177+
// parsed. If we just slice the rest of the string, we'll print out
178+
// the remainder of the file, which is undesirable.
179+
end = str::byte_len(file);
180+
auto rest = str::slice(file, begin, end);
181+
auto newline = str::index(rest, '\n' as u8);
182+
if (newline != -1) {
183+
end = begin + (newline as uint);
184+
}
177185
}
178186
ret str::slice(file, begin, end);
179187
}

0 commit comments

Comments
 (0)