use super::*;
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum NamespaceKind {
Shared,
Unique,
Test,
}
impl Display for NamespaceKind {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
f.write_str("namespace")?;
match self {
NamespaceKind::Shared => Ok(()),
NamespaceKind::Unique => f.write_char('!'),
NamespaceKind::Test => f.write_char('?'),
}
}
}
impl Display for NamespaceDeclarationNode {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(f, "{} ", self.kind)?;
for (idx, id) in self.path.iter().enumerate() {
if idx != 0 {
f.write_char('.')?;
}
Display::fmt(id, f)?;
}
Ok(())
}
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct NamespaceDeclarationNode {
pub kind: NamespaceKind,
pub path: Vec<IdentifierNode>,
pub span: Range<usize>,
}
impl NamespaceDeclarationNode {
pub fn new<I>(names: I, range: &Range<usize>) -> Self
where
I: IntoIterator<Item = IdentifierNode>,
{
Self { kind: NamespaceKind::Unique, path: names.into_iter().collect(), span: range.clone() }
}
pub fn with_kind(mut self, kind: NamespaceKind) -> Self {
self.kind = kind;
self
}
}