Yerbacon/src/headers/transpiler/implementations/GodotScript.hpp
Username404-59 348da1eaa3
GodotScript.hpp: Fix GodotScript constants after the last commit
Signed-off-by: Username404-59 <w.iron.zombie@gmail.com>
2025-04-08 14:36:22 +02:00

49 lines
2.3 KiB
C++

#ifndef GODOTSCRIPT_HPP
#define GODOTSCRIPT_HPP
using namespace StandardComponents;
struct GsTarget: Target {
print_functions_pair printFunctions() final { return make_pair("printraw", "print"); }
unordered_task_map getTaskMap() final {
return {
make_task(Define<false>,
const optional previous = parsedTree.findReferenceByName<Define<false>>(parseComponent.name);
if (previous.has_value() and &previous.value().get() == &parseComponent) { // TODO Recursively traverse the parsedTree's parents and their parents to find existing definitions and do it in semantic analysis
output << "var ";
} else if (parseComponent.final) {
output << "const ";
}
output << 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);
),
make_task(Condition::Statement,
output << "if ("; transpileTree(parseComponent.condition); output << "):" << separator << indentation;
if (parseComponent.empty()) output << "pass";
separate_transpileTree(parseComponent, 1);
if (not parseComponent.else_branches.empty()) {
output << separator;
separate_transpileTree(parseComponent.else_branches);
}
),
make_task(Condition::Statement::Branch,
if (parseComponent.is_conditional()) {
output << "elif ("; transpileTree(parseComponent.condition); output << ")";
} else output << "else";
output << ':' << separator << indentation;
separate_transpileTree(parseComponent, 1);
if (parseComponent.empty()) output << "pass";
)
};
}
using Target::Target;
};
#endif