Skip to content

Commit

Permalink
Hopefully the final off-by-one bug with source positions
Browse files Browse the repository at this point in the history
  • Loading branch information
Pat-Lafon committed May 19, 2022
1 parent 6947e02 commit 83ef192
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions bril-rs/bril2json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,28 @@ impl Lines {

fn get_position(&self, index: usize) -> Option<Position> {
if self.use_pos {
Some(self.new_lines.iter().enumerate().fold(
Position { col: 1, row: 1 },
|current, (line_num, idx)| {
if *idx < index {
Some(
self.new_lines
.iter()
.enumerate()
.map(|(i, j)| (i + 1, j))
.fold(
Position {
row: (line_num + 1) as u64,
col: (index - idx) as u64,
}
} else {
current
}
},
))
col: 1,
row: index as u64,
},
|current, (line_num, idx)| {
if *idx < index {
Position {
row: (line_num + 1) as u64,
col: (index - idx) as u64,
}
} else {
current
}
},
),
)
} else {
None
}
Expand Down

0 comments on commit 83ef192

Please sign in to comment.