comline/core/src/codegen/mod.rs

38 lines
1,009 B
Rust

// Relative Modules
pub(crate) mod rust;
pub(crate) mod luau;
pub(crate) mod python;
// Standard Uses
use std::collections::HashMap;
// Crate Uses
use crate::schema::ir::frozen::unit::FrozenUnit;
// External Uses
use once_cell::sync::Lazy;
pub type VersionGenerators = Lazy<HashMap<&'static str, GeneratorFn>>;
pub type GeneratorFn = fn(&Vec<FrozenUnit>) -> String;
pub type Generator = (GeneratorFn, &'static str);
static LANG_GENERATORS: Lazy<HashMap<&str, (&VersionGenerators, &str)>> = Lazy::new(|| {
HashMap::from([
("rust", (&rust::GENERATORS, "rs")),
("luau", (&luau::GENERATORS, "luau")),
("python", (&python::GENERATORS, "py"))
])
});
pub fn find_generator(name: &str, version: &str) -> Option<(&'static GeneratorFn, &'static str)> {
if let Some((lang_generator, extension)) = LANG_GENERATORS.get(name) {
if let Some(version_generator) = lang_generator.get(version) {
return Some((version_generator, extension))
}
};
None
}