diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-08-09 11:06:37 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-08-09 11:26:41 +0200 |
| commit | 3932bb2cb93be95d67fc56998423eb9ce047fdfa (patch) | |
| tree | c36bd4df1d2c74f8ae100d2f3bd3a0b232b797f5 /src/diag.rs | |
| parent | 3c92bad9a7cd6b880de197806443ffcce2cac9d8 (diff) | |
New source loading architecture
Diffstat (limited to 'src/diag.rs')
| -rw-r--r-- | src/diag.rs | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/src/diag.rs b/src/diag.rs index 397a833f..0fcdef17 100644 --- a/src/diag.rs +++ b/src/diag.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; -use crate::loading::FileId; +use crate::source::SourceId; use crate::syntax::Span; /// The result type for typesetting and all its subpasses. @@ -14,14 +14,14 @@ pub type StrResult<T> = Result<T, String>; /// An error in a source file. #[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)] pub struct Error { - /// The file that contains the error. - pub file: FileId, + /// The id of the source file that contains the error. + pub source: SourceId, /// The erroneous location in the source code. pub span: Span, /// A diagnostic message describing the problem. pub message: String, /// The trace of function calls leading to the error. - pub trace: Vec<(FileId, Span, Tracepoint)>, + pub trace: Vec<(SourceId, Span, Tracepoint)>, } /// A part of an error's [trace](Error::trace). @@ -35,9 +35,13 @@ pub enum Tracepoint { impl Error { /// Create a new, bare error. - pub fn new(file: FileId, span: impl Into<Span>, message: impl Into<String>) -> Self { + pub fn new( + source: SourceId, + span: impl Into<Span>, + message: impl Into<String>, + ) -> Self { Self { - file, + source, span: span.into(), trace: vec![], message: message.into(), @@ -47,11 +51,11 @@ impl Error { /// Create a boxed vector containing one error. The return value is suitable /// as the `Err` variant of a [`TypResult`]. pub fn boxed( - file: FileId, + source: SourceId, span: impl Into<Span>, message: impl Into<String>, ) -> Box<Vec<Self>> { - Box::new(vec![Self::new(file, span, message)]) + Box::new(vec![Self::new(source, span, message)]) } /// Partially build a vec-boxed error, returning a function that just needs @@ -60,23 +64,23 @@ impl Error { /// This is useful in to convert from [`StrResult`] to a [`TypResult`] using /// [`map_err`](Result::map_err). pub fn partial( - file: FileId, + source: SourceId, span: impl Into<Span>, ) -> impl FnOnce(String) -> Box<Vec<Self>> { - move |message| Self::boxed(file, span, message) + move |message| Self::boxed(source, span, message) } } /// Early-return with a vec-boxed [`Error`]. #[macro_export] macro_rules! bail { - ($file:expr, $span:expr, $message:expr $(,)?) => { + ($source:expr, $span:expr, $message:expr $(,)?) => { return Err(Box::new(vec![$crate::diag::Error::new( - $file, $span, $message, + $source, $span, $message, )])); }; - ($file:expr, $span:expr, $fmt:expr, $($arg:expr),+ $(,)?) => { - $crate::bail!($file, $span, format!($fmt, $($arg),+)); + ($source:expr, $span:expr, $fmt:expr, $($arg:expr),+ $(,)?) => { + $crate::bail!($source, $span, format!($fmt, $($arg),+)); }; } |
