diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index fa01a15af5a..e8e39ff272a 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -189,7 +189,7 @@ pub impl FileMap { return FileMap { name: filename, substr: substr, src: src, start_pos: start_pos, - mut lines: ~[start_pos] + mut lines: ~[] }; } diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index dbeaff28625..178d772ecc6 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -45,18 +45,17 @@ fn new_low_level_string_reader(span_diagnostic: span_handler, filemap: @codemap::FileMap, itr: @token::ident_interner) -> string_reader { + // Force the initial reader bump to start on a fresh line + let initial_char = '\n'; let r = @{span_diagnostic: span_diagnostic, src: filemap.src, - mut col: CharPos(0), mut pos: BytePos(0), mut curr: -1 as char, + mut col: CharPos(0), mut pos: BytePos(0), + mut curr: initial_char, mut chpos: filemap.start_pos.ch, filemap: filemap, interner: itr, /* dummy values; not read */ mut peek_tok: token::EOF, mut peek_span: ast_util::dummy_sp()}; - if r.pos.to_uint() < (*filemap.src).len() { - let next = str::char_range_at(*r.src, r.pos.to_uint()); - r.pos = BytePos(next.next); - r.curr = next.ch; - } + bump(r); return r; } @@ -142,9 +141,10 @@ fn bump(rdr: string_reader) { rdr.pos = BytePos(next.next); rdr.curr = next.ch; } else { + // XXX: What does this accomplish? if (rdr.curr != -1 as char) { - rdr.col += CharPos(1u); rdr.chpos += CharPos(1u); + rdr.col += CharPos(1u); rdr.curr = -1 as char; } }