use miette::Diagnostic; use thiserror::Error; use crate::{ diagnostics::TokenDiagnostic, tokenize::{AttributeToken, AttributeTokenType, Span}, }; #[derive(Error, Debug, Diagnostic)] #[error("Attribute names must be alphabetic")] #[diagnostic(code(NonAlphabeticAttributeName), severity(Error))] pub struct NonAlphabeticAttributeName { #[label( primary, "attribute names must only contain uppercase and lowercase letters" )] attribute_name: Span, } impl TokenDiagnostic for NonAlphabeticAttributeName { fn handle_attribute_token(token: &AttributeToken<'_>) -> Option { let AttributeTokenType::Identifier { lowercase_name, .. } = token.ty else { return None; }; if lowercase_name .chars() .all(|char| char.is_ascii_alphabetic()) { return None; } Some(Self { attribute_name: token.span, }) } }