summaryrefslogtreecommitdiff
path: root/src/diagnostics/non_alphabetic_attribute_name.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/diagnostics/non_alphabetic_attribute_name.rs')
-rw-r--r--src/diagnostics/non_alphabetic_attribute_name.rs37
1 files changed, 37 insertions, 0 deletions
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<Self> {
+ 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,
+ })
+ }
+}