morgana_core/syntax/source/
range.rs

1#[derive(Debug, Clone, derive_more::Display)]
2#[display(fmt = "{}:{}", "line", "col")]
3pub struct Pos {
4    pub filename: Option<String>,
5    pub line: u32,
6    pub col: u32,
7}
8
9#[derive(Debug, Clone)]
10pub struct Range {
11    pub from: Pos,
12    pub to: Pos,
13}
14
15impl Range {
16    pub fn new(from: Pos, to: Pos) -> Self {
17        Self { from, to }
18    }
19}
20
21impl std::fmt::Display for Range {
22    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23        if let Some(fname) = &self.from.filename {
24            write!(f, "{}-{} @ {}", self.from, self.to, fname.clone())
25        } else {
26            write!(f, "{}-{} @ unknown", self.from, self.to)
27        }
28    }
29}