use alloc::string::String;
use alloc::vec::Vec;
use core::fmt;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[non_exhaustive]
pub struct Atom {
pub symbol: String,
pub arguments: Vec<String>,
}
impl Atom {
#[must_use]
pub fn new<S, I, A>(symbol: S, arguments: I) -> Self
where
S: AsRef<str>,
I: IntoIterator<Item = A>,
A: AsRef<str>,
{
Self {
symbol: lower(symbol.as_ref()),
arguments: arguments.into_iter().map(|a| lower(a.as_ref())).collect(),
}
}
pub(crate) const fn lowered(symbol: String, arguments: Vec<String>) -> Self {
Self { symbol, arguments }
}
}
impl fmt::Display for Atom {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "({}", self.symbol)?;
for argument in &self.arguments {
write!(f, " {argument}")?;
}
f.write_str(")")
}
}
pub(crate) fn lower(name: &str) -> String {
name.to_ascii_lowercase()
}