use miette::Diagnostic; use thiserror::Error; use crate::{ diagnostics::TokenDiagnostic, tokenize::{Span, Token, TokenType}, }; #[derive(Error, Debug, Diagnostic)] #[error("Unterminated comment")] #[diagnostic(code(UnterminatedComment), severity(Error))] pub struct UnterminatedComment { #[label(primary, "This comment is not terminated by a `-->` sequence")] comment: Span, } impl TokenDiagnostic for UnterminatedComment { fn handle_token(token: &Token<'_>) -> Option { let TokenType::Comment { terminated, .. } = token.ty else { return None; }; if terminated { return None; } Some(Self { comment: token.span, }) } }