From 2330b87c0f06c1d65fa0eee356e40bc4a51dbd4a Mon Sep 17 00:00:00 2001 From: Username404 Date: Thu, 21 Apr 2022 22:21:08 +0200 Subject: [PATCH] Target.hpp: Add a "use_uniqueLineSeparator" virtual function Js.hpp: override the new virtual function to always output semicolons Signed-off-by: Username404 --- src/headers/transpiler/Target.hpp | 6 ++++-- src/headers/transpiler/implementations/Js.hpp | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/headers/transpiler/Target.hpp b/src/headers/transpiler/Target.hpp index 7366c9f..5dbdc2b 100644 --- a/src/headers/transpiler/Target.hpp +++ b/src/headers/transpiler/Target.hpp @@ -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 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 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'; diff --git a/src/headers/transpiler/implementations/Js.hpp b/src/headers/transpiler/implementations/Js.hpp index 2efd8c8..78bb491 100644 --- a/src/headers/transpiler/implementations/Js.hpp +++ b/src/headers/transpiler/implementations/Js.hpp @@ -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,