From 22d159923760d76fd06cce81974f1754abb06152 Mon Sep 17 00:00:00 2001 From: Username404 Date: Thu, 7 Jul 2022 17:21:59 +0200 Subject: [PATCH] Add a GodotScript target Signed-off-by: Username404 --- src/headers/transpiler/Target.hpp | 2 ++ .../implementations/GodotScript.hpp | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/headers/transpiler/implementations/GodotScript.hpp diff --git a/src/headers/transpiler/Target.hpp b/src/headers/transpiler/Target.hpp index 434a341..859aa19 100644 --- a/src/headers/transpiler/Target.hpp +++ b/src/headers/transpiler/Target.hpp @@ -156,12 +156,14 @@ public: #include "implementations/Lua.hpp" #include "implementations/Js.hpp" #include "implementations/Py.hpp" +#include "implementations/GodotScript.hpp" 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); + ADDTARGET("gd", GsTarget); #undef ADDTARGET #undef make_nonlocal_task #undef make_task_noR diff --git a/src/headers/transpiler/implementations/GodotScript.hpp b/src/headers/transpiler/implementations/GodotScript.hpp new file mode 100644 index 0000000..d658f71 --- /dev/null +++ b/src/headers/transpiler/implementations/GodotScript.hpp @@ -0,0 +1,25 @@ +#ifndef GODOTSCRIPT_HPP +#define GODOTSCRIPT_HPP + +struct GsTarget: Target { + print_functions_pair printFunctions() final { return make_pair("printraw", "print"); } + unordered_task_map getTaskMap() final { + return { + make_task(Define, + output << (parseComponent.final ? "const " : "var ") << parseComponent.name << " = "; + transpileTree(parseComponent.content); + ), + make_task(types::String, stringInterpolation(R"(""")", parseComponent.content);), + make_task(Function, + output << "func " << parseComponent.name << '('; + separate_transpileTree(parseComponent.parameters, ", "); + output << "):" << separator << indentation; + if (parseComponent.empty()) output << "pass"; + separate_transpileTree(parseComponent, 1); + ) + }; + } + using Target::Target; +}; + +#endif \ No newline at end of file