1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use line_col::LineColLookup;

#[derive(Clone, PartialEq, Eq, Hash, Debug)]
pub struct Position {
    pub file: String,
    pub line: usize,
    pub column: usize,
}

impl Position {
    pub fn new<S: Into<String>>(file: S, lookup: &LineColLookup, offset: usize) -> Self {
        let file = file.into();
        let (line, column) = lookup.get(offset);
        Self { file, line, column }
    }
}

impl std::fmt::Display for Position {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}:{}:{}", self.file, self.line, self.column)
    }
}