Skip to content

Commit

Permalink
Add Spanned to Annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
flyingsilverfin committed Jan 29, 2025
1 parent e30b57a commit 024963d
Showing 1 changed file with 86 additions and 1 deletion.
87 changes: 86 additions & 1 deletion rust/annotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
use std::fmt::{self, Write};

use crate::{
common::{identifier::Identifier, token, Span},
common::{identifier::Identifier, Span, token},
util::write_joined,
value::{IntegerLiteral, Literal, StringLiteral},
};
use crate::common::Spanned;

#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Annotation {
Expand All @@ -27,6 +28,24 @@ pub enum Annotation {
Values(Values),
}

impl Spanned for Annotation {
fn span(&self) -> Option<Span> {
match self {
Annotation::Abstract(annotation) => annotation.span(),
Annotation::Cardinality(annotation) => annotation.span(),
Annotation::Cascade(annotation) => annotation.span(),
Annotation::Distinct(annotation) => annotation.span(),
Annotation::Independent(annotation) => annotation.span(),
Annotation::Key(annotation) => annotation.span(),
Annotation::Range(annotation) => annotation.span(),
Annotation::Regex(annotation) => annotation.span(),
Annotation::Subkey(annotation) => annotation.span(),
Annotation::Unique(annotation) => annotation.span(),
Annotation::Values(annotation) => annotation.span(),
}
}
}

impl fmt::Display for Annotation {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expand Down Expand Up @@ -56,6 +75,12 @@ impl Abstract {
}
}

impl Spanned for Abstract {
fn span(&self) -> Option<Span> {
self.span
}
}

impl fmt::Display for Abstract {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "@{}", token::Annotation::Abstract)
Expand All @@ -74,6 +99,12 @@ impl Cardinality {
}
}

impl Spanned for Cardinality {
fn span(&self) -> Option<Span> {
self.span
}
}

impl fmt::Display for Cardinality {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "@{}({})", token::Annotation::Cardinality, self.range)
Expand Down Expand Up @@ -107,6 +138,12 @@ impl Cascade {
}
}

impl Spanned for Cascade {
fn span(&self) -> Option<Span> {
self.span
}
}

impl fmt::Display for Cascade {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "@{}", token::Annotation::Cascade)
Expand All @@ -124,6 +161,12 @@ impl Distinct {
}
}

impl Spanned for Distinct {
fn span(&self) -> Option<Span> {
self.span
}
}

impl fmt::Display for Distinct {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "@{}", token::Annotation::Distinct)
Expand All @@ -141,6 +184,12 @@ impl Independent {
}
}

impl Spanned for Independent {
fn span(&self) -> Option<Span> {
self.span
}
}

impl fmt::Display for Independent {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "@{}", token::Annotation::Independent)
Expand All @@ -158,6 +207,12 @@ impl Key {
}
}

impl Spanned for Key {
fn span(&self) -> Option<Span> {
self.span
}
}

impl fmt::Display for Key {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "@{}", token::Annotation::Key)
Expand All @@ -177,6 +232,12 @@ impl Range {
}
}

impl Spanned for Range {
fn span(&self) -> Option<Span> {
self.span
}
}

impl fmt::Display for Range {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "@{}(", token::Annotation::Range)?;
Expand Down Expand Up @@ -204,6 +265,12 @@ impl Regex {
}
}

impl Spanned for Regex {
fn span(&self) -> Option<Span> {
self.span
}
}

impl fmt::Display for Regex {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "@{}({})", token::Annotation::Regex, self.regex.value)
Expand All @@ -222,6 +289,12 @@ impl Subkey {
}
}

impl Spanned for Subkey {
fn span(&self) -> Option<Span> {
self.span
}
}

impl fmt::Display for Subkey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "@{}({})", token::Annotation::Subkey, self.ident)
Expand All @@ -239,6 +312,12 @@ impl Unique {
}
}

impl Spanned for Unique {
fn span(&self) -> Option<Span> {
self.span
}
}

impl fmt::Display for Unique {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "@{}", token::Annotation::Unique)
Expand All @@ -257,6 +336,12 @@ impl Values {
}
}

impl Spanned for Values {
fn span(&self) -> Option<Span> {
self.span
}
}

impl fmt::Display for Values {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "@{}(", token::Annotation::Values)?;
Expand Down

0 comments on commit 024963d

Please sign in to comment.