summaryrefslogtreecommitdiff
path: root/src/diagnostics/unterminated_comment.rs
blob: 2c583a4415b9a4570fcc35ce373c98cefb530079 (plain)
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<Self> {
		let TokenType::Comment { terminated, .. } = token.ty else {
			return None;
		};

		if terminated {
			return None;
		}

		Some(Self {
			comment: token.span,
		})
	}
}