diff --git a/src/main.rs b/src/main.rs index 7cafd3f..19c4318 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ mod transpiler; mod parser; mod lexer; mod compile; -use std::{env::set_current_dir, fs}; +use std::fs; use clap::Parser; use lexer::LexerState; use transpiler::Options; diff --git a/src/transpiler.rs b/src/transpiler.rs index a7b6ad0..91f69c6 100644 --- a/src/transpiler.rs +++ b/src/transpiler.rs @@ -23,10 +23,10 @@ fn clean_incl(input: &str) -> String { .collect() } -pub fn transpile_mod(ast: Ast, options: &mut Options) -> String { +pub fn transpile_mod(ast: Ast, options: &mut Options, s: &str) -> String { let modfile = ast.tokens[0].value.as_str(); let modname = format!("{}_{}", clean_incl(modfile.split(".").collect::>()[0]), options.clone().modnum); - let file_content = fs::read_to_string("lib/".to_string()+modfile) + let file_content = fs::read_to_string(s.to_string()+modfile) .expect("Error reading file"); let transpiled_code = transpile(file_content, 0, LexerState { line: 1, column: 0 }, &mut Options::default()); fs::write(("wyst_tmp/".to_string()+modname.as_str())+".rs", @@ -172,7 +172,16 @@ pub fn transpile(input: String, indent: u32, state: LexerState, options: &mut Op } else if ast.ast_type == AstType::StructVar { result += format!("let mut {}: {} = {} {}{}{}", ast.tokens[1].value.as_str(), ast.tokens[0].value.as_str(), ast.tokens[0].value.as_str(), "{", ast.tokens[2].value.as_str(), "}").as_str(); } else if ast.ast_type == AstType::Include { - let modname = transpile_mod(ast, options); + let modname = transpile_mod(ast, options, "/lib"); + result += "mod "; + result += modname.as_str(); + result += ";\n"; + result += "use "; + result += modname.as_str(); + result += "::*;\n"; + options.modnum += 1; + } else if ast.ast_type == AstType::IncludeLocal { + let modname = transpile_mod(ast, options, ""); result += "mod "; result += modname.as_str(); result += ";\n";