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:
parent
97a9703a1a
commit
2330b87c0f
|
@ -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';
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue