rl_model/parser/
position.rs

1use line_col::LineColLookup;
2
3#[derive(Clone, PartialEq, Eq, Hash, Debug)]
4pub struct Position {
5    pub file: String,
6    pub line: usize,
7    pub column: usize,
8}
9
10impl Position {
11    pub fn new<S: Into<String>>(file: S, lookup: &LineColLookup, offset: usize) -> Self {
12        let file = file.into();
13        let (line, column) = lookup.get(offset);
14        Self { file, line, column }
15    }
16}
17
18impl std::fmt::Display for Position {
19    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20        write!(f, "{}:{}:{}", self.file, self.line, self.column)
21    }
22}