1
use crate::metadata::Metadata;
2

            
3
use super::{Expression, Literal, Name};
4
use serde::{Deserialize, Serialize};
5
use uniplate::derive::Uniplate;
6

            
7
/// An `Atom` is an indivisible expression, such as a literal or a reference.
8
3246
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Uniplate)]
9
#[uniplate()]
10
#[biplate(to=Name)]
11
#[biplate(to=Literal)]
12
#[biplate(to=Metadata)]
13
#[biplate(to=Expression)]
14
pub enum Atom {
15
    Literal(Literal),
16
    Reference(Name),
17
}
18

            
19
impl std::fmt::Display for Atom {
20
46971
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21
46971
        match self {
22
13447
            Atom::Literal(x) => x.fmt(f),
23
33524
            Atom::Reference(x) => x.fmt(f),
24
        }
25
46971
    }
26
}
27

            
28
impl From<Literal> for Atom {
29
    fn from(value: Literal) -> Self {
30
        Atom::Literal(value)
31
    }
32
}
33

            
34
impl From<Name> for Atom {
35
816
    fn from(value: Name) -> Self {
36
816
        Atom::Reference(value)
37
816
    }
38
}