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; use shm_rs::RustCodeDerives; #[derive(Serialize, Deserialize)] enum MyEnum { Item1, Item2 } #[allow(non_camel_case_types)] #[derive(Serialize, Deserialize)] enum OurEnum { HItem1, Item2, CItem, Item3Test } #[derive(Serialize, Deserialize)] struct CommonLevels { enum1: MyEnum, enum2: OurEnum, enum3: MyEnum, enum4: Vec } fn main() { let curdir = std::env::current_dir().unwrap(); //curdir.push("examples/test3.shm"); println!("{}", curdir.display()); // let lex = lexer::Lexer::from_file(curdir).unwrap(); let schm = init::SchemeInit::new_with_path(curdir).unwrap(); let res = schm.run_from_file("examples/scheme_enum/init_enum.shm", None).unwrap(); let resser = res.get("test1").unwrap().clone(); println!("{:?}", res); let mut rc = RustCode::new(vec![RustCodeDerives::Debug], vec![], None); println!("Structures: "); match resser.generate_rust_code(&mut rc) { Ok(_) => { println!("{}", rc); }, Err(e) => { panic!("{}", e); } } let mut curdir = std::env::current_dir().unwrap(); curdir.push("examples/scheme_enum/enum.shm"); let (_, dyn_res) = environment::DynEnvironment::from_file(curdir, resser.clone()).unwrap(); let ret = serializator::Serialization::serialize(resser.clone(), dyn_res.clone()).unwrap(); //println!("dynproc:\n{:?}\n", dyn_res); let serialized = serde_json::to_string(&ret).unwrap(); println!("Result:\n{}", serialized); let _deserialized: CommonLevels = serde_json::from_str(&serialized).unwrap(); let lvls = CommonLevels { enum1: MyEnum::Item1, enum2: OurEnum::Item2, enum3: MyEnum::Item2, enum4: vec![OurEnum::HItem1, OurEnum::Item2, OurEnum::CItem], }; let serialized_nat = serde_json::to_string(&lvls).unwrap(); println!("nat:{}", serialized_nat); println!("ser:{}", serialized); if serialized != serialized_nat { panic!("not equal"); } }