Yerbacon/src/main.cpp

32 lines
1.3 KiB
C++

#include <iostream>
#include <memory>
using namespace std;
extern string getFileContent(const string& file);
extern void setOutputFileContent(const string& language, const string& file, const string& content);
extern string parseString(unique_ptr<string> toParse);
extern string transpile(const string& toTranspile, string language);
int main(int argc, char* argv[]) {
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;
for (int i = 0; i < argc; i++)
{
currentArg = ((string) argv[i]);
if (currentArg == "-printresult") printResult = true;
else if (currentArg.starts_with("--target=")) target = '.' + currentArg.erase(0, 9);
}
const string parsedString = parseString(make_unique<string>(getFileContent(fileName)));
const string transpiledString = transpile(parsedString, target);
if (printResult) cout << "~~~~[Yerbacon compilation result]~~~~\n\n" << "[WIP]\n" << transpiledString << "\n\n";
setOutputFileContent(target, fileName.erase(fileName.find(".ybcon")) + target, transpiledString);
}
else cout << "No valid file provided.\n";
return EXIT_SUCCESS;
}