diff options
Diffstat (limited to 'src/diagnostics/too_many_equal_signs.rs')
| -rw-r--r-- | src/diagnostics/too_many_equal_signs.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/diagnostics/too_many_equal_signs.rs b/src/diagnostics/too_many_equal_signs.rs new file mode 100644 index 0000000..b20cb83 --- /dev/null +++ b/src/diagnostics/too_many_equal_signs.rs @@ -0,0 +1,35 @@ +use miette::Diagnostic; +use thiserror::Error; + +use crate::{diagnostics::AstDiagnostic, parse::Attribute, tokenize::Span}; + +#[derive(Error, Debug, Diagnostic)] +#[error("Multiple equal signs in a row")] +#[diagnostic(code(TooManyEqualSigns), severity(Error))] +pub struct TooManyEqualSigns { + #[label(primary, "only one equal sign should be present")] + token: Span, +} + +impl AstDiagnostic for TooManyEqualSigns { + fn handle_attribute(attribute: &crate::parse::Attribute<'_>) -> Option<Self> { + let Attribute::NamedArgumentWithTooManyEqualSigns { equal_signs, .. } = attribute else { + return None; + }; + + Some(Self { + token: Span { + start: equal_signs + .first() + .expect("at least two equal signs") + .span + .start, + end: equal_signs + .last() + .expect("at least two equal signs") + .span + .end, + }, + }) + } +} |
