summaryrefslogtreecommitdiff
path: root/src/diagnostics/unterminated_tag.rs
blob: cab21f892fa3aca7d1112dcc31f76b08cc73538d (plain)
use miette::Diagnostic;
use thiserror::Error;

use crate::{
	diagnostics::TokenDiagnostic,
	tokenize::{Span, Token, TokenType},
};

#[derive(Error, Debug, Diagnostic)]
#[error("Unterminated tag")]
#[diagnostic(code(UnterminatedTag), severity(Error))]
pub struct UnterminatedTag {
	#[label(primary, "This tag is not terminated by a greater-than sign (>)")]
	tag: Span,
}

impl TokenDiagnostic for UnterminatedTag {
	fn handle_token(token: &Token<'_>) -> Option<Self> {
		let TokenType::Tag {
			greater_than_exists,
			..
		} = token.ty
		else {
			return None;
		};

		if greater_than_exists {
			return None;
		}

		Some(Self { tag: token.span })
	}
}