From 96bd6bf70855b3dd5dd7cec7f04c84edac794718 Mon Sep 17 00:00:00 2001 From: Username404 Date: Sat, 11 Sep 2021 11:49:57 +0200 Subject: [PATCH] Re-add the newlinesoff argument --- src/headers/lex.hpp | 2 +- src/headers/transpiler/Target.hpp | 12 +++++++----- src/headers/transpiler/implementations/Js.hpp | 1 + src/headers/transpiler/implementations/Lua.hpp | 1 + src/headers/transpiler/implementations/Py.hpp | 1 + src/main.cpp | 9 +++++---- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/headers/lex.hpp b/src/headers/lex.hpp index e485197..041163f 100644 --- a/src/headers/lex.hpp +++ b/src/headers/lex.hpp @@ -22,7 +22,7 @@ struct tok { const type toktype; const std::string toktext; 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; } }; std::vector lex(const std::string& in); diff --git a/src/headers/transpiler/Target.hpp b/src/headers/transpiler/Target.hpp index d01b9e5..bffb43f 100644 --- a/src/headers/transpiler/Target.hpp +++ b/src/headers/transpiler/Target.hpp @@ -62,7 +62,7 @@ protected: INCLUDECOMPONENT(StandardComponents::Reference); INCLUDECOMPONENT(StandardComponents::Class); public: - static shared_ptr forName(string_view name); + static shared_ptr forName(string_view name, bool newLines); #define with(X) if (id == typeid(X)) { this->on(reinterpret_cast(*component)); continue; } string transpileWithTree(const ParseTree& tree) { @@ -77,11 +77,13 @@ public: return output.str(); }; #undef with + const bool newLines; + explicit Target(const bool newLines): newLines(newLines) {}; }; #undef INCLUDECOMPONENT -inline string transpile(const ParseTree& tree, const string_view& language) { - return Target::forName(language)->transpileWithTree(tree); +inline string transpile(const ParseTree& tree, const string_view& language, const bool newLines) { + return Target::forName(language, newLines)->transpileWithTree(tree); } #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 }; constinit array languages { ".lua", ".js", ".py"}; -shared_ptr Target::forName(string_view name) { +shared_ptr Target::forName(string_view name, const bool newLines = true) { LANGUAGE selected = NONE; for (unsigned int i = 0; i < languages.size(); ++i) { if (name == languages[i]) { @@ -100,7 +102,7 @@ shared_ptr Target::forName(string_view name) { } } shared_ptr target; - #define ADDTARGET(X) target = make_shared(X()); + #define ADDTARGET(X) target = shared_ptr(new X(newLines)); switch (selected) { #ifdef LUA_HPP case LUA: ADDTARGET(LUA_HPP); break; diff --git a/src/headers/transpiler/implementations/Js.hpp b/src/headers/transpiler/implementations/Js.hpp index 4ad2054..b6e6161 100644 --- a/src/headers/transpiler/implementations/Js.hpp +++ b/src/headers/transpiler/implementations/Js.hpp @@ -8,6 +8,7 @@ struct JsTarget: Target { void on(const StandardComponents::types::String &parseComponent) override { stringInterpolation(parseComponent.content); } + using Target::Target; }; #endif \ No newline at end of file diff --git a/src/headers/transpiler/implementations/Lua.hpp b/src/headers/transpiler/implementations/Lua.hpp index 66d68cd..12f2772 100644 --- a/src/headers/transpiler/implementations/Lua.hpp +++ b/src/headers/transpiler/implementations/Lua.hpp @@ -11,6 +11,7 @@ struct LuaTarget: Target { void on(const StandardComponents::types::String &parseComponent) override { stringInterpolation(parseComponent.content, "[[", "]]", ".."); } + using Target::Target; }; #endif \ No newline at end of file diff --git a/src/headers/transpiler/implementations/Py.hpp b/src/headers/transpiler/implementations/Py.hpp index 2bbdb4c..d82bc70 100644 --- a/src/headers/transpiler/implementations/Py.hpp +++ b/src/headers/transpiler/implementations/Py.hpp @@ -8,6 +8,7 @@ struct PyTarget: Target { void on(const StandardComponents::types::String &parseComponent) override { stringInterpolation(parseComponent.content, "\"\"\"", "\"\"\""); } + using Target::Target; }; #endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 3881eeb..befce84 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,6 +14,7 @@ int main(int argc, char* argv[]) { string target = ".lua"; bool printResult = false; bool parallel = false; + bool newLines = true; if (argc > 0) { vector files; @@ -22,15 +23,15 @@ int main(int argc, char* argv[]) { const string_view currentArg (argv[i]); if (currentArg == ArgumentShort("printresult")) printResult = true; else if (currentArg == ArgumentAssignable("target")) { - target.clear(); - string value = ArgumentAssignable::getValueFor(currentArg.data()); + const string value = ArgumentAssignable::getValueFor(currentArg.data()); if (!value.empty()) (target = '.') += value; } else if (currentArg == Argument("parallel")) parallel = true; + else if (currentArg == Argument("newlinesoff")) newLines = false; else if (currentArg.ends_with(".ybcon")) files.push_back(currentArg); } - const auto compile = [&target](string_view name) { - string transpiledString = transpile(parseString(getFileContent(name.data())), target); + const auto compile = [&target, &newLines](string_view name) { + string transpiledString = transpile(parseString(getFileContent(name.data())), target, newLines); name.remove_suffix(6); string outputFile; (outputFile = name).append(target);