about summary refs log tree commit diff
path: root/src/comp/syntax
diff options
context:
space:
mode:
authorMarijn Haverbeke <marijnh@gmail.com>2012-02-15 10:19:51 +0100
committerMarijn Haverbeke <marijnh@gmail.com>2012-02-15 11:53:32 +0100
commit9ff5ba085de572f8efaf501b88eb831d8ee40d47 (patch)
tree03f7e1cbb33736bd9be7e1d0b974cf7f5aaf8711 /src/comp/syntax
parent6627890f6bcbf2a2b71229572023cfaec91ab805 (diff)
Fix bad line printing for parse errors
The code that extracted lines from partially-parsed files
was broken.

Closes #1848
Diffstat (limited to 'src/comp/syntax')
-rw-r--r--src/comp/syntax/codemap.rs15
1 files changed, 5 insertions, 10 deletions
diff --git a/src/comp/syntax/codemap.rs b/src/comp/syntax/codemap.rs
index 03ade9a6931..7e153839448 100644
--- a/src/comp/syntax/codemap.rs
+++ b/src/comp/syntax/codemap.rs
@@ -157,16 +157,11 @@ fn span_to_lines(sp: span, cm: codemap::codemap) -> @file_lines {
 
 fn get_line(fm: filemap, line: int) -> str unsafe {
     let begin: uint = fm.lines[line].byte - fm.start_pos.byte;
-    let end: uint;
-    if line as uint < vec::len(fm.lines) - 1u {
-        end = fm.lines[line + 1].byte - fm.start_pos.byte;
-        ret str::unsafe::slice_bytes(*fm.src, begin, end);
-    } 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.
-        ret str::splitn_char(*fm.src, '\n', 1u)[0];
-    }
+    let end = alt str::byte_index(*fm.src, '\n' as u8, begin) {
+      some(e) { e }
+      none { str::len(*fm.src) }
+    };
+    str::unsafe::slice_bytes(*fm.src, begin, end)
 }
 
 fn lookup_byte_offset(cm: codemap::codemap, chpos: uint)