Target.hpp: Add a "use_uniqueLineSeparator" virtual function

Js.hpp: override the new virtual function to always output semicolons

Signed-off-by: Username404 <w.iron.zombie@gmail.com>
This commit is contained in:
Username404 2022-04-21 22:21:08 +02:00
parent 97a9703a1a
commit 2330b87c0f
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
2 changed files with 5 additions and 2 deletions

View File

@ -107,7 +107,8 @@ protected:
IS(ParseTree)
void separate_transpileTree(const T& parseTree, const unsigned short& indentationLevel = 0) {
transpileTree(parseTree, indentationLevel, [this, &parseTree](const auto& iterator){
if (iterator + 1 != parseTree.cend()) { output << separator; }
if ((newLines || iterator + 1 == parseTree.cend()) && use_uniqueLineSeparator()) output << uniqueLineSeparator().value();
if (iterator + 1 != parseTree.cend()) output << separator;
});
}
IS(ParseTree)
@ -118,6 +119,7 @@ protected:
}
typedef optional<const char*> optional_string;
virtual optional_string uniqueLineSeparator() { return ";"; };
virtual bool use_uniqueLineSeparator() { return supportsOneLine(); };
const bool newLines;
string separator;
static constexpr const char* indentation = " ";
@ -140,7 +142,7 @@ public:
};
static shared_ptr<Target> forName(string_view name, bool newLines);
string transpileWithTree(const ParseTree& tree) {
separator = newLines ? "\n" : (supportsOneLine() ? uniqueLineSeparator().value() : throw Yerbacon::Exception("--newlines=off is not supported by the current target"));
separator = newLines ? "\n" : (use_uniqueLineSeparator() ? uniqueLineSeparator().value() : throw Yerbacon::Exception("--newlines=off is not supported by the current target"));
output.str(string());
separate_transpileTree(tree);
return output.str() + '\n';

View File

@ -4,6 +4,7 @@ using namespace StandardComponents;
struct JsTarget: Target {
print_functions_pair printFunctions() final { return make_pair("util.write", "console.log"); }
bool use_uniqueLineSeparator() final { return true; }
unordered_task_map getTaskMap() final {
return {
make_task(Define,