Fix FileMap::line_begin_pos().

The method relied on the FileMap still being under construction in
order for it to do what the name promises. It's now independent of
the current state.
This commit is contained in:
Michael Woerister 2018-06-28 10:45:57 +02:00
parent ba30c1dac9
commit a1f8a6ce80
2 changed files with 7 additions and 7 deletions

View File

@ -240,9 +240,11 @@ fn read_block_comment(rdr: &mut StringReader,
let mut lines: Vec<String> = Vec::new(); let mut lines: Vec<String> = Vec::new();
// Count the number of chars since the start of the line by rescanning. // Count the number of chars since the start of the line by rescanning.
let mut src_index = rdr.src_index(rdr.filemap.line_begin_pos()); let mut src_index = rdr.src_index(rdr.filemap.line_begin_pos(rdr.pos));
let end_src_index = rdr.src_index(rdr.pos); let end_src_index = rdr.src_index(rdr.pos);
assert!(src_index <= end_src_index); assert!(src_index <= end_src_index,
"src_index={}, end_src_index={}, line_begin_pos={}",
src_index, end_src_index, rdr.filemap.line_begin_pos(rdr.pos).to_u32());
let mut n = 0; let mut n = 0;
while src_index < end_src_index { while src_index < end_src_index {
let c = char_at(&rdr.src, src_index); let c = char_at(&rdr.src, src_index);

View File

@ -976,11 +976,9 @@ impl FileMap {
} }
/// Return the BytePos of the beginning of the current line. /// Return the BytePos of the beginning of the current line.
pub fn line_begin_pos(&self) -> BytePos { pub fn line_begin_pos(&self, pos: BytePos) -> BytePos {
match self.lines.last() { let line_index = self.lookup_line(pos).unwrap();
Some(&line_pos) => line_pos, self.lines[line_index]
None => self.start_pos,
}
} }
/// Add externally loaded source. /// Add externally loaded source.