Nilton Constantino c01c6ee17c
pr 08
2026-01-28 18:23:48 +00:00

58 lines
1.2 KiB
Rust

use crate::common::spans::Span;
#[derive(Debug, Clone)]
pub enum DiagnosticLevel {
Error,
Warning,
}
#[derive(Debug, Clone)]
pub struct Diagnostic {
pub level: DiagnosticLevel,
pub code: Option<String>,
pub message: String,
pub span: Option<Span>,
}
#[derive(Debug, Clone)]
pub struct DiagnosticBundle {
pub diagnostics: Vec<Diagnostic>,
}
impl DiagnosticBundle {
pub fn new() -> Self {
Self {
diagnostics: Vec::new(),
}
}
pub fn push(&mut self, diagnostic: Diagnostic) {
self.diagnostics.push(diagnostic);
}
pub fn error(message: String, span: Option<Span>) -> Self {
let mut bundle = Self::new();
bundle.push(Diagnostic {
level: DiagnosticLevel::Error,
code: None,
message,
span,
});
bundle
}
pub fn has_errors(&self) -> bool {
self.diagnostics
.iter()
.any(|d| matches!(d.level, DiagnosticLevel::Error))
}
}
impl From<Diagnostic> for DiagnosticBundle {
fn from(diagnostic: Diagnostic) -> Self {
let mut bundle = Self::new();
bundle.push(diagnostic);
bundle
}
}