diff --git a/Cargo.lock b/Cargo.lock index 904478a..afe3e8d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1356,6 +1356,7 @@ dependencies = [ name = "rox_compiler" version = "0.1.0" dependencies = [ + "futures", "lazy-regex", "rbx_dom_weak", "rbx_xml", diff --git a/rox_compiler/Cargo.toml b/rox_compiler/Cargo.toml index cc6c259..dca7762 100644 --- a/rox_compiler/Cargo.toml +++ b/rox_compiler/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] +futures = "0.3.30" lazy-regex = "3.1.0" rbx_dom_weak = "2.7.0" rbx_xml = "0.13.3" diff --git a/rox_compiler/src/compile.rs b/rox_compiler/src/compile.rs index 0f7b1fa..f7275ef 100644 --- a/rox_compiler/src/compile.rs +++ b/rox_compiler/src/compile.rs @@ -394,6 +394,10 @@ enum TooComplicated{ Skip, } +enum CompileError{ + NullChildRef, +} + async fn compile(config:CompileConfig,&mut dom:rbx_dom_weak::WeakDom)->Result<(),CompileError>{ //add in scripts and models let mut folder=config.input_folder.clone(); @@ -402,7 +406,7 @@ async fn compile(config:CompileConfig,&mut dom:rbx_dom_weak::WeakDom)->Result<() match instruction{ CompileStackInstruction::TraverseReferent(item_ref,blacklist)=>{ let sans={ - let item=dom.get_by_ref(item_ref).ok_or(anyhow::Error::msg("null child ref"))?; + let item=dom.get_by_ref(item_ref).ok_or(CompileError::NullChildRef)?; sanitize(item.name.as_str()).to_string() }; folder.push(sans.as_str()); @@ -410,14 +414,14 @@ async fn compile(config:CompileConfig,&mut dom:rbx_dom_weak::WeakDom)->Result<() //check if a folder exists with item.name if let Ok(dir)=tokio::fs::read_dir(folder.as_path()).await{ let mut exist_names:std::collections::HashSet={ - let item=dom.get_by_ref(item_ref).ok_or(anyhow::Error::msg("null child ref"))?; + let item=dom.get_by_ref(item_ref).ok_or(CompileError::NullChildRef)?; //push existing dom children objects onto stack (unrelated to exist_names) stack.extend(item.children().into_iter().map(|&referent|CompileStackInstruction::TraverseReferent(referent,None))); //get names of existing objects item.children().into_iter().map(|&child_ref|{ - let child=dom.get_by_ref(child_ref).ok_or(anyhow::Error::msg("null child ref"))?; - Ok::<_,anyhow::Error>(sanitize(child.name.as_str()).to_string()) - }).collect::>()? + let child=dom.get_by_ref(child_ref).ok_or(CompileError::NullChildRef)?; + Ok::<_,CompileError>(sanitize(child.name.as_str()).to_string()) + }).collect::>()? }; if let Some(dont)=blacklist{ exist_names.insert(dont);