53 lines
2.3 KiB
C++
53 lines
2.3 KiB
C++
#include <iostream>
|
|
#include <set>
|
|
#include <future>
|
|
#include <sstream>
|
|
using namespace std;
|
|
|
|
#include "headers/misc.hpp"
|
|
#include "headers/Yerbacon.hpp"
|
|
|
|
int main(int argc, char* argv[]) {
|
|
if ((argc == 2) && (((string) argv[1]) == "--version")) { cout << Yerbacon::getVersion() << endl; exit(EXIT_SUCCESS); }
|
|
string target = ".lua";
|
|
string_view currentArg;
|
|
bool printResult = false;
|
|
bool parallel = false;
|
|
if (argc > 0) {
|
|
vector<string_view> files;
|
|
for (signed int i = 0; i < argc; ++i)
|
|
{
|
|
currentArg = static_cast<string_view>(argv[i]);
|
|
if ((currentArg == "--printresult") || (currentArg == "-p")) printResult = true;
|
|
else if (currentArg.starts_with("--target=")) {
|
|
currentArg.remove_prefix(9);
|
|
(target = '.') += currentArg;
|
|
}
|
|
else if (currentArg == "--parallel") parallel = true;
|
|
else if (currentArg.ends_with(".ybcon")) files.push_back(currentArg);
|
|
}
|
|
if (!files.empty()) {
|
|
const set<string_view> uniqueFiles(files.begin(), files.end());
|
|
vector<future<string>> Units;
|
|
for (string_view fileName: uniqueFiles) {
|
|
if (fileName != "none") {
|
|
const launch Policy = !parallel ? launch::deferred : launch::async;
|
|
future<string> newAsync = async(Policy, [printResult, fileName, target]() mutable {
|
|
const string transpiledString = transpile(parseString(getFileContent(fileName.data())), target);
|
|
stringstream consoleOutput;
|
|
if (printResult) consoleOutput << "~~~~[Yerbacon compilation result]~~~~\n\n" << "[WIP]\n" << transpiledString << "\n\n";
|
|
fileName.remove_suffix(6);
|
|
string outputFile;
|
|
(outputFile = fileName).append(target);
|
|
outputFileContent(outputFile, transpiledString);
|
|
return consoleOutput.str();
|
|
});
|
|
Units.push_back(move(newAsync));
|
|
}
|
|
}
|
|
for (auto& currentFuture: Units) cout << currentFuture.get();
|
|
} else cout << "No valid file provided.\n";
|
|
}
|
|
return EXIT_SUCCESS;
|
|
}
|