use crate::span::Span;
use super::expr::Expr;
use super::path::Path;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Annotation {
Marker { at_token: Span, name: Path },
SingleElement {
at_token: Span,
name: Path,
eq_token: Span,
value: Box<ElementValue>,
},
Normal {
at_token: Span,
name: Path,
paren_span: (Span, Span), pairs: Vec<ElementValuePair>,
},
}
impl Annotation {
pub fn span(&self) -> Span {
match self {
Self::Marker { at_token, name } => at_token.join(name.span),
Self::SingleElement {
at_token, value, ..
} => at_token.join(value.span()),
Self::Normal {
at_token,
paren_span,
..
} => at_token.join(paren_span.1),
}
}
pub fn path(&self) -> &Path {
match self {
Self::Marker { name, .. } => name,
Self::SingleElement { name, .. } => name,
Self::Normal { name, .. } => name,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ElementValuePair {
pub key: crate::ident::Ident,
pub eq_span: Span,
pub value: ElementValue,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ElementValue {
Expr(Expr),
Array {
brace_span: (Span, Span),
values: Vec<ElementValue>,
trailing_comma: bool,
},
Annotation(Annotation),
}
impl ElementValue {
pub fn span(&self) -> Span {
match self {
Self::Expr(e) => e.span(),
Self::Array { brace_span, .. } => brace_span.0.join(brace_span.1),
Self::Annotation(a) => a.span(),
}
}
}