diff --git a/app.html b/app.html new file mode 100644 index 0000000..7190a48 --- /dev/null +++ b/app.html @@ -0,0 +1,17 @@ + + + + + + app + + + +

hi: {name}

i said hello +

Age:{age}

title:{title}

+ +in[one:[name="kenneth"]]in[two:[age="34" title="chief"]]in[one:[name="val"]] +in[one:[name="ken"]] + + + \ No newline at end of file diff --git a/app.js b/app.js new file mode 100644 index 0000000..e69de29 diff --git a/gen.scml b/gen.scml new file mode 100644 index 0000000..563fa30 --- /dev/null +++ b/gen.scml @@ -0,0 +1,17 @@ +[html one] +

hi: {name}

+i said hello +[html] + +[html two] +

Age:{age}

+

title:{title}

+[html] + +[html] +in[one:[name="kenneth"]] +in[two:[age="34" title="chief"]] +in[one:[name="val"]] +[html] + +in[one:[name="ken"]] \ No newline at end of file diff --git a/src/html_processing.rs b/src/html_processing.rs index b778016..b7ec649 100644 --- a/src/html_processing.rs +++ b/src/html_processing.rs @@ -41,35 +41,50 @@ pub mod process_html{ tmp } - // pub fn replace_variable_parameter(scml_string:&str, scml_hash:HashMap)->String{ - // let mut tmp=String::from(scml_string); - // let mut html_id = HashMap::new(); - - // for (key, mut value) in scml_hash{ - // let string_target=format!(r#"in\[{}\s*?:\s*?\[(\w+=\s*?["|']\s*?[[:alnum:]]*[[:punct:]]*\s*?["|']\s*?)\]+?\s*?\]"#, key); - // let string_regex=Regex::new(&string_target).unwrap(); - // for val in string_regex.captures_iter(scml_string){ - - // for val2 in Regex::new(r#"\s*?(\w+)\s*?=["|']\s*?(.*)["|'],??"#).unwrap().captures_iter(val.get(1).unwrap().as_str()){ - // if Regex::new(r#"\s*?(\w+)\s*?=["|']\s*?(.*)["|']"#).unwrap().is_match(val.get(1).unwrap().as_str()){ - - // html_id.insert(String::from(val2.get(1).unwrap().as_str()), val2.get(2).unwrap().as_str()); - // } - // } - - // let mut new_val=String::from(value); - - // for (key2, value2) in &html_id{ - // let var_format=format!("{{{{{}}}}}", key2); - - // new_val= value.replace(&var_format, &value2); - // } - // let string_litral=format!("in[{}:[{}]]", key, val.get(1).unwrap().as_str()); - // tmp=tmp.replace(&string_litral, &new_val); - // } - // } - // tmp - // } + pub fn replace_variable_parameter(scml_string:&str, scml_hash:&HashMap)->String{ + let mut tmp=String::from(scml_string); + + // for _i in 1..50{ + for (key, value) in scml_hash{ + //get hash conten + let mut key_content= value.to_string(); + + //in[seg_name:[name="value"]] + let string_target=format!(r#"in\[{}\s*?:\s*?(\[\w+=\s*?["|']\s*?.+?\s*?["|']\s*?\]+?)\s*?\]"#, key); + let string_regex=Regex::new(&string_target).unwrap(); + + + let generic_hash=generate_generic_hash(&scml_string, &key); + for(generic_hash_key, generic_hash_value) in &generic_hash{ + + let key=format!(r#"{{{}}}"#, generic_hash_key); + + key_content=key_content.replace(&key, &generic_hash_value); + + } + tmp=string_regex.replace(&tmp, key_content.as_str()).to_string(); + } + // } + + tmp + } + + fn generate_generic_hash(scml_string:&str, key:&str)->HashMap{ + let mut generic_hash = HashMap::new(); + + let string_target=format!(r#"in\[{}\s*?:\s*?(\[\w+=\s*?["|']\s*?.+?\s*?["|']\s*?\]+?)\s*?\]"#, key); + let string_regex=Regex::new(&string_target).unwrap(); + + let variables=format!(r#"(\w+)=\s*?["|']\s*?(.+?)\s*?["|']\s*?"#); + let string_variables=Regex::new(&variables).unwrap(); + + for val in string_regex.captures_iter(scml_string){ + for val2 in string_variables.captures_iter(val.get(1).unwrap().as_str()){ + generic_hash.insert(String::from(val2.get(1).unwrap().as_str()), String::from(val2.get(2).unwrap().as_str())); + } + } + generic_hash + } pub fn generate_scml_hash(value:&str)->HashMap{ let re= Regex::new(r"\[html (\w+)\]\s*?(.+?)\s*?\[html\]").unwrap(); diff --git a/src/main.rs b/src/main.rs index 8a5fe52..c2793ba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,6 +28,8 @@ fn main() { let hash_value=process_html::generate_scml_hash(&file_content); let final_string=process_html::replace_variable(&file_content, &hash_value); + let generaic_seg=process_html::replace_variable_parameter(&file_content, &hash_value); + println!("{}", generaic_seg); let vector=process_js::process_innerjs(&file_content); if vector.len()>0 { diff --git a/tester.scml b/tester.scml index fb3087b..156b912 100644 --- a/tester.scml +++ b/tester.scml @@ -63,5 +63,9 @@ inFile[head.scml]

copy me

+in[five:[name="val house" age="34" date="23/34/2020"]] +in[three:[name="kin" age="44" date="23/34/2020"]] +
-[html] \ No newline at end of file +in[one] +[html]