diff --git a/src/compiler.rs b/src/compiler.rs index 510e5a7..d1d0945 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -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")); + } } diff --git a/src/transpiler.rs b/src/transpiler.rs index 9d1c307..687552f 100644 --- a/src/transpiler.rs +++ b/src/transpiler.rs @@ -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); } } diff --git a/src/wyst.pest b/src/wyst.pest index b910e59..6e1ddea 100644 --- a/src/wyst.pest +++ b/src/wyst.pest @@ -57,5 +57,5 @@ top_expr = { include | include_global | func_def - )+ + )* ~ !ANY } \ No newline at end of file