Prohibit the use of --newlinesoff with targets that do not support putting a whole script on one line

This commit is contained in:
Username404 2021-09-11 13:19:43 +02:00
parent 96bd6bf708
commit 26421597f2
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
2 changed files with 7 additions and 1 deletions

View File

@ -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> Target::forName(string_view name, const bool newLines = true)
}
}
shared_ptr<Target> target;
#define ADDTARGET(X) target = shared_ptr<X>(new X(newLines));
#define ADDTARGET(X) target = shared_ptr<X>(new X(newLines))
switch (selected) {
#ifdef LUA_HPP
case LUA: ADDTARGET(LUA_HPP); break;
@ -123,6 +124,10 @@ shared_ptr<Target> 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;
};

View File

@ -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 << " = ";
}