From 8399983fd45bc0f11eac9def280c0833ffb93c04 Mon Sep 17 00:00:00 2001 From: Mica White Date: Sun, 12 Jul 2026 19:49:14 -0400 Subject: initial commit --- src/diagnostics/unterminated_comment.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/diagnostics/unterminated_comment.rs (limited to 'src/diagnostics/unterminated_comment.rs') diff --git a/src/diagnostics/unterminated_comment.rs b/src/diagnostics/unterminated_comment.rs new file mode 100644 index 0000000..2c583a4 --- /dev/null +++ b/src/diagnostics/unterminated_comment.rs @@ -0,0 +1,31 @@ +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, + }) + } +} -- cgit v1.2.3