error codes and compiler

This commit is contained in:
2024-07-09 12:29:36 +02:00
parent 0137beff70
commit 58af9cdd95
6 changed files with 163 additions and 37 deletions
+29 -18
View File
@@ -1,25 +1,36 @@
use utils::{ProblemCap, Variables};
use std::{fs, process};
mod compiler;
mod parser;
mod transpiler;
mod utils;
use clap::{App, Arg};
use compiler::{compile_rust, transpile};
fn main() {
let mut vars = Variables::new();
let mut trsp = transpiler::Transpiler::default();
let out = trsp.transpile("rust{let mut x;}".to_string(), 0, &mut vars);
for p in trsp.problems {
match p {
ProblemCap::Error(problem) => {
println!(
"\x1b[31;1mError\x1b[0;1m: {}\x1b[0m\n{}:{}: {:?}",
problem.problem_msg,
problem.state.line,
problem.state.column,
problem.problem_type,
)
}
}
}
println!("{out}\n\n\n");
let matches = App::new("Wyst")
.version("0.51")
.author("Leo dev")
.about("The wyst compiler")
.arg(
Arg::with_name("file")
.required(true)
.help("Sets the input file to use"),
)
.arg(
Arg::with_name("output")
.short('o')
.long("output")
.takes_value(true)
.help("Specifies the output executable file name"),
)
.get_matches();
let file = matches.value_of("file").unwrap().to_string();
let output = matches.value_of("output").unwrap_or("out").to_string();
if let Ok(_) = fs::create_dir("build") {}
let ecode = transpile(file, "main.rs".to_string(), true);
compile_rust(output);
fs::remove_dir_all("build").expect("Error removing build");
process::exit(ecode as i32);
}