Re-add the newlinesoff argument

This commit is contained in:
Username404 2021-09-11 11:49:57 +02:00
parent bfa8f50ad9
commit 96bd6bf708
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
6 changed files with 16 additions and 10 deletions

View File

@ -22,7 +22,7 @@ struct tok {
const type toktype; const type toktype;
const std::string toktext; const std::string toktext;
const unsigned long line = 0; const unsigned long line = 0;
tok(type Type, std::string_view Text, auto line): toktype(Type), toktext(Text), line(line) {} tok(type Type, std::string_view Text, decltype(line) line): toktype(Type), toktext(Text), line(line) {}
friend std::ostream& operator<<(std::ostream& output, const tok& it) { return output << it.toktext; } friend std::ostream& operator<<(std::ostream& output, const tok& it) { return output << it.toktext; }
}; };
std::vector<tok> lex(const std::string& in); std::vector<tok> lex(const std::string& in);

View File

@ -62,7 +62,7 @@ protected:
INCLUDECOMPONENT(StandardComponents::Reference); INCLUDECOMPONENT(StandardComponents::Reference);
INCLUDECOMPONENT(StandardComponents::Class); INCLUDECOMPONENT(StandardComponents::Class);
public: public:
static shared_ptr<Target> forName(string_view name); static shared_ptr<Target> forName(string_view name, bool newLines);
#define with(X) if (id == typeid(X)) { this->on(reinterpret_cast<X&>(*component)); continue; } #define with(X) if (id == typeid(X)) { this->on(reinterpret_cast<X&>(*component)); continue; }
string transpileWithTree(const ParseTree& tree) { string transpileWithTree(const ParseTree& tree) {
@ -77,11 +77,13 @@ public:
return output.str(); return output.str();
}; };
#undef with #undef with
const bool newLines;
explicit Target(const bool newLines): newLines(newLines) {};
}; };
#undef INCLUDECOMPONENT #undef INCLUDECOMPONENT
inline string transpile(const ParseTree& tree, const string_view& language) { inline string transpile(const ParseTree& tree, const string_view& language, const bool newLines) {
return Target::forName(language)->transpileWithTree(tree); return Target::forName(language, newLines)->transpileWithTree(tree);
} }
#include "implementations/Lua.hpp" #include "implementations/Lua.hpp"
@ -91,7 +93,7 @@ inline string transpile(const ParseTree& tree, const string_view& language) {
enum LANGUAGE: signed short { NONE = -1, LUA, JS, PY }; enum LANGUAGE: signed short { NONE = -1, LUA, JS, PY };
constinit array<string_view, 3> languages { ".lua", ".js", ".py"}; constinit array<string_view, 3> languages { ".lua", ".js", ".py"};
shared_ptr<Target> Target::forName(string_view name) { shared_ptr<Target> Target::forName(string_view name, const bool newLines = true) {
LANGUAGE selected = NONE; LANGUAGE selected = NONE;
for (unsigned int i = 0; i < languages.size(); ++i) { for (unsigned int i = 0; i < languages.size(); ++i) {
if (name == languages[i]) { if (name == languages[i]) {
@ -100,7 +102,7 @@ shared_ptr<Target> Target::forName(string_view name) {
} }
} }
shared_ptr<Target> target; shared_ptr<Target> target;
#define ADDTARGET(X) target = make_shared<X>(X()); #define ADDTARGET(X) target = shared_ptr<X>(new X(newLines));
switch (selected) { switch (selected) {
#ifdef LUA_HPP #ifdef LUA_HPP
case LUA: ADDTARGET(LUA_HPP); break; case LUA: ADDTARGET(LUA_HPP); break;

View File

@ -8,6 +8,7 @@ struct JsTarget: Target {
void on(const StandardComponents::types::String &parseComponent) override { void on(const StandardComponents::types::String &parseComponent) override {
stringInterpolation(parseComponent.content); stringInterpolation(parseComponent.content);
} }
using Target::Target;
}; };
#endif #endif

View File

@ -11,6 +11,7 @@ struct LuaTarget: Target {
void on(const StandardComponents::types::String &parseComponent) override { void on(const StandardComponents::types::String &parseComponent) override {
stringInterpolation(parseComponent.content, "[[", "]]", ".."); stringInterpolation(parseComponent.content, "[[", "]]", "..");
} }
using Target::Target;
}; };
#endif #endif

View File

@ -8,6 +8,7 @@ struct PyTarget: Target {
void on(const StandardComponents::types::String &parseComponent) override { void on(const StandardComponents::types::String &parseComponent) override {
stringInterpolation(parseComponent.content, "\"\"\"", "\"\"\""); stringInterpolation(parseComponent.content, "\"\"\"", "\"\"\"");
} }
using Target::Target;
}; };
#endif #endif

View File

@ -14,6 +14,7 @@ int main(int argc, char* argv[]) {
string target = ".lua"; string target = ".lua";
bool printResult = false; bool printResult = false;
bool parallel = false; bool parallel = false;
bool newLines = true;
if (argc > 0) { if (argc > 0) {
vector<string_view> files; vector<string_view> files;
@ -22,15 +23,15 @@ int main(int argc, char* argv[]) {
const string_view currentArg (argv[i]); const string_view currentArg (argv[i]);
if (currentArg == ArgumentShort("printresult")) printResult = true; if (currentArg == ArgumentShort("printresult")) printResult = true;
else if (currentArg == ArgumentAssignable("target")) { else if (currentArg == ArgumentAssignable("target")) {
target.clear(); const string value = ArgumentAssignable::getValueFor(currentArg.data());
string value = ArgumentAssignable::getValueFor(currentArg.data());
if (!value.empty()) (target = '.') += value; if (!value.empty()) (target = '.') += value;
} }
else if (currentArg == Argument("parallel")) parallel = true; else if (currentArg == Argument("parallel")) parallel = true;
else if (currentArg == Argument("newlinesoff")) newLines = false;
else if (currentArg.ends_with(".ybcon")) files.push_back(currentArg); else if (currentArg.ends_with(".ybcon")) files.push_back(currentArg);
} }
const auto compile = [&target](string_view name) { const auto compile = [&target, &newLines](string_view name) {
string transpiledString = transpile(parseString(getFileContent(name.data())), target); string transpiledString = transpile(parseString(getFileContent(name.data())), target, newLines);
name.remove_suffix(6); name.remove_suffix(6);
string outputFile; string outputFile;
(outputFile = name).append(target); (outputFile = name).append(target);