From 26421597f21054350a7065a1fa2c74e15b0c2e0c Mon Sep 17 00:00:00 2001 From: Username404 Date: Sat, 11 Sep 2021 13:19:43 +0200 Subject: [PATCH] Prohibit the use of --newlinesoff with targets that do not support putting a whole script on one line --- src/headers/transpiler/Target.hpp | 7 ++++++- src/headers/transpiler/implementations/Py.hpp | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/headers/transpiler/Target.hpp b/src/headers/transpiler/Target.hpp index bffb43f..c60bd0d 100644 --- a/src/headers/transpiler/Target.hpp +++ b/src/headers/transpiler/Target.hpp @@ -15,6 +15,7 @@ class Target { constexpr static const char* const interpolationString = "${"; constexpr static const char* const interpolationCloseString = "}"; protected: + virtual constexpr bool supportsOneLine() { return true; }; std::stringstream output; INCLUDECOMPONENT(StandardComponents::Define); INCLUDECOMPONENT(StandardComponents::types::String); @@ -102,7 +103,7 @@ shared_ptr Target::forName(string_view name, const bool newLines = true) } } shared_ptr target; - #define ADDTARGET(X) target = shared_ptr(new X(newLines)); + #define ADDTARGET(X) target = shared_ptr(new X(newLines)) switch (selected) { #ifdef LUA_HPP case LUA: ADDTARGET(LUA_HPP); break; @@ -123,6 +124,10 @@ shared_ptr Target::forName(string_view name, const bool newLines = true) } } #undef ADDTARGET + if (not newLines and not target->supportsOneLine()) { + cout << "--newlinesoff cannot be used with --target=" << name.substr(1) << endl; + exit(0); + } return target; }; diff --git a/src/headers/transpiler/implementations/Py.hpp b/src/headers/transpiler/implementations/Py.hpp index d82bc70..1281ea8 100644 --- a/src/headers/transpiler/implementations/Py.hpp +++ b/src/headers/transpiler/implementations/Py.hpp @@ -2,6 +2,7 @@ #define PY_HPP PyTarget struct PyTarget: Target { + bool supportsOneLine() final { return false; } void on(const StandardComponents::Define &parseComponent) override { output << parseComponent.name << " = "; }