This commit is contained in:
Quaternions 2024-07-01 12:39:39 -07:00
parent 43b5dfd0d5
commit 48c2a010d8
3 changed files with 11 additions and 5 deletions

1
Cargo.lock generated
View File

@ -1356,6 +1356,7 @@ dependencies = [
name = "rox_compiler" name = "rox_compiler"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"futures",
"lazy-regex", "lazy-regex",
"rbx_dom_weak", "rbx_dom_weak",
"rbx_xml", "rbx_xml",

View File

@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
futures = "0.3.30"
lazy-regex = "3.1.0" lazy-regex = "3.1.0"
rbx_dom_weak = "2.7.0" rbx_dom_weak = "2.7.0"
rbx_xml = "0.13.3" rbx_xml = "0.13.3"

View File

@ -394,6 +394,10 @@ enum TooComplicated<T>{
Skip, Skip,
} }
enum CompileError{
NullChildRef,
}
async fn compile(config:CompileConfig,&mut dom:rbx_dom_weak::WeakDom)->Result<(),CompileError>{ async fn compile(config:CompileConfig,&mut dom:rbx_dom_weak::WeakDom)->Result<(),CompileError>{
//add in scripts and models //add in scripts and models
let mut folder=config.input_folder.clone(); 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{ match instruction{
CompileStackInstruction::TraverseReferent(item_ref,blacklist)=>{ CompileStackInstruction::TraverseReferent(item_ref,blacklist)=>{
let sans={ 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() sanitize(item.name.as_str()).to_string()
}; };
folder.push(sans.as_str()); 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 //check if a folder exists with item.name
if let Ok(dir)=tokio::fs::read_dir(folder.as_path()).await{ if let Ok(dir)=tokio::fs::read_dir(folder.as_path()).await{
let mut exist_names:std::collections::HashSet<String>={ let mut exist_names:std::collections::HashSet<String>={
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) //push existing dom children objects onto stack (unrelated to exist_names)
stack.extend(item.children().into_iter().map(|&referent|CompileStackInstruction::TraverseReferent(referent,None))); stack.extend(item.children().into_iter().map(|&referent|CompileStackInstruction::TraverseReferent(referent,None)));
//get names of existing objects //get names of existing objects
item.children().into_iter().map(|&child_ref|{ item.children().into_iter().map(|&child_ref|{
let child=dom.get_by_ref(child_ref).ok_or(anyhow::Error::msg("null child ref"))?; let child=dom.get_by_ref(child_ref).ok_or(CompileError::NullChildRef)?;
Ok::<_,anyhow::Error>(sanitize(child.name.as_str()).to_string()) Ok::<_,CompileError>(sanitize(child.name.as_str()).to_string())
}).collect::<AResult<_>>()? }).collect::<Result<_,CompileError>>()?
}; };
if let Some(dont)=blacklist{ if let Some(dont)=blacklist{
exist_names.insert(dont); exist_names.insert(dont);