Add support for multiple input files
This commit is contained in:
parent
a75cbeb129
commit
c5d33fd480
|
@ -4,20 +4,20 @@ using namespace std;
|
||||||
|
|
||||||
string getFileContent(const string& file)
|
string getFileContent(const string& file)
|
||||||
{
|
{
|
||||||
ifstream filetoParse;
|
ifstream fileStream;
|
||||||
string lineinput, fullinput;
|
string lineinput, fullinput;
|
||||||
filetoParse.open(file, ios::in);
|
fileStream.open(file, ios::in);
|
||||||
if (filetoParse.is_open()) while (getline(filetoParse, lineinput)) {
|
if (fileStream.is_open()) while (getline(fileStream, lineinput)) {
|
||||||
fullinput.append(lineinput + "\n");
|
fullinput.append(lineinput + "\n");
|
||||||
} else {
|
} else {
|
||||||
cout << "Could not open the file(s)." << endl;
|
cout << "Could not open \"" << file << "\"." << endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
filetoParse.close();
|
fileStream.close();
|
||||||
return fullinput;
|
return fullinput;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setOutputFileContent(const string& file, string_view content) {
|
void outputFileContent(const string& file, const string_view content) {
|
||||||
static ofstream outputFile (file, ofstream::out);
|
ofstream outputFile (file, ofstream::out);
|
||||||
outputFile << content;
|
outputFile << content;
|
||||||
}
|
}
|
|
@ -8,7 +8,7 @@
|
||||||
consteval const char* getVersion() noexcept { return YBCON_VERSION; }
|
consteval const char* getVersion() noexcept { return YBCON_VERSION; }
|
||||||
|
|
||||||
string getFileContent(const string& file);
|
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"
|
#include "src/headers/parsing/ParseComponents.hpp"
|
||||||
ParseTree parseString(const string& toParse);
|
ParseTree parseString(const string& toParse);
|
||||||
|
|
29
src/main.cpp
29
src/main.cpp
|
@ -1,26 +1,35 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <set>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#include "headers/misc.hpp"
|
#include "headers/misc.hpp"
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
if ((argc == 2) && (((string) argv[1]) == "--version")) { cout << getVersion() << endl; exit(EXIT_SUCCESS); }
|
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 target = ".lua";
|
||||||
string currentArg;
|
string_view currentArg;
|
||||||
|
bool printResult = false;
|
||||||
|
if (argc > 0) {
|
||||||
|
vector<string_view> files;
|
||||||
for (signed int i = 0; i < argc; ++i)
|
for (signed int i = 0; i < argc; ++i)
|
||||||
{
|
{
|
||||||
currentArg = static_cast<string>(argv[i]);
|
currentArg = static_cast<string_view>(argv[i]);
|
||||||
if ((currentArg == "--printresult") || (currentArg == "-p")) printResult = true;
|
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;
|
||||||
}
|
}
|
||||||
const string transpiledString = transpile(parseString(getFileContent(fileName)), target);
|
else files.push_back(currentArg);
|
||||||
|
}
|
||||||
|
const set<string_view> 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";
|
if (printResult) cout << "~~~~[Yerbacon compilation result]~~~~\n\n" << "[WIP]\n" << transpiledString << "\n\n";
|
||||||
setOutputFileContent(fileName.erase(fileName.find(".ybcon")) + target, transpiledString);
|
fileName.remove_suffix(6);
|
||||||
|
outputFileContent(target.insert(0, fileName), transpiledString);
|
||||||
}
|
}
|
||||||
else cout << "No valid file provided.\n";
|
}
|
||||||
|
} else cout << "No valid file provided.\n";
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ using namespace std;
|
||||||
|
|
||||||
enum LANGUAGE: unsigned short {LUA=0,JS=1,PY=2};
|
enum LANGUAGE: unsigned short {LUA=0,JS=1,PY=2};
|
||||||
|
|
||||||
pair<LANGUAGE, bool> validLanguage(const string& it) {
|
pair<LANGUAGE, bool> validLanguage(const string_view& it) {
|
||||||
static const string_view languages[3] = {".lua", ".js", ".py"};
|
static const string_view languages[3] = {".lua", ".js", ".py"};
|
||||||
LANGUAGE selected = LUA;
|
LANGUAGE selected = LUA;
|
||||||
bool valid = false;
|
bool valid = false;
|
||||||
|
|
Loading…
Reference in New Issue