mod context;
mod decl;
mod desugar;
mod expr;
mod stmt;
pub use context::LoweringContext;
pub use desugar::{lower_file, lower_module};
#[derive(Debug, Clone)]
pub struct LowerDiagnostic {
pub kind: DiagnosticKind,
pub message: String,
pub span: Option<crate::ast::Span>,
pub suggestion: Option<String>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DiagnosticKind {
Deprecation,
Warning,
Error,
}
impl std::fmt::Display for LowerDiagnostic {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let prefix = match self.kind {
DiagnosticKind::Deprecation => "deprecated",
DiagnosticKind::Warning => "warning",
DiagnosticKind::Error => "error",
};
write!(f, "{}: {}", prefix, self.message)?;
if let Some(suggestion) = &self.suggestion {
write!(f, " (suggestion: {})", suggestion)?;
}
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_diagnostic_display() {
let diag = LowerDiagnostic {
kind: DiagnosticKind::Deprecation,
message: "'let' is deprecated".to_string(),
span: None,
suggestion: Some("use 'val' instead".to_string()),
};
let s = format!("{}", diag);
assert!(s.contains("deprecated"));
assert!(s.contains("let"));
assert!(s.contains("val"));
}
#[test]
fn test_diagnostic_kind_eq() {
assert_eq!(DiagnosticKind::Error, DiagnosticKind::Error);
assert_ne!(DiagnosticKind::Error, DiagnosticKind::Warning);
}
}