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 struct LdActionExec { pub executable: String } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct LdGrep { pub regex_str: String } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct LdActionBlock { pub exec_pipeline: Vec, pub grep_pipe: Option } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct LdAction { pub action_block: Option, pub action_unblock: Option } fn main() { let control_inst = LdAction { action_block: Some( LdActionBlock { exec_pipeline: vec![ LdActionExec { executable: "test1".to_string() }, LdActionExec { executable: "test2".to_string() }, ], grep_pipe: Some( LdGrep { regex_str: "grep1".to_string() } ), } ), action_unblock: Some( LdActionBlock { exec_pipeline: vec![ LdActionExec { executable: "unblock_test".to_string() }, ], grep_pipe: None } ), }; 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_common_struct/schm_init.shm", None).unwrap(); let resser = res.get("test_common").unwrap().clone(); let mut curdir = std::env::current_dir().unwrap(); curdir.push("examples/scheme_common_struct/schm_dyn.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(); println!("Serialized:\n{}", serialized); let ctrl_ser = serde_json::to_string(&control_inst).unwrap(); if ctrl_ser == serialized { println!("matched!"); } else { panic!("unmatched"); } let _: LdAction = serde_json::from_str(&ctrl_ser).unwrap(); 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); } } }