diff --git a/src/etc/filefuncs.cpp b/src/etc/filefuncs.cpp index 2457a7b..a5779bc 100644 --- a/src/etc/filefuncs.cpp +++ b/src/etc/filefuncs.cpp @@ -4,20 +4,20 @@ using namespace std; string getFileContent(const string& file) { - ifstream filetoParse; + ifstream fileStream; string lineinput, fullinput; - filetoParse.open(file, ios::in); - if (filetoParse.is_open()) while (getline(filetoParse, lineinput)) { + fileStream.open(file, ios::in); + if (fileStream.is_open()) while (getline(fileStream, lineinput)) { fullinput.append(lineinput + "\n"); } else { - cout << "Could not open the file(s)." << endl; + cout << "Could not open \"" << file << "\"." << endl; exit(EXIT_FAILURE); } - filetoParse.close(); + fileStream.close(); return fullinput; } -void setOutputFileContent(const string& file, string_view content) { - static ofstream outputFile (file, ofstream::out); +void outputFileContent(const string& file, const string_view content) { + ofstream outputFile (file, ofstream::out); outputFile << content; } \ No newline at end of file diff --git a/src/headers/misc.hpp b/src/headers/misc.hpp index fb5d1d9..d1ff6d7 100644 --- a/src/headers/misc.hpp +++ b/src/headers/misc.hpp @@ -8,7 +8,7 @@ consteval const char* getVersion() noexcept { return YBCON_VERSION; } string getFileContent(const string& file); -void setOutputFileContent(const string& file, string_view content); +void outputFileContent(const string& file, string_view content); #include "src/headers/parsing/ParseComponents.hpp" ParseTree parseString(const string& toParse); diff --git a/src/main.cpp b/src/main.cpp index c9512bf..a7d15d6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,26 +1,35 @@ #include +#include using namespace std; #include "headers/misc.hpp" int main(int argc, char* argv[]) { if ((argc == 2) && (((string) argv[1]) == "--version")) { cout << getVersion() << endl; exit(EXIT_SUCCESS); } - string fileName = (argv[argc - 1] != nullptr) ? argv[argc - 1] : "none" ; - if (fileName != "none" and fileName.ends_with(".ybcon")) - { - bool printResult = false; - string target = ".lua"; - string currentArg; + string target = ".lua"; + string_view currentArg; + bool printResult = false; + if (argc > 0) { + vector files; for (signed int i = 0; i < argc; ++i) { - currentArg = static_cast(argv[i]); + currentArg = static_cast(argv[i]); if ((currentArg == "--printresult") || (currentArg == "-p")) printResult = true; - else if (currentArg.starts_with("--target=")) target = '.' + currentArg.erase(0, 9); + else if (currentArg.starts_with("--target=")) { + currentArg.remove_prefix(9); + target = currentArg; + } + else files.push_back(currentArg); } - const string transpiledString = transpile(parseString(getFileContent(fileName)), target); - if (printResult) cout << "~~~~[Yerbacon compilation result]~~~~\n\n" << "[WIP]\n" << transpiledString << "\n\n"; - setOutputFileContent(fileName.erase(fileName.find(".ybcon")) + target, transpiledString); - } - else cout << "No valid file provided.\n"; + const set uniqueFiles(files.begin(), files.end()); + for (string_view fileName: uniqueFiles) { + if (fileName != "none" and fileName.ends_with(".ybcon")) { + const string transpiledString = transpile(parseString(getFileContent(fileName.data())), target); + if (printResult) cout << "~~~~[Yerbacon compilation result]~~~~\n\n" << "[WIP]\n" << transpiledString << "\n\n"; + fileName.remove_suffix(6); + outputFileContent(target.insert(0, fileName), transpiledString); + } + } + } else cout << "No valid file provided.\n"; return EXIT_SUCCESS; } diff --git a/src/transpiler/MainTranspile.cpp b/src/transpiler/MainTranspile.cpp index 1121036..ebd1bd2 100644 --- a/src/transpiler/MainTranspile.cpp +++ b/src/transpiler/MainTranspile.cpp @@ -4,7 +4,7 @@ using namespace std; enum LANGUAGE: unsigned short {LUA=0,JS=1,PY=2}; -pair validLanguage(const string& it) { +pair validLanguage(const string_view& it) { static const string_view languages[3] = {".lua", ".js", ".py"}; LANGUAGE selected = LUA; bool valid = false;