language_reporting/
span.rs1use derive_new::new;
2use std::fmt::Debug;
3use std::path::PathBuf;
4
5#[derive(Debug)]
6pub enum FileName {
7 Virtual(PathBuf),
8 Real(PathBuf),
9 Verbatim(String),
10}
11
12#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd, new)]
13pub struct Location {
14 pub line: usize,
15 pub column: usize,
16}
17
18pub trait ReportingSpan: Debug + Copy {
19 fn with_start(&self, start: usize) -> Self;
20 fn with_end(&self, end: usize) -> Self;
21 fn start(&self) -> usize;
22 fn end(&self) -> usize;
23}
24
25pub trait ReportingFiles: Debug + Clone {
26 type Span: ReportingSpan;
27 type FileId: Copy;
28
29 fn byte_span(
30 &self,
31 file: Self::FileId,
32 from_index: usize,
33 to_index: usize,
34 ) -> Option<Self::Span>;
35
36 fn file_id(&self, span: Self::Span) -> Self::FileId;
37 fn file_name(&self, file: Self::FileId) -> FileName;
38 fn byte_index(&self, file: Self::FileId, line: usize, column: usize) -> Option<usize>;
39 fn location(&self, file: Self::FileId, byte_index: usize) -> Option<Location>;
40 fn line_span(&self, file: Self::FileId, lineno: usize) -> Option<Self::Span>;
41 fn source(&self, span: Self::Span) -> Option<String>;
42}