diff --git a/src/headers/transpiler/Target.hpp b/src/headers/transpiler/Target.hpp index 5dbdc2b..3ff70cc 100644 --- a/src/headers/transpiler/Target.hpp +++ b/src/headers/transpiler/Target.hpp @@ -140,7 +140,7 @@ public: })); return staticMap; }; - static shared_ptr forName(string_view name, bool newLines); + static unique_ptr forName(string_view name, bool newLines); string transpileWithTree(const ParseTree& tree) { separator = newLines ? "\n" : (use_uniqueLineSeparator() ? uniqueLineSeparator().value() : throw Yerbacon::Exception("--newlines=off is not supported by the current target")); output.str(string()); @@ -156,39 +156,19 @@ public: #include "implementations/Js.hpp" #include "implementations/Py.hpp" -enum LANGUAGE: signed short { NONE = -1, LUA, JS, PY }; -constinit const array languages { "lua", "js", "py" }; - -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]) { - selected = static_cast(i); - break; - } - } - shared_ptr target; - #define ADDTARGET(X) target = shared_ptr(new X(newLines)) - switch (selected) { - #ifdef LUA_HPP - case LUA: ADDTARGET(LUA_HPP); break; - #endif - #ifdef JS_HPP - case JS: ADDTARGET(JS_HPP); break; - #endif - #ifdef PY_HPP - case PY: ADDTARGET(PY_HPP); break; - #endif - case NONE: - default: Yerbacon::fail({"\"", string(1, (char) toupper(name.at(1))).data(), name.substr(2).data(), "\" is not a valid target."}); - } +unique_ptr Target::forName(string_view name, const bool newLines = true) { + #define ADDTARGET(X, target_class) if (name == X) return unique_ptr(new target_class(newLines)) + ADDTARGET("lua", LuaTarget); + ADDTARGET("js", JsTarget); + ADDTARGET("py", PyTarget); #undef ADDTARGET #undef make_nonlocal_task #undef make_task_noR #undef make_task #undef make_task_base_R #undef make_task_base - return target; + Yerbacon::fail({"\"", to_string(toupper(name.at(1))).data(), name.substr(2).data(), "\" is not a valid target."}); + return nullptr; } #endif //YERBACON_TARGET_HPP \ No newline at end of file diff --git a/src/headers/transpiler/implementations/Js.hpp b/src/headers/transpiler/implementations/Js.hpp index 78bb491..ce8f5c7 100644 --- a/src/headers/transpiler/implementations/Js.hpp +++ b/src/headers/transpiler/implementations/Js.hpp @@ -1,5 +1,5 @@ #ifndef JS_HPP -#define JS_HPP JsTarget +#define JS_HPP using namespace StandardComponents; struct JsTarget: Target { diff --git a/src/headers/transpiler/implementations/Lua.hpp b/src/headers/transpiler/implementations/Lua.hpp index d512bb2..e6283bc 100644 --- a/src/headers/transpiler/implementations/Lua.hpp +++ b/src/headers/transpiler/implementations/Lua.hpp @@ -1,5 +1,5 @@ #ifndef LUA_HPP -#define LUA_HPP LuaTarget +#define LUA_HPP using namespace StandardComponents; struct LuaTarget: Target { diff --git a/src/headers/transpiler/implementations/Py.hpp b/src/headers/transpiler/implementations/Py.hpp index 829caf3..16081a7 100644 --- a/src/headers/transpiler/implementations/Py.hpp +++ b/src/headers/transpiler/implementations/Py.hpp @@ -1,5 +1,5 @@ #ifndef PY_HPP -#define PY_HPP PyTarget +#define PY_HPP using namespace StandardComponents; struct PyTarget: Target {