Mist.toml support

This commit is contained in:
2026-06-11 19:06:07 +02:00
parent c37392046a
commit 74d53fff97
5 changed files with 120 additions and 31 deletions
+39 -5
View File
@@ -1,4 +1,5 @@
use std::fs;
use std::path::Path;
use std::path::PathBuf;
use std::process;
use std::time;
@@ -8,20 +9,53 @@ use mist_parser::error;
use crate::modules;
use mist_codegen::GetRust;
use serde::Deserialize;
#[derive(Debug, Deserialize)]
pub struct MistConfig {
packages Vec<PathBuf>,
}
impl MistConfig {
pub fn is_package(*self, path *Path) bool {
for (pkg : &self.packages) {
if (path.ends_with(pkg)) {
return true;
}
}
false
}
}
pub fn transpile() PathBuf {
let start = time::Instant::now();
let root = env::current_dir().expect("Unable to find project root");
let toml_path = root.join("Mist.toml");
let src = root.join("src");
let out = root.join(".mist/src");
let master = modules::master_package(src.join("main.mist"));
let toml_content = fs::read_to_string(&toml_path)
.unwrap_or_else(fn(_) -> panic!("Could not read file at {:?}", toml_path));
master.transpile(&out);
let mut config MistConfig = toml::from_str(&toml_content)
.unwrap_or_else(fn(_) -> panic!("Failed to parse Mist.toml from {:?}", toml_path));
for (pkg : &mut config.packages) {
*pkg = src.join(&*pkg);
}
let master = modules::master_package(
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()
);
master.transpile(&out, &config);
let elapsed = start.elapsed();
println!(
"\x1b[32m\nTranspile successful\x1b[0m in \x1b[34m{:.2?}\x1b[0m",
elapsed
@@ -31,7 +65,7 @@ pub fn transpile() PathBuf {
}
impl modules::Module {
fn transpile(*self, parent_dir *PathBuf) String {
fn transpile(*self, parent_dir *PathBuf, config *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())
@@ -50,7 +84,7 @@ impl modules::Module {
let mut output = String::new();
for (child : &self.children) {
output.push_str(&child.transpile(&dir));
output.push_str(&child.transpile(&dir, config));
}
if (self.path.is_dir()) {