extract_script_overrides
This commit is contained in:
parent
8ee041918b
commit
db2c760c49
45
src/main.rs
45
src/main.rs
@ -1266,6 +1266,31 @@ impl Query for QueryQuad{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ScriptWithOverrides{
|
||||||
|
overrides:PropertiesOverride,
|
||||||
|
source:String,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn extract_script_overrides(mut source:String)->AResult<ScriptWithOverrides>{
|
||||||
|
let mut overrides=PropertiesOverride::default();
|
||||||
|
let mut count=0;
|
||||||
|
for line in source.lines(){
|
||||||
|
//only string type properties are supported atm
|
||||||
|
if let Some(captures)=lazy_regex::regex!(r#"^\-\-\!\s*Properties\.([A-z]\w*)\s*\=\s*"(\w+)"$"#)
|
||||||
|
.captures(line){
|
||||||
|
count+=line.len();
|
||||||
|
match &captures[1]{
|
||||||
|
"Name"=>overrides.name=Some(captures[2].to_owned()),
|
||||||
|
"ClassName"=>overrides.class=Some(captures[2].to_owned()),
|
||||||
|
other=>return Err(anyhow::Error::msg(format!("Unimplemented property {other}"))),
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(ScriptWithOverrides{overrides,source:source.split_off(count)})
|
||||||
|
}
|
||||||
|
|
||||||
async fn discern_node(search_path:&std::path::PathBuf,search_name:&str,style:Option<DecompileStyle>)->AResult<Option<CompileNode>>{
|
async fn discern_node(search_path:&std::path::PathBuf,search_name:&str,style:Option<DecompileStyle>)->AResult<Option<CompileNode>>{
|
||||||
let mut contents_folder=search_path.clone();
|
let mut contents_folder=search_path.clone();
|
||||||
contents_folder.push(search_name);
|
contents_folder.push(search_name);
|
||||||
@ -1293,10 +1318,19 @@ async fn discern_node(search_path:&std::path::PathBuf,search_name:&str,style:Opt
|
|||||||
let mut buf=String::new();
|
let mut buf=String::new();
|
||||||
file.read_to_string(&mut buf).await?;
|
file.read_to_string(&mut buf).await?;
|
||||||
//regex script according to Properties lines at the top
|
//regex script according to Properties lines at the top
|
||||||
todo!("unimplemented");
|
let script_with_overrides=extract_script_overrides(buf)?;
|
||||||
//script
|
//script
|
||||||
CompileNode{
|
CompileNode{
|
||||||
class:CompileClass::Script(buf),
|
name:script_with_overrides.overrides.name.unwrap_or_else(||search_name.to_owned()),
|
||||||
|
class:match (script_with_overrides.overrides.class.as_deref(),hint){
|
||||||
|
(Some("ModuleScript"),_)
|
||||||
|
|(None,ScriptHint::ModuleScript|ScriptHint::Undetermined)=>CompileClass::ModuleScript(script_with_overrides.source),
|
||||||
|
(Some("LocalScript"),_)
|
||||||
|
|(None,ScriptHint::Script)=>CompileClass::LocalScript(script_with_overrides.source),
|
||||||
|
(Some("Script"),_)
|
||||||
|
|(None,ScriptHint::LocalScript)=>CompileClass::Script(script_with_overrides.source),
|
||||||
|
other=>return Err(anyhow::Error::msg(format!("Invalid hint or class {other:?}"))),
|
||||||
|
},
|
||||||
folder:Some(dir),
|
folder:Some(dir),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -1306,6 +1340,7 @@ async fn discern_node(search_path:&std::path::PathBuf,search_name:&str,style:Opt
|
|||||||
file.read_to_end(&mut buf).await?;
|
file.read_to_end(&mut buf).await?;
|
||||||
//model
|
//model
|
||||||
CompileNode{
|
CompileNode{
|
||||||
|
name:search_name.to_owned(),
|
||||||
class:CompileClass::Model(buf),
|
class:CompileClass::Model(buf),
|
||||||
folder:Some(dir),
|
folder:Some(dir),
|
||||||
}
|
}
|
||||||
@ -1313,6 +1348,7 @@ async fn discern_node(search_path:&std::path::PathBuf,search_name:&str,style:Opt
|
|||||||
(Ok(_),Ok(_))=>Err(QueryResolveError::Ambiguous)?,
|
(Ok(_),Ok(_))=>Err(QueryResolveError::Ambiguous)?,
|
||||||
//neither
|
//neither
|
||||||
(Err(QueryResolveError::NotFound),Err(QueryResolveError::NotFound))=>CompileNode{
|
(Err(QueryResolveError::NotFound),Err(QueryResolveError::NotFound))=>CompileNode{
|
||||||
|
name:search_name.to_owned(),
|
||||||
class:CompileClass::Folder,
|
class:CompileClass::Folder,
|
||||||
folder:Some(dir),
|
folder:Some(dir),
|
||||||
},
|
},
|
||||||
@ -1325,7 +1361,7 @@ async fn discern_node(search_path:&std::path::PathBuf,search_name:&str,style:Opt
|
|||||||
None
|
None
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
#[derive(Debug)]
|
||||||
enum ScriptHint{
|
enum ScriptHint{
|
||||||
Script,
|
Script,
|
||||||
LocalScript,
|
LocalScript,
|
||||||
@ -1346,8 +1382,9 @@ enum CompileClass{
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct CompileNode{
|
struct CompileNode{
|
||||||
folder:Option<tokio::fs::ReadDir>,
|
name:String,
|
||||||
class:CompileClass,
|
class:CompileClass,
|
||||||
|
folder:Option<tokio::fs::ReadDir>,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum CompileStackInstruction{
|
enum CompileStackInstruction{
|
||||||
|
Loading…
Reference in New Issue
Block a user