Added no_space parameter for units

This commit is contained in:
2023-06-13 09:13:24 -07:00
parent 088853014e
commit a6bcbd5f66
4 changed files with 53 additions and 10 deletions

View File

@ -31,6 +31,7 @@ fn write_wholeunit_main(mut file: &File, units: &Vec<Value>) {
writeln!(file, "}}\n").unwrap();
// ToString
writeln!(file,
concat!(
"impl ToString for WholeUnit {{\n",
@ -47,7 +48,30 @@ fn write_wholeunit_main(mut file: &File, units: &Vec<Value>) {
).unwrap();
}
writeln!(file, "\t\t}})\n\t}}\n}}").unwrap();
writeln!(file, "\t\t}})\n\t}}\n}}\n").unwrap();
// Properties
writeln!(file,
concat!(
"impl WholeUnit {{\n",
"\tfn no_space(&self) -> bool {{\n",
"\t\tmatch self {{"
)
).unwrap();
for u in units {
if u.as_table().unwrap().contains_key("no_space") {
if u.as_table().unwrap()["no_space"].as_bool().unwrap() {
writeln!(file,
"\t\t\tWholeUnit::{} => true,",
u["enum_name"].as_str().unwrap()
).unwrap();
}
}
}
writeln!(file, "\t\t\t_ => false\n\t\t}}\n\t}}\n}}").unwrap();
}
@ -223,9 +247,6 @@ fn write_freeunit_from_string(mut file: &File, units: &Vec<Value>) {
fn main() -> Result<(), ()>{
let out_dir = env::var_os("OUT_DIR").unwrap();