1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
pub mod constant;
pub mod symbol;
pub mod list;

use std::{collections::HashMap, fmt::{Debug, Display}, sync::Arc};
use serde::{Serialize, Deserialize};

use self::{constant::Constant, list::List, symbol::Symbol};

pub type Handle<T> = Arc<T>;


#[derive(Debug, Clone, PartialEq)]
#[derive(Serialize, Deserialize)]
pub enum GAst {
    Const(Constant),
    List(Handle<List>),
}


#[derive(Debug, Clone, PartialEq)]
#[derive(Serialize, Deserialize)]
pub struct Record (pub HashMap<Handle<Symbol>, GAst>);


impl Display for GAst {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        fmt_gast_case!(self, f, Const);
        fmt_gast_case!(self, f, List);
        unreachable!()
    }
}

impl GAst {
    impl_is_type!(is_const, Const);
    impl_is_type!(is_list, List);
}

impl GAst {
    impl_get_item!(get_const, Const, Constant);
    impl_get_item!(get_list, List, Handle<List>);
}