From 919447875a185291fde47486862131fc6df8c2b6 Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Fri, 12 Jun 2026 19:17:34 +0200 Subject: [PATCH] Update api bootstrap --- crates/mist-api/src/builder.mist | 21 ++++++++------- crates/mist-api/src/lib.mist | 3 --- crates/mist-api/src/modules.mist | 22 ++++++++------- crates/mist-api/src/transpiler.mist | 42 +++++++++++++++-------------- 4 files changed, 46 insertions(+), 42 deletions(-) diff --git a/crates/mist-api/src/builder.mist b/crates/mist-api/src/builder.mist index 95f15da..dd94ee7 100644 --- a/crates/mist-api/src/builder.mist +++ b/crates/mist-api/src/builder.mist @@ -1,3 +1,5 @@ +pub module builder; + use std::collections::HashMap; use std::env; use std::fs; @@ -47,11 +49,11 @@ pub fn build(mut args Vec, root PathBuf) bool { let mist_src = format!(".mist{MAIN_SEPARATOR}src"); - for (message : cargo_metadata::Message::parse_stream(&mut reader)) { - match (message) { + for message in cargo_metadata::Message::parse_stream(&mut reader) { + match message { Ok[Message::CompilerMessage[msg]] => { - for (span : &msg.message.spans) { - if (span.is_primary) { + for span in &msg.message.spans { + if span.is_primary { let rust_path = root.join(&span.file_name); let mist_file = span @@ -63,7 +65,7 @@ pub fn build(mut args Vec, root PathBuf) bool { let mist_path = root.join(&mist_file); - if (!fs::exists(&mist_path).expect("Unable to check if mist file exists")) { + if !fs::exists(&mist_path).expect("Unable to check if mist file exists") { diagnostics.push(MistDiagnostic::Rust(msg)); break; } @@ -85,7 +87,8 @@ pub fn build(mut args Vec, root PathBuf) bool { msg.message.message, span.label.clone().unwrap_or_default() ), - file_name: if (is_root) { + file_name: if is_root { + (); // TODO: fix this mist_file } else { mist_path.to_string_lossy().to_string() @@ -95,7 +98,7 @@ pub fn build(mut args Vec, root PathBuf) bool { column: column }; - match (msg.message.level) { + match msg.message.level { cargo_metadata::diagnostic::DiagnosticLevel::Error => { diagnostics.push(MistDiagnostic::Error(mist_msg)) } @@ -136,8 +139,8 @@ pub fn build(mut args Vec, root PathBuf) bool { pub fn print_diagnostics(diagnostics *Vec) { let mut files = HashMap::new(); - for (diag : diagnostics) { - match (diag) { + for diag in diagnostics { + match diag { MistDiagnostic::Error[msg] => { let line = get_line(&mut files, &msg); diff --git a/crates/mist-api/src/lib.mist b/crates/mist-api/src/lib.mist index ac42ad7..e69de29 100644 --- a/crates/mist-api/src/lib.mist +++ b/crates/mist-api/src/lib.mist @@ -1,3 +0,0 @@ -pub mod builder; -pub mod transpiler; -pub mod modules; \ No newline at end of file diff --git a/crates/mist-api/src/modules.mist b/crates/mist-api/src/modules.mist index 70ce4c4..a6ad128 100644 --- a/crates/mist-api/src/modules.mist +++ b/crates/mist-api/src/modules.mist @@ -1,3 +1,5 @@ +pub module modules; + use std::path::Path; use std::path::PathBuf; use std::fs; @@ -9,7 +11,7 @@ use crate::transpiler::MistConfig; pub class Module { pub name String; pub path PathBuf; - pub children Vec>; + pub children Vec; pub constructor(mist_path PathBuf, config *MistConfig) { self.children = Vec::new(); @@ -19,16 +21,16 @@ pub class Module { .to_string(); self.path = mist_path; - if (self.path.is_dir()) { + if self.path.is_dir() { let dir = self.path.clone(); let pkg_gate = self.path.join("package.mist"); - if (pkg_gate.exists()) { + if pkg_gate.exists() { self.path = pkg_gate; } self.scan_directory(&dir, config); - } else if (config.should_ignore(&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); @@ -36,7 +38,7 @@ pub class Module { } fn scan_directory(*mut self, search_dir *Path, config *MistConfig) { - let entries = match (fs::read_dir(search_dir)) { + let entries = match fs::read_dir(search_dir) { Ok[entries] => entries; Err[e] => { eprintln!("error: failed to read directory {}\n {}", search_dir.display(), e); @@ -44,8 +46,8 @@ pub class Module { } }; - for (entry : entries) { - let entry = match (entry) { + for entry in entries { + let entry = match entry { Ok[entry] => entry; Err[e] => { eprintln!("error: failed to read directory entry\n {}", e); @@ -55,7 +57,7 @@ pub class Module { let child_path = entry.path(); - if (child_path == self.path || child_path == config.package) { + if child_path == self.path || child_path == config.package { continue; } @@ -68,7 +70,7 @@ pub class Module { } pub fn output_dir(*self, parent_dir *PathBuf) PathBuf { - if (self.path.is_dir() || self.is_package()) { + if self.path.is_dir() || self.is_package() { parent_dir.join(&self.name) } else { parent_dir.clone() @@ -76,7 +78,7 @@ pub class Module { } pub fn output_path(*self, parent_dir *PathBuf) PathBuf { - if (self.path.is_dir() || self.is_package()) { + if self.path.is_dir() || self.is_package() { parent_dir.join(&self.name).join("mod.rs") } else { parent_dir.join(&self.name).with_extension("rs") diff --git a/crates/mist-api/src/transpiler.mist b/crates/mist-api/src/transpiler.mist index 82f497b..37551fa 100644 --- a/crates/mist-api/src/transpiler.mist +++ b/crates/mist-api/src/transpiler.mist @@ -1,3 +1,5 @@ +pub module transpiler; + use std::fs; use std::path::Path; use std::path::PathBuf; @@ -20,12 +22,12 @@ pub struct MistConfig { } impl MistConfig { pub fn should_ignore(*self, path *Path) bool { - if (path == self.package) { + if path == self.package { return true; } - for (pkg : &self.packages) { - if (path.ends_with(pkg)) { + for pkg in &self.packages { + if path.ends_with(pkg) { return true; } } @@ -58,7 +60,7 @@ pub fn transpile() PathBuf { 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) { + for pkg in &mut config.packages { *pkg = src.join(&*pkg); } @@ -83,7 +85,7 @@ pub fn transpile() PathBuf { impl modules::Module { 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")) { + 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()) .expect("Failed to get file name"); @@ -100,15 +102,15 @@ impl modules::Module { let mut output = String::new(); - for (child : &self.children) { - if (!config.should_ignore(&child.path)) { + for child in &self.children { + if !config.should_ignore(&child.path) { output.push_str(&child.transpile(&dir, config)); } } - if (self.path == config.package) { + if self.path == config.package { config.main_mods = output.clone(); - } else if (config.should_ignore(&self.path)) { + } else if config.should_ignore(&self.path) { output.push_str(&config.main_mods) } @@ -116,14 +118,14 @@ impl modules::Module { } fn write_transpile(*self, output String, output_file PathBuf) String { - if (self.path.is_dir()) { - if (output.len() == 0) { + if self.path.is_dir() { + if output.len() == 0 { return String::new(); } let res = fs::write(&output_file, output); - if (res.is_err()) { + if res.is_err() { eprintln!( "error: failed to write output {}\n {}", output_file.display(), @@ -141,7 +143,7 @@ impl modules::Module { } fn transpile_file(path *PathBuf, mut output_file PathBuf, mod_decl *str) String { - let source = match (fs::read_to_string(&path)) { + let source = match fs::read_to_string(&path) { Ok[s] => s; Err[e] => { eprintln!("error: failed to read file {}\n {}", path.display(), e); @@ -152,10 +154,10 @@ fn transpile_file(path *PathBuf, mut output_file PathBuf, mod_decl *str) String let mut gc = mist_codegen::RustCodegen::new(); - let parsed = match (mist_parser::parse(&source)) { + let parsed = match mist_parser::parse(&source) { Ok[ast] => ast; Err[e] => { - match (e) { + match e { error::ParseError::Ast[e] => { let start_pos = e.span.start_pos().line_col(); @@ -186,9 +188,9 @@ fn transpile_file(path *PathBuf, mut output_file PathBuf, mod_decl *str) String let output = gc.generate(parsed.1); - if (let [Some[[vis, name]], _] = parsed) { - if (output_file.file_name().map(fn(v) -> v.to_str()).unwrap_or_default() != Some("mod.rs")) { - if (let Some[ext] = output_file.extension().map(fn(e) -> e.to_owned())) { + if let [Some[[vis, name]], _] = parsed { + if output_file.file_name().map(fn(v) -> v.to_str()).unwrap_or_default() != Some("mod.rs") { + if let Some[ext] = output_file.extension().map(fn(e) -> e.to_owned()) { let mut new_name = std::ffi::OsString::from(&name.0); new_name.push("."); @@ -202,7 +204,7 @@ fn transpile_file(path *PathBuf, mut output_file PathBuf, mod_decl *str) String let res = fs::write(&output_file, format!("{mod_decl}{output}")); - if (res.is_err()) { + if res.is_err() { eprintln!( "error: failed to write output {}\n {}", output_file.display(), @@ -216,7 +218,7 @@ fn transpile_file(path *PathBuf, mut output_file PathBuf, mod_decl *str) String } else { let res = fs::write(&output_file, format!("{mod_decl}{output}")); - if (res.is_err()) { + if res.is_err() { eprintln!( "error: failed to write output {}\n {}", output_file.display(),