From 9ad253e91652fcb38d916f661e6f4a5e5a1ca415 Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Thu, 11 Jun 2026 20:17:29 +0200 Subject: [PATCH] Fixing --- crates/mist-api/src/modules.mist | 4 +-- crates/mist-api/src/transpiler.mist | 42 +++++++++++++++++++++++------ mist-test/Mist.toml | 3 ++- 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/crates/mist-api/src/modules.mist b/crates/mist-api/src/modules.mist index e107248..ca7c9f0 100644 --- a/crates/mist-api/src/modules.mist +++ b/crates/mist-api/src/modules.mist @@ -28,7 +28,7 @@ pub class Module { } self.scan_directory(&dir, config); - } else if (config.is_package(&self.path)) { + } else if (config.should_ignore(&self.path)) { let dir = self.path.parent().expect("Failed to get parent directory to scan").to_path_buf(); self.scan_directory(&dir, config); @@ -55,7 +55,7 @@ pub class Module { let child_path = entry.path(); - if (child_path == self.path || child_path == config.packages[0]) { + if (child_path == self.path || child_path == config.package) { continue; } diff --git a/crates/mist-api/src/transpiler.mist b/crates/mist-api/src/transpiler.mist index 9c99d9b..7209e1a 100644 --- a/crates/mist-api/src/transpiler.mist +++ b/crates/mist-api/src/transpiler.mist @@ -12,11 +12,18 @@ use mist_codegen::GetRust; use serde::Deserialize; #[derive(Debug, Deserialize)] +#[serde(default)] pub struct MistConfig { + pub package PathBuf, pub packages Vec, + pub main_mods String } impl MistConfig { - pub fn is_package(*self, path *Path) bool { + pub fn should_ignore(*self, path *Path) bool { + if (path == self.package) { + return true; + } + for (pkg : &self.packages) { if (path.ends_with(pkg)) { return true; @@ -26,6 +33,15 @@ impl MistConfig { false } } +impl Default for MistConfig { + fn default() Self { + Self { + package: PathBuf::from("main.mist"), + packages: Vec::new(), + main_mods: String::new(), + } + } +} pub fn transpile() PathBuf { let start = time::Instant::now(); @@ -46,14 +62,14 @@ pub fn transpile() PathBuf { *pkg = src.join(&*pkg); } + config.package = src.join(&*config.package); + let master = modules::Module::new( - config.packages.get(0) - .unwrap_or_else(fn() -> panic!("Mist.toml packages must contain at least one element, eg, 'src/main.mist'")) - .to_path_buf(), + config.package.clone(), &config ); - master.transpile(&out, &config); + master.transpile(&out, &mut config); let elapsed = start.elapsed(); @@ -66,7 +82,7 @@ pub fn transpile() PathBuf { } impl modules::Module { - fn transpile(*self, parent_dir *PathBuf, config *MistConfig) String { + fn transpile(*self, parent_dir *PathBuf, config *mut MistConfig) String { if (!self.path.is_dir() && self.path.extension().and_then(fn(v) -> v.to_str()) != Some("mist")) { let file_name = self.path.file_name() .and_then(fn(s) -> s.to_str()) @@ -85,11 +101,21 @@ impl modules::Module { let mut output = String::new(); for (child : &self.children) { - if (!config.is_package(&child.path)) { + if (!config.should_ignore(&child.path)) { output.push_str(&child.transpile(&dir, config)); } } + if (self.path == config.package) { + config.main_mods = output.clone(); + } else if (config.should_ignore(&self.path)) { + output.push_str(&config.main_mods) + } + + self.write_transpile(output, output_file) + } + + fn write_transpile(*self, output String, output_file PathBuf) String { if (self.path.is_dir()) { if (output.len() == 0) { return String::new(); @@ -184,7 +210,7 @@ fn transpile_file(path *PathBuf, mut output_file PathBuf, mod_decl *str) String process::exit(1); } - format!("{}mod {};", vis.get_rust(), name.get_rust()) + format!("{}mod {};\n", vis.get_rust(), name.get_rust()) } else { let output = gc.generate(parsed.1); diff --git a/mist-test/Mist.toml b/mist-test/Mist.toml index 5c7ad70..c289d2a 100644 --- a/mist-test/Mist.toml +++ b/mist-test/Mist.toml @@ -1 +1,2 @@ -packages = ["main.mist"] \ No newline at end of file +package = "main.mist" +packages = ["yo.mist"] \ No newline at end of file