45 lines
2.1 KiB
C++
45 lines
2.1 KiB
C++
#ifndef PY_HPP
|
|
#define PY_HPP
|
|
using namespace StandardComponents;
|
|
|
|
struct PyTarget: Target {
|
|
print_functions_pair printFunctions() final { return make_pair("sys.stdout.write", "print"); }
|
|
optional_string uniqueLineSeparator() final { return {}; }
|
|
unordered_task_map getTaskMap() final {
|
|
return {
|
|
make_task(Define, output << parseComponent.name << " = "; transpileTree(parseComponent.content);),
|
|
make_task(types::String, stringInterpolation(R"(""")", parseComponent.content);),
|
|
make_task(Function,
|
|
output << "def " << 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);
|
|
),
|
|
make_task(StandardComponents::Reference,
|
|
if (parseComponent.name == "true" or parseComponent.name == "false") {
|
|
output << (char) toupper(parseComponent.name.front()) << parseComponent.name.substr(1);
|
|
} else output << parseComponent.name;
|
|
)
|
|
};
|
|
}
|
|
using Target::Target;
|
|
};
|
|
|
|
#endif |