tamer: xir::tree::attr: Display impls

main
Mike Gerwitz 2021-11-23 13:05:10 -05:00
parent ba7ebad930
commit 54531e2284
1 changed files with 22 additions and 0 deletions

View File

@ -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