tamer: xir::tree::attr: Display impls
parent
ba7ebad930
commit
54531e2284
|
@ -25,6 +25,7 @@
|
|||
|
||||
use super::QName;
|
||||
use crate::{span::Span, sym::SymbolId};
|
||||
use std::fmt::Display;
|
||||
|
||||
/// An attribute.
|
||||
///
|
||||
|
@ -143,6 +144,15 @@ impl Attr {
|
|||
}
|
||||
}
|
||||
|
||||
impl Display for Attr {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Simple(attr) => attr.fmt(f),
|
||||
Self::Extensible(parts) => parts.fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Element attribute with an atomic value.
|
||||
///
|
||||
/// This should be used in place of [`AttrParts`] whenever the attribute is
|
||||
|
@ -164,6 +174,12 @@ impl SimpleAttr {
|
|||
}
|
||||
}
|
||||
|
||||
impl Display for SimpleAttr {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "`@{}=\"{}\"` at {}", self.name, self.value, self.span.0)
|
||||
}
|
||||
}
|
||||
|
||||
/// Element attribute with a value composed of multiple fragments.
|
||||
///
|
||||
/// This should be used when one or more of these properties is desirable:
|
||||
|
@ -253,6 +269,12 @@ impl From<Attr> for AttrParts {
|
|||
}
|
||||
}
|
||||
|
||||
impl Display for AttrParts {
|
||||
fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
todo!("<AttrParts as std::fmt::Display>::fmt")
|
||||
}
|
||||
}
|
||||
|
||||
/// List of attributes.
|
||||
///
|
||||
/// Attributes are ordered in XIR so that this IR will be suitable for code
|
||||
|
|
Loading…
Reference in New Issue