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/non_alphabetic_attribute_name.rs | 37 ++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/diagnostics/non_alphabetic_attribute_name.rs (limited to 'src/diagnostics/non_alphabetic_attribute_name.rs') diff --git a/src/diagnostics/non_alphabetic_attribute_name.rs b/src/diagnostics/non_alphabetic_attribute_name.rs new file mode 100644 index 0000000..1cb31d9 --- /dev/null +++ b/src/diagnostics/non_alphabetic_attribute_name.rs @@ -0,0 +1,37 @@ +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, + }) + } +} -- cgit v1.2.3