1use std::path::PathBuf;
2
3#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
4pub struct Position {
5 pub index: usize,
6 pub line: usize,
7 pub column: usize,
8}
9
10impl std::fmt::Display for Position {
11 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12 write!(f, "{}:{}", self.line, self.column)
13 }
14}
15
16#[derive(Debug, Clone, PartialEq, Eq, Hash)]
17pub struct Span {
18 pub start: Position,
19 pub end: Position,
20 pub filename: PathBuf,
21}
22
23impl std::fmt::Display for Span {
24 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25 match self.filename.to_str() {
26 Some(filename) => write!(f, "{filename}")?,
27 None => write!(f, "<non-utf8 filename>")?,
28 }
29 write!(f, ":{}", self.start)?;
30 if self.start != self.end {
31 write!(f, "~{}", self.end)?;
32 }
33 Ok(())
34 }
35}
36
37pub struct SourceFile {
38 pub contents: String,
39 pub filename: PathBuf,
40}