Overhauled flag system and added compilation
Usage: wyst <file.wst> --flags Flags: (none) -> shows transpiled code -r / --rust <rust_file_name> -> shows transpiled code and turns it into a rust file -c / --compile <exe_name> -> shows transpiled code, creates a temp.rs file, compiles to an exe and deletes the temp.rs file
This commit is contained in:
+37
-5
@@ -1,15 +1,21 @@
|
||||
mod transpiler;
|
||||
mod parser;
|
||||
mod lexer;
|
||||
mod compile;
|
||||
use std::fs;
|
||||
use clap::Parser;
|
||||
|
||||
|
||||
//Arguments for Wyst (short and long version)
|
||||
// Arguments for Wyst (short and long version)
|
||||
#[derive(Parser)]
|
||||
struct Args {
|
||||
#[clap()]
|
||||
file: std::path::PathBuf,
|
||||
|
||||
#[clap(short, long)]
|
||||
file: String,
|
||||
rust: Option<String>,
|
||||
|
||||
#[clap(short, long)]
|
||||
compile: Option<String>,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@@ -18,5 +24,31 @@ fn main() {
|
||||
.expect("Error reading file");
|
||||
|
||||
let transpiled_code = transpiler::transpile(file_content, 0);
|
||||
println!("{}", transpiled_code);
|
||||
}
|
||||
|
||||
match args.rust {
|
||||
Some(ref rust_file_name) => {
|
||||
// Write transpiled code to Rust file
|
||||
compile::write_to_rust_file(&transpiled_code, rust_file_name)
|
||||
.expect("Error writing to Rust file");
|
||||
println!("Transpiled code written to {}", rust_file_name);
|
||||
}
|
||||
None => {
|
||||
// No Rust file specified, print transpiled code
|
||||
println!("{}", transpiled_code);
|
||||
}
|
||||
}
|
||||
|
||||
match args.compile {
|
||||
Some(ref exe_name) => {
|
||||
// Compile transpiled Rust code into executable
|
||||
compile::write_to_rust_file(&transpiled_code, "temp.rs")
|
||||
.expect("Error writing to temporary Rust file");
|
||||
compile::compile_to_executable("temp.rs", exe_name)
|
||||
.expect("Error compiling to executable");
|
||||
fs::remove_file("temp.rs")
|
||||
.expect("Error removing temporary Rust file");
|
||||
println!("Compiled executable: {}", exe_name);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user