Skip to main content

cabalist_parser/
diagnostic.rs

1//! Diagnostics emitted during parsing.
2
3use crate::span::Span;
4
5/// Severity level for a diagnostic.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7pub enum Severity {
8    /// A hard error: the file is structurally invalid at this point.
9    Error,
10    /// Something suspicious but not necessarily wrong.
11    Warning,
12    /// Informational note.
13    Info,
14}
15
16/// A diagnostic message attached to a source location.
17#[derive(Debug, Clone, PartialEq, Eq)]
18pub struct Diagnostic {
19    pub severity: Severity,
20    pub message: String,
21    pub span: Span,
22}
23
24impl Diagnostic {
25    pub fn error(span: Span, message: impl Into<String>) -> Self {
26        Self {
27            severity: Severity::Error,
28            message: message.into(),
29            span,
30        }
31    }
32
33    pub fn warning(span: Span, message: impl Into<String>) -> Self {
34        Self {
35            severity: Severity::Warning,
36            message: message.into(),
37            span,
38        }
39    }
40
41    pub fn info(span: Span, message: impl Into<String>) -> Self {
42        Self {
43            severity: Severity::Info,
44            message: message.into(),
45            span,
46        }
47    }
48}