diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-05-31 12:37:05 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-05-31 12:37:05 +0200 |
| commit | 9bbebd69ddb4a7d7da98c3a79ff7d0cb187873fd (patch) | |
| tree | 0fc651f43337d65e13cccb2bbe85ab1b79666725 /src/diag.rs | |
| parent | 08a6188123ad0806986fa4f5477b728a07d081cc (diff) | |
Numbered spans
Diffstat (limited to 'src/diag.rs')
| -rw-r--r-- | src/diag.rs | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/diag.rs b/src/diag.rs index 9e756bfe..f9ffb1a5 100644 --- a/src/diag.rs +++ b/src/diag.rs @@ -36,8 +36,10 @@ pub type StrResult<T> = Result<T, String>; /// An error in a source file. #[derive(Debug, Clone, Eq, PartialEq)] pub struct Error { - /// The erroneous location in the source code. + /// The erroneous node in the source code. pub span: Span, + /// Where in the node the error should be annotated. + pub pos: ErrorPos, /// A diagnostic message describing the problem. pub message: String, /// The trace of function calls leading to the error. @@ -49,12 +51,24 @@ impl Error { pub fn new(span: Span, message: impl Into<String>) -> Self { Self { span, + pos: ErrorPos::Full, trace: vec![], message: message.into(), } } } +/// Where in a node an error should be annotated. +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum ErrorPos { + /// At the start of the node. + Start, + /// Over the full width of the node. + Full, + /// At the end of the node. + End, +} + /// A part of an error's [trace](Error::trace). #[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)] pub enum Tracepoint { @@ -110,9 +124,7 @@ impl<T> Trace<T> for TypResult<T> { { self.map_err(|mut errors| { for error in errors.iter_mut() { - if !span.surrounds(error.span) { - error.trace.push(Spanned::new(make_point(), span)); - } + error.trace.push(Spanned::new(make_point(), span)); } errors }) |
