fixed bugs
This commit is contained in:
+7
-1
@@ -1,4 +1,5 @@
|
||||
use std::{fs, path::Path, process::Command};
|
||||
use std::str;
|
||||
|
||||
use crate::{
|
||||
transpiler::{State, Transpiler},
|
||||
@@ -65,10 +66,15 @@ pub fn transpile(input_file: String, output_file: String, is_main: bool) -> u8 {
|
||||
}
|
||||
|
||||
pub fn compile_rust(exe_file: String) {
|
||||
Command::new("rustc")
|
||||
let output = Command::new("rustc")
|
||||
.arg(Path::new("build").join("main.rs"))
|
||||
.arg("-o")
|
||||
.arg(exe_file)
|
||||
.output()
|
||||
.expect("Error compiling rust: ");
|
||||
if &output.stderr.len() == &0 {
|
||||
println!("Compiled successfully");
|
||||
} else {
|
||||
println!("{}", str::from_utf8(&output.stderr).expect("Error encoding stderr"));
|
||||
}
|
||||
}
|
||||
|
||||
+18
-3
@@ -75,9 +75,9 @@ impl Transpiler {
|
||||
let tokens = to_indexable(pair.clone().into_inner());
|
||||
match pair.as_rule() {
|
||||
Rule::func_def => {
|
||||
res += format!("fn {}({}) -> {} {}", tokens[1].as_str(),
|
||||
res += format!("fn {}({}) -> {} {}", self.transpile(tokens[1].clone()),
|
||||
self.transpile_pairs(tokens[2].clone().into_inner()).as_str(),
|
||||
tokens[0].as_str(),
|
||||
self.transpile(tokens[0].clone()),
|
||||
self.transpile(tokens[3].clone())
|
||||
).as_str();
|
||||
}
|
||||
@@ -96,6 +96,22 @@ impl Transpiler {
|
||||
Rule::include_global => {}
|
||||
Rule::include => {}
|
||||
|
||||
Rule::identifier => {
|
||||
let ident = pair.as_str().trim();
|
||||
res+=match ident {
|
||||
"void" => {"()"}
|
||||
_ => {ident}
|
||||
};
|
||||
}
|
||||
|
||||
Rule::def_identifier => {
|
||||
let ident = pair.as_str().trim();
|
||||
res+=match ident {
|
||||
"void" => {"()"}
|
||||
_ => {ident}
|
||||
};
|
||||
}
|
||||
|
||||
_ => {
|
||||
res += " ";
|
||||
res += pair.as_str();
|
||||
@@ -113,7 +129,6 @@ impl Transpiler {
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
// println!("err: {}", e.line());
|
||||
println!("{}", e);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -57,5 +57,5 @@ top_expr = {
|
||||
include |
|
||||
include_global |
|
||||
func_def
|
||||
)+
|
||||
)* ~ !ANY
|
||||
}
|
||||
Reference in New Issue
Block a user