use serde::{Serialize, Deserialize}; use shm_rs::Lexer; use shm_rs::lexer::lexer; use shm_rs::scheme_composer::composer::from_struct; use shm_rs::serializator::serializator; use shm_rs::static_scheme::init; use shm_rs::dynamic_scheme::environment; #[derive(Serialize, Deserialize)] enum MyEnum { Item1, Item2 } #[allow(non_camel_case_types)] #[derive(Serialize, Deserialize)] enum OurEnum { H_item1, Item2, C_item } #[derive(Serialize, Deserialize)] struct CommonLevels { enum1: MyEnum, enum2: OurEnum } pub fn main() { let mut curdir = std::env::current_dir().unwrap(); curdir.push("examples/struct_to_scheme/enum_arg/init_enum.shm"); println!("{}", curdir.display()); let lex = lexer::Lexer::from_file(curdir).unwrap(); let schm = init::SchemeInit::new().unwrap(); let res = schm.run(&lex, None).unwrap(); let resser = res.get("test1").unwrap().clone(); println!("Static: \n{:?}\n", res); let mut curdir = std::env::current_dir().unwrap(); curdir.push("examples/struct_to_scheme/enum_arg/enum.shm"); let lex = lexer::Lexer::from_file(curdir).unwrap(); let dynenv = environment::DynEnvironment::new_root(resser.clone()).unwrap(); let dynres = environment::DynEnvironment::run(&lex, dynenv).unwrap(); let ret = serializator::Serialization::serialize(resser.clone(), dynres.clone()).unwrap(); let serialized = serde_json::to_string(&ret).unwrap(); let n: CommonLevels = serde_json::from_str(&serialized).unwrap(); let scmp = from_struct(n, resser.clone()); if scmp.is_err() == true { panic!("{}", scmp.err().unwrap()); } else { let out_res = scmp.unwrap(); println!("{}", out_res); let lex_out = Lexer::from_str(&out_res.to_string(), "test").unwrap(); let dyn_root = environment::DynEnvironment::new_root(resser.clone()).unwrap(); let dyn_res = environment::DynEnvironment::run(&lex_out, dyn_root); if dyn_res.is_err() == true { println!("{}", dyn_res.err().unwrap()); } } }