Yerbacon/src/headers/transpiler/implementations/Lua.hpp
Username404-59 888c75a31e
Share the Reference analysis task with the Define one
Signed-off-by: Username404-59 <w.iron.zombie@gmail.com>
2024-12-31 23:11:15 +01:00

54 lines
2.3 KiB
C++

#ifndef LUA_HPP
#define LUA_HPP
using namespace StandardComponents;
struct LuaTarget: Target {
print_functions_pair printFunctions() final { return make_pair("io.write", "print"); }
optional_string uniqueLineSeparator() final { return " "; }
unordered_task_map getTaskMap() final {
return {
make_task(Define<false>,
if (parseComponent.final) output << "local ";
output << parseComponent.name;
if (parseComponent.final) output << " <const>"; // TODO Find an alternative to <const> for lua <5.4
output << " = ";
transpileTree(parseComponent.content);
),
make_task(types::String, stringInterpolation(parseComponent.content, "[[", "]]", "..");),
make_task(Function,
output << "function " << parseComponent.name << '(';
separate_transpileTree(parseComponent.parameters, ", ");
output << ')';
if (not parseComponent.empty()) {
output << separator;
if (newLines) output << indentation;
} else output << ' ';
separate_transpileTree(parseComponent, 1);
if (not parseComponent.empty()) output << separator;
output << "end";
),
make_task(Condition::Statement,
output << "if ("; transpileTree(parseComponent.condition); output << ") then";
if (not parseComponent.empty()) {
output << separator; if (newLines) output << indentation; }
separate_transpileTree(parseComponent, 1);
if (not parseComponent.else_branches.empty()) {
output << separator;
separate_transpileTree(parseComponent.else_branches);
}
output << separator << "end";
),
make_task(Condition::Statement::Branch,
if (parseComponent.is_conditional()) {
output << "elseif ("; transpileTree(parseComponent.condition); output << ") then";
} else output << "else";
output << separator;
if (newLines) output << indentation;
separate_transpileTree(parseComponent, 1);
)
};
}
using Target::Target;
};
#endif