var on parser

This commit is contained in:
2024-06-04 14:35:34 +02:00
parent 15ff863fbe
commit 5c367e6b44
5 changed files with 376 additions and 435 deletions
+12 -11
View File
@@ -1,11 +1,10 @@
mod transpiler;
mod parser;
mod lexer;
mod compile;
mod lexer;
mod lsp;
use std::{fs, path::Path};
mod parser;
mod transpiler;
use clap::Parser;
use lexer::LexerState;
use std::{fs, path::Path};
use transpiler::Transpiler;
use crate::lsp::run_lsp_server;
@@ -28,22 +27,24 @@ fn main() {
match args.stdio {
true => {
run_lsp_server();
},
}
false => {
let file_content = fs::read_to_string("main.wt")
.expect("Error reading file");
let file_content = fs::read_to_string("main.wt").expect("Error reading file");
if Path::new("build").exists() {
fs::remove_dir_all("build").expect("err rm build");
}
fs::create_dir("build").expect("error making build");
let mut trsp = Transpiler::default();
let transpiled_code = trsp.transpile(file_content, 0, LexerState { line: 1, column: 0 });
let transpiled_code = trsp.transpile(file_content, 0);
match args.rust {
Some(ref rust_file_name) => {
// Write transpiled code to Rust file
compile::write_to_rust_file(&transpiled_code, ("build/".to_string()+rust_file_name).as_str())
.expect("Error writing to Rust file");
compile::write_to_rust_file(
&transpiled_code,
("build/".to_string() + rust_file_name).as_str(),
)
.expect("Error writing to Rust file");
println!("Transpiled code written to {}", rust_file_name);
}
None => {