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:
parent
ba30c1dac9
commit
a1f8a6ce80
@ -240,9 +240,11 @@ fn read_block_comment(rdr: &mut StringReader,
|
||||
let mut lines: Vec<String> = Vec::new();
|
||||
|
||||
// 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);
|
||||
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;
|
||||
while src_index < end_src_index {
|
||||
let c = char_at(&rdr.src, src_index);
|
||||
|
@ -976,11 +976,9 @@ impl FileMap {
|
||||
}
|
||||
|
||||
/// Return the BytePos of the beginning of the current line.
|
||||
pub fn line_begin_pos(&self) -> BytePos {
|
||||
match self.lines.last() {
|
||||
Some(&line_pos) => line_pos,
|
||||
None => self.start_pos,
|
||||
}
|
||||
pub fn line_begin_pos(&self, pos: BytePos) -> BytePos {
|
||||
let line_index = self.lookup_line(pos).unwrap();
|
||||
self.lines[line_index]
|
||||
}
|
||||
|
||||
/// Add externally loaded source.
|
||||
|
Loading…
Reference in New Issue
Block a user