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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
use serde::{Serialize, Deserialize};

use shm_rs::static_scheme::generator::RustCode;
use shm_rs::static_scheme::init;
use shm_rs::dynamic_scheme::environment;
use shm_rs::serializator::serializator;

#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum MyEnum 
{ 
    Item1, 

    Item2
}


pub const TEST_SYMBOL: &'static str = "test1234";

/// An enum for the auto type 
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum ShmTypeAnyField 
{ 
    /// An integer data type
    Int(i64), 

    /// An unsigned integer type
    UInt(u64), 

    /// An integer data type
    LongInt(i64), 

    /// An unsigned integer type
    LongUInt(u64), 

    /// A boolean type
    Bool(bool), 

    /// A string type
    String(String), 

    /// An entity type
    Entity(String), 

    /// A variable type
    Variable(String)
}


#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct TestStruct 
{ 
    pub auto_field: ShmTypeAnyField,
    pub auto_u128: ShmTypeAnyField,
    pub auto_vec: Vec<ShmTypeAnyField>,
    pub auto_symb: ShmTypeAnyField,
    pub auto_enum: ShmTypeAnyField
}

fn main()
{
    let curdir = std::env::current_dir().unwrap();

    println!("{}", curdir.display());

    let schm = init::SchemeInit::new_with_path(curdir).unwrap();

    let res = schm.run_from_file("examples/scheme_auto/test_auto_init.shm", None).unwrap();

    let resser = res.get("test_auto").unwrap().clone();

    let mut curdir = std::env::current_dir().unwrap();

    curdir.push("examples/scheme_auto/test_auto_data.shm");

   // let lex = lexer::Lexer::from_file(curdir).unwrap();
    let (_dynenv, dyn_res) = 
        environment::DynEnvironment::from_file(curdir, resser.clone()).unwrap();
   // let dynenv = environment::DynEnvironment::new_root(resser.clone());

    //let dyn_res = environment::DynEnvironment::run(&lex, dynenv).unwrap();

    let ret = serializator::Serialization::serialize(resser.clone(), dyn_res.clone()).unwrap();

    let serialized = serde_json::to_string(&ret).unwrap();

        // control

        let ctrl_struct = 
        TestStruct
        { 
            auto_field: ShmTypeAnyField::UInt(4),
            auto_u128: ShmTypeAnyField::LongUInt(128),
            auto_vec: vec![ShmTypeAnyField::String("test".to_string()), ShmTypeAnyField::Int(34), ShmTypeAnyField::UInt(34), ShmTypeAnyField::Bool(true)],
            auto_symb: ShmTypeAnyField::String(String::from("test1234")),
            auto_enum: ShmTypeAnyField::String(String::from("Item1")),
        };
    let ctrl_struct_ser = serde_json::to_string(&ctrl_struct).unwrap();

    println!("Control:\n{}\n", ctrl_struct_ser);

    println!("Serialized Result:\n{}", serialized);

    let deserialized: TestStruct = serde_json::from_str(&serialized).unwrap();

    println!("Deserialized result: \n{:?}", deserialized);




    if ctrl_struct_ser != serialized
    {
        panic!("not equal");
    }
    else
    {
        println!("OK");
    }


    let mut rc = RustCode::new(&["Clone", "Debug", "Serialize", "Deserialize"], &["Clone", "Debug", "Serialize", "Deserialize"]);
    println!("Structures: ");
    match resser.generate_rust_structs(&mut rc)
    {
        Ok(_) => 
        {
            println!("{}", rc);
        },
        Err(e) => 
        {
            println!("{}", e);
        }
    }

}