use ; use ; use ; pub mod builder; pub mod transpiler; void main() { Vec args = env::args().collect(); if (args.len() < 2) { print_usage(); process::exit(1); } match (args[1].as_str()) { "run" | "build" | "check" | "r" | "b" | "c" => { var root = transpiler::build(false); println!(""); if (builder::build(args, root)) { println!("\x1b[32m\nBuild successful\x1b[0m"); } else { println!("\x1b[31m\nBuild failed\x1b[0m"); } } "transpile" | "t" => { transpiler::build(args.get(2).is_some()); } "init" => { init_project(args); } "version" | "--version" | "-v" => { println!("mist {}", env!("CARGO_PKG_VERSION")); } "help" | "--help" | "-h" => { print_usage(); } unknown => { eprintln!("error: unknown command '{}'\n", unknown); print_usage(); process::exit(1); } } } void print_usage() { println!("Mist - the mist compiler\n"); println!("󰖟 View our documentation! \x1b[35mhttps://mist.selimaj.dev\x1b[0m"); println!(" Follow us on github! \x1b[35mhttps://github.com/mist-go\x1b[0m\n"); println!("usage:"); println!(" \x1b[36m mist run\x1b[0m,\x1b[36m r\x1b[0m run the project in the current directory\n"); println!( " \x1b[36m mist build\x1b[0m,\x1b[36m b\x1b[0m build the project in the current directory\n" ); println!( " \x1b[36m mist transpile\x1b[0m,\x1b[36m t\x1b[0m transpile the project in the current directory\n" ); println!( " \x1b[36m mist check\x1b[0m,\x1b[36m c\x1b[0m check the project in the current directory\n" ); println!( " \x1b[36m mist init\x1b[0m initialize a project in the current folder\n" ); println!(" \x1b[36m mist version \x1b[0m print the compiler version\n"); println!(" \x1b[36m mist help\x1b[0m print this message\n"); } void init_project(Vec mut args) { args.remove(0); new process::Command("cargo") .args(args) .stdout(process::Stdio::inherit()) .stderr(process::Stdio::inherit()) .stdin(process::Stdio::inherit()) .spawn() .expect("Failed to run cargo").wait().expect("Unable to wait"); bool is_lib = fs::metadata("src/lib.rs").is_ok(); if (is_lib) { fs::remove_file("src/lib.rs").expect("Failed to remove src/lib.rs"); fs::write("src/lib.mist", "void test() {\n}").expect("Failed to create src/lib.mist"); } else { fs::remove_file("src/main.rs").expect("Failed to remove src/main.rs"); fs::write("src/main.mist", "void main() {\n println!(\"Hello, World!\");\n}\n").expect("Failed to create src/main.mist"); } inject_mist_target(is_lib); println!("\n\x1b[34minfo\x1b[0m: Please open Cargo.toml and adjust `\x1b[35mname\x1b[0m = ` as needed, Thank you for using Mist!\n"); } void inject_mist_target(bool is_lib) { String toml_content = fs::read_to_string("Cargo.toml").expect("Failed to read Cargo.toml"); str* inject = if (is_lib) { "\n[lib]\nname = \"my_lib\"\npath = \".mist/src/lib.rs\"\n" } else { "\n[[bin]]\nname = \"my_bin\"\npath = \".mist/src/main.rs\"\n" }; fs::write("Cargo.toml", toml_content+inject).expect("Failed to create src/main.mist"); }