Make the newLine constructor parameter a reference & add a "separator" member and a "uniqueLineSeparator" virtual method to Target.hpp
Signed-off-by: Username404 <w.iron.zombie@gmail.com>
This commit is contained in:
parent
63b24752d6
commit
3c130529a4
|
@ -19,7 +19,7 @@ class Target {
|
||||||
constexpr static const char* const interpolationString = "${";
|
constexpr static const char* const interpolationString = "${";
|
||||||
constexpr static const char* const interpolationCloseString = "}";
|
constexpr static const char* const interpolationCloseString = "}";
|
||||||
protected:
|
protected:
|
||||||
virtual constexpr bool supportsOneLine() { return true; };
|
inline bool supportsOneLine() { return uniqueLineSeparator().has_value(); };
|
||||||
std::stringstream output;
|
std::stringstream output;
|
||||||
inline void stringInterpolation(const char* multiline, const string& view) { stringInterpolation(view, multiline, multiline); }
|
inline void stringInterpolation(const char* multiline, const string& view) { stringInterpolation(view, multiline, multiline); }
|
||||||
void stringInterpolation(string view, const char* openMultiline = "", const char* closeMultiline = "", const char* concatenationCharacters = "+") {
|
void stringInterpolation(string view, const char* openMultiline = "", const char* closeMultiline = "", const char* concatenationCharacters = "+") {
|
||||||
|
@ -74,6 +74,10 @@ protected:
|
||||||
typedef pair<const char*, const char*> print_functions_pair;
|
typedef pair<const char*, const char*> print_functions_pair;
|
||||||
virtual unordered_task_map getTaskMap() = 0;
|
virtual unordered_task_map getTaskMap() = 0;
|
||||||
virtual print_functions_pair printFunctions() = 0;
|
virtual print_functions_pair printFunctions() = 0;
|
||||||
|
typedef optional<const char*> optional_string;
|
||||||
|
virtual optional_string uniqueLineSeparator() { return ";"; };
|
||||||
|
const bool newLines;
|
||||||
|
const char* separator;
|
||||||
public:
|
public:
|
||||||
const unordered_task_map& getTaskMapInstance() {
|
const unordered_task_map& getTaskMapInstance() {
|
||||||
static unordered_task_map staticMap = getTaskMap();
|
static unordered_task_map staticMap = getTaskMap();
|
||||||
|
@ -101,12 +105,9 @@ public:
|
||||||
return staticMap;
|
return staticMap;
|
||||||
};
|
};
|
||||||
static shared_ptr<Target> forName(string_view name, bool newLines);
|
static shared_ptr<Target> forName(string_view name, bool newLines);
|
||||||
const bool newLines;
|
|
||||||
string transpileWithTree(const ParseTree& tree) {
|
string transpileWithTree(const ParseTree& tree) {
|
||||||
|
separator = newLines ? "\n" : (supportsOneLine() ? uniqueLineSeparator().value() : throw Yerbacon::Exception("--newlines=off is not supported by the current target"));
|
||||||
const unordered_task_map& taskMap = getTaskMapInstance();
|
const unordered_task_map& taskMap = getTaskMapInstance();
|
||||||
if (not newLines && !supportsOneLine()) {
|
|
||||||
throw Yerbacon::Exception("--newlines=off is not supported by the current target");
|
|
||||||
}
|
|
||||||
output.str(string());
|
output.str(string());
|
||||||
for (unsigned int i = 0; i < tree.size(); ++i) {
|
for (unsigned int i = 0; i < tree.size(); ++i) {
|
||||||
const component_ptr& component = tree[i];
|
const component_ptr& component = tree[i];
|
||||||
|
@ -125,7 +126,7 @@ public:
|
||||||
}
|
}
|
||||||
return output.str() + '\n';
|
return output.str() + '\n';
|
||||||
};
|
};
|
||||||
explicit Target(const bool newLines): newLines(newLines) {};
|
explicit Target(const bool& newLines): newLines(newLines), separator() {};
|
||||||
virtual ~Target() = default;
|
virtual ~Target() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ using namespace StandardComponents;
|
||||||
|
|
||||||
struct LuaTarget: Target {
|
struct LuaTarget: Target {
|
||||||
print_functions_pair printFunctions() final { return make_pair("io.write", "print"); }
|
print_functions_pair printFunctions() final { return make_pair("io.write", "print"); }
|
||||||
|
optional_string uniqueLineSeparator() final { return " "; }
|
||||||
unordered_task_map getTaskMap() final {
|
unordered_task_map getTaskMap() final {
|
||||||
return {
|
return {
|
||||||
make_task(Define,
|
make_task(Define,
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
using namespace StandardComponents;
|
using namespace StandardComponents;
|
||||||
|
|
||||||
struct PyTarget: Target {
|
struct PyTarget: Target {
|
||||||
bool supportsOneLine() final { return false; }
|
|
||||||
print_functions_pair printFunctions() final { return make_pair("sys.stdout.write", "print"); }
|
print_functions_pair printFunctions() final { return make_pair("sys.stdout.write", "print"); }
|
||||||
|
optional_string uniqueLineSeparator() final { return {}; }
|
||||||
unordered_task_map getTaskMap() final {
|
unordered_task_map getTaskMap() final {
|
||||||
return {
|
return {
|
||||||
make_task(Define, output << parseComponent.name << " = ";),
|
make_task(Define, output << parseComponent.name << " = ";),
|
||||||
|
|
Loading…
Reference in New Issue