From 77e74307767e1dc107a9a5979fa0acc6917bc5cf Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Mon, 22 Jun 2026 02:30:18 +0200 Subject: [PATCH] Update api bootstrap --- crates/mist-api/src/builder.mist | 28 +++++++++---------- crates/mist-api/src/modules.mist | 18 ++++++------ crates/mist-api/src/transpiler.mist | 43 +++++++++++++++-------------- 3 files changed, 45 insertions(+), 44 deletions(-) diff --git a/crates/mist-api/src/builder.mist b/crates/mist-api/src/builder.mist index 990ccd1..4a055aa 100644 --- a/crates/mist-api/src/builder.mist +++ b/crates/mist-api/src/builder.mist @@ -20,12 +20,12 @@ pub struct MistDiagnosticMessage { #[derive(Debug, Clone)] pub enum MistDiagnostic { - Error[MistDiagnosticMessage], - Warning[MistDiagnosticMessage], - Rust[CompilerMessage], + Error(MistDiagnosticMessage), + Warning(MistDiagnosticMessage), + Rust(CompilerMessage), } -pub fn build(mut args Vec, root PathBuf) bool { +pub fn bool build(mut args Vec, root PathBuf) { args.remove(0); args.insert(1, "--message-format=json".to_string()); @@ -45,7 +45,7 @@ pub fn build(mut args Vec, root PathBuf) bool { for message in cargo_metadata::Message::parse_stream(&mut reader) { match message { - Ok[Message::CompilerMessage[msg]] => { + Ok(Message::CompilerMessage(msg)) => { for span in &msg.message.spans { if span.is_primary { let rust_path = root.join(&span.file_name); @@ -65,7 +65,7 @@ pub fn build(mut args Vec, root PathBuf) bool { let mist_file = map.mist_path.strip_prefix(&root); - let [_, rev_mapper::MistMap[line, column]] = + let (_, rev_mapper::MistMap(line, column)) = map.find(&rev_mapper::RustMap(span.line_end, span.column_start)) .expect("Unable to find mapping"); @@ -100,7 +100,7 @@ pub fn build(mut args Vec, root PathBuf) bool { } } - Ok[Message::BuildFinished[finish]] => { + Ok(Message::BuildFinished(finish)) => { print_diagnostics(&diagnostics); let mut raw_reader = reader.into_inner(); @@ -115,7 +115,7 @@ pub fn build(mut args Vec, root PathBuf) bool { return finish.success; } - Ok[Message::TextLine[text]] => println!("{text}"); + Ok(Message::TextLine(text)) => println!("{text}"); _ => {} } } @@ -123,12 +123,12 @@ pub fn build(mut args Vec, root PathBuf) bool { false } -pub fn print_diagnostics(diagnostics *Vec) { +pub fn void print_diagnostics(diagnostics *Vec) { let mut files = HashMap::new(); for diag in diagnostics { match diag { - MistDiagnostic::Error[msg] => { + MistDiagnostic::Error(msg) => { let line = get_line(&mut files, &msg); println!( @@ -141,7 +141,7 @@ pub fn print_diagnostics(diagnostics *Vec) { ) } - MistDiagnostic::Warning[msg] => { + MistDiagnostic::Warning(msg) => { let line = get_line(&mut files, &msg); println!( @@ -154,15 +154,15 @@ pub fn print_diagnostics(diagnostics *Vec) { ) } - MistDiagnostic::Rust[rs] => println!("{rs}"); + MistDiagnostic::Rust(rs) => println!("{rs}"); } } } -pub fn get_line( +pub fn Option get_line( files *mut HashMap>, msg *MistDiagnosticMessage, -) Option { +) { let src_path = msg.file_path.clone(); let lines = files.entry(src_path.clone()).or_insert_with(fn() { diff --git a/crates/mist-api/src/modules.mist b/crates/mist-api/src/modules.mist index ea1c3c4..6754844 100644 --- a/crates/mist-api/src/modules.mist +++ b/crates/mist-api/src/modules.mist @@ -37,10 +37,10 @@ pub class Module { } } - fn scan_directory(*mut self, search_dir *Path, config *MistConfig) { + fn void scan_directory(*mut self, search_dir *Path, config *MistConfig) { let entries = match fs::read_dir(search_dir) { - Ok[entries] => entries; - Err[e] => { + Ok(entries) => entries; + Err(e) => { eprintln!("error: failed to read directory {}\n {}", search_dir.display(), e); process::exit(1); } @@ -48,8 +48,8 @@ pub class Module { for entry in entries { let entry = match entry { - Ok[entry] => entry; - Err[e] => { + Ok(entry) => entry; + Err(e) => { eprintln!("error: failed to read directory entry\n {}", e); process::exit(1); } @@ -65,11 +65,11 @@ pub class Module { } } - pub fn is_package(*self) bool { + pub fn bool is_package(*self) { self.path.file_name().map(fn(v) -> v.to_str()).unwrap_or_default() == Some("package.mist") } - pub fn output_dir(*self, parent_dir *PathBuf) PathBuf { + pub fn PathBuf output_dir(*self, parent_dir *PathBuf) { if self.path.is_dir() || self.is_package() { parent_dir.join(&self.name) } else { @@ -77,8 +77,8 @@ pub class Module { } } - pub fn output_path(*self, parent_dir *PathBuf, curr_mod_decl *Option<[mist_parser::ast::Visibility, mist_parser::ast::Identifier]>) PathBuf { - let name = if let Some[[_, name]] = curr_mod_decl { + pub fn PathBuf output_path(*self, parent_dir *PathBuf, curr_mod_decl *Option<(mist_parser::ast::Visibility, mist_parser::ast::Identifier)>) { + let name = if let Some((_, name)) = curr_mod_decl { &name.0 } else { &self.name diff --git a/crates/mist-api/src/transpiler.mist b/crates/mist-api/src/transpiler.mist index f7001ea..097a25f 100644 --- a/crates/mist-api/src/transpiler.mist +++ b/crates/mist-api/src/transpiler.mist @@ -20,8 +20,9 @@ pub struct MistConfig { pub packages Vec, pub main_mods String } + impl MistConfig { - pub fn should_ignore(*self, path *Path) bool { + pub fn bool should_ignore(*self, path *Path) { if path == self.package { return true; } @@ -36,7 +37,7 @@ impl MistConfig { } } impl Default for MistConfig { - fn default() Self { + fn Self default() { Self { package: PathBuf::from("main.mist"), packages: Vec::new(), @@ -45,7 +46,7 @@ impl Default for MistConfig { } } -pub fn transpile() PathBuf { +pub fn PathBuf transpile() { let start = time::Instant::now(); let root = env::current_dir().expect("Unable to find project root"); @@ -84,7 +85,7 @@ pub fn transpile() PathBuf { } impl modules::Module { - fn transpile(*self, parent_dir *PathBuf, config *mut MistConfig) [bool, String] { + fn (bool, String) transpile(*self, parent_dir *PathBuf, config *mut MistConfig) { 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()) @@ -123,7 +124,7 @@ impl modules::Module { self.write_transpile(output, parent_dir, child_changed) } - fn write_transpile(*self, output String, parent_dir *PathBuf, child_changed bool) [bool, String] { + fn (bool, String) write_transpile(*self, output String, parent_dir *PathBuf, child_changed bool) { if self.path.is_dir() { let output_file = self.output_path(parent_dir, &None); @@ -146,8 +147,8 @@ impl modules::Module { (false, format!("pub mod {};\n", self.name)) } else { let source = match fs::read_to_string(&self.path) { - Ok[s] => s; - Err[e] => { + Ok(s) => s; + Err(e) => { eprintln!("error: failed to read file {}\n {}", self.path.display(), e); process::exit(1); @@ -173,7 +174,7 @@ impl modules::Module { } } -fn is_source_newer(source *Path, output *Path) std::io::Result { +fn std::io::Result is_source_newer(source *Path, output *Path) { if !output.exists() { return Ok(true); } @@ -185,12 +186,12 @@ fn is_source_newer(source *Path, output *Path) std::io::Result { } pub enum TranspileError<'a> { - Parse[error::ParseError<'a, Vec>], - Semantic[Vec] + Parse(error::ParseError<'a, Vec>), + Semantic(Vec) } -pub fn transpile_code<'a>(path *PathBuf, source *'a str, mut output_file PathBuf, mod_decl *str, curr_mod_decl *Option<[mist_parser::ast::Visibility, mist_parser::ast::Identifier]>) - Result<[PathBuf, mist_codegen::RustCodegen, String], TranspileError<'a>> { +pub fn Result<(PathBuf, mist_codegen::RustCodegen, String), TranspileError<'a>> + transpile_code<'a>(path *PathBuf, source *'a str, mut output_file PathBuf, mod_decl *str, curr_mod_decl *Option<(mist_parser::ast::Visibility, mist_parser::ast::Identifier)>) { if let Some[[_, name]] = &curr_mod_decl { if output_file.file_name().map(fn(v) -> v.to_str()).unwrap_or_default() != Some("mod.rs") { @@ -222,10 +223,10 @@ pub fn transpile_code<'a>(path *PathBuf, source *'a str, mut output_file PathBuf Ok((output_file, gc, output)) } -pub fn transpile_file(path *PathBuf, source *str, output_file PathBuf, mod_decl *str, curr_mod_decl *Option<[mist_parser::ast::Visibility, mist_parser::ast::Identifier]>) { - let [output_file, gc, output] = match transpile_code(path, source, output_file, mod_decl, curr_mod_decl) { - Ok[output] => output; - Err[e] => { +pub fn void transpile_file(path *PathBuf, source *str, output_file PathBuf, mod_decl *str, curr_mod_decl *Option<(mist_parser::ast::Visibility, mist_parser::ast::Identifier)>) { + let (output_file, gc, output) = match transpile_code(path, source, output_file, mod_decl, curr_mod_decl) { + Ok(output) => output; + Err(e) => { decode_err(&e, path); process::exit(1); } @@ -258,11 +259,11 @@ pub fn transpile_file(path *PathBuf, source *str, output_file PathBuf, mod_decl } } -pub fn decode_err<'a>(err *TranspileError<'a>, path *PathBuf) { +pub fn void decode_err<'a>(err *TranspileError<'a>, path *PathBuf) { let curr_dir = std::env::current_dir().unwrap(); match err { - TranspileError::Semantic[e_list] => { + TranspileError::Semantic(e_list) => { for e in e_list { eprintln!( "\n{}:{}:{}\n \x1b[31mError\x1b[0m: {}", @@ -274,9 +275,9 @@ pub fn decode_err<'a>(err *TranspileError<'a>, path *PathBuf) { } } - TranspileError::Parse[e] => { + TranspileError::Parse(e) => { match e { - error::ParseError::Ast[e] => { + error::ParseError::Ast(e) => { let start_pos = e.span.start_pos().line_col(); let span = e.span.as_str(); @@ -293,7 +294,7 @@ pub fn decode_err<'a>(err *TranspileError<'a>, path *PathBuf) { ); } - error::ParseError::PreAst[e] => { + error::ParseError::PreAst(e) => { eprintln!("error: parse failed in {}\n{}", path.strip_prefix(curr_dir).unwrap_or_else(|_| path).display(), e); } }