Re-add the newlinesoff argument
This commit is contained in:
parent
bfa8f50ad9
commit
96bd6bf708
|
@ -22,7 +22,7 @@ struct tok {
|
|||
const type toktype;
|
||||
const std::string toktext;
|
||||
const unsigned long line = 0;
|
||||
tok(type Type, std::string_view Text, auto line): toktype(Type), toktext(Text), line(line) {}
|
||||
tok(type Type, std::string_view Text, decltype(line) line): toktype(Type), toktext(Text), line(line) {}
|
||||
friend std::ostream& operator<<(std::ostream& output, const tok& it) { return output << it.toktext; }
|
||||
};
|
||||
std::vector<tok> lex(const std::string& in);
|
||||
|
|
|
@ -62,7 +62,7 @@ protected:
|
|||
INCLUDECOMPONENT(StandardComponents::Reference);
|
||||
INCLUDECOMPONENT(StandardComponents::Class);
|
||||
public:
|
||||
static shared_ptr<Target> forName(string_view name);
|
||||
static shared_ptr<Target> forName(string_view name, bool newLines);
|
||||
|
||||
#define with(X) if (id == typeid(X)) { this->on(reinterpret_cast<X&>(*component)); continue; }
|
||||
string transpileWithTree(const ParseTree& tree) {
|
||||
|
@ -77,11 +77,13 @@ public:
|
|||
return output.str();
|
||||
};
|
||||
#undef with
|
||||
const bool newLines;
|
||||
explicit Target(const bool newLines): newLines(newLines) {};
|
||||
};
|
||||
#undef INCLUDECOMPONENT
|
||||
|
||||
inline string transpile(const ParseTree& tree, const string_view& language) {
|
||||
return Target::forName(language)->transpileWithTree(tree);
|
||||
inline string transpile(const ParseTree& tree, const string_view& language, const bool newLines) {
|
||||
return Target::forName(language, newLines)->transpileWithTree(tree);
|
||||
}
|
||||
|
||||
#include "implementations/Lua.hpp"
|
||||
|
@ -91,7 +93,7 @@ inline string transpile(const ParseTree& tree, const string_view& language) {
|
|||
enum LANGUAGE: signed short { NONE = -1, LUA, JS, PY };
|
||||
constinit array<string_view, 3> languages { ".lua", ".js", ".py"};
|
||||
|
||||
shared_ptr<Target> Target::forName(string_view name) {
|
||||
shared_ptr<Target> Target::forName(string_view name, const bool newLines = true) {
|
||||
LANGUAGE selected = NONE;
|
||||
for (unsigned int i = 0; i < languages.size(); ++i) {
|
||||
if (name == languages[i]) {
|
||||
|
@ -100,7 +102,7 @@ shared_ptr<Target> Target::forName(string_view name) {
|
|||
}
|
||||
}
|
||||
shared_ptr<Target> target;
|
||||
#define ADDTARGET(X) target = make_shared<X>(X());
|
||||
#define ADDTARGET(X) target = shared_ptr<X>(new X(newLines));
|
||||
switch (selected) {
|
||||
#ifdef LUA_HPP
|
||||
case LUA: ADDTARGET(LUA_HPP); break;
|
||||
|
|
|
@ -8,6 +8,7 @@ struct JsTarget: Target {
|
|||
void on(const StandardComponents::types::String &parseComponent) override {
|
||||
stringInterpolation(parseComponent.content);
|
||||
}
|
||||
using Target::Target;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -11,6 +11,7 @@ struct LuaTarget: Target {
|
|||
void on(const StandardComponents::types::String &parseComponent) override {
|
||||
stringInterpolation(parseComponent.content, "[[", "]]", "..");
|
||||
}
|
||||
using Target::Target;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -8,6 +8,7 @@ struct PyTarget: Target {
|
|||
void on(const StandardComponents::types::String &parseComponent) override {
|
||||
stringInterpolation(parseComponent.content, "\"\"\"", "\"\"\"");
|
||||
}
|
||||
using Target::Target;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -14,6 +14,7 @@ int main(int argc, char* argv[]) {
|
|||
string target = ".lua";
|
||||
bool printResult = false;
|
||||
bool parallel = false;
|
||||
bool newLines = true;
|
||||
|
||||
if (argc > 0) {
|
||||
vector<string_view> files;
|
||||
|
@ -22,15 +23,15 @@ int main(int argc, char* argv[]) {
|
|||
const string_view currentArg (argv[i]);
|
||||
if (currentArg == ArgumentShort("printresult")) printResult = true;
|
||||
else if (currentArg == ArgumentAssignable("target")) {
|
||||
target.clear();
|
||||
string value = ArgumentAssignable::getValueFor(currentArg.data());
|
||||
const string value = ArgumentAssignable::getValueFor(currentArg.data());
|
||||
if (!value.empty()) (target = '.') += value;
|
||||
}
|
||||
else if (currentArg == Argument("parallel")) parallel = true;
|
||||
else if (currentArg == Argument("newlinesoff")) newLines = false;
|
||||
else if (currentArg.ends_with(".ybcon")) files.push_back(currentArg);
|
||||
}
|
||||
const auto compile = [&target](string_view name) {
|
||||
string transpiledString = transpile(parseString(getFileContent(name.data())), target);
|
||||
const auto compile = [&target, &newLines](string_view name) {
|
||||
string transpiledString = transpile(parseString(getFileContent(name.data())), target, newLines);
|
||||
name.remove_suffix(6);
|
||||
string outputFile;
|
||||
(outputFile = name).append(target);
|
||||
|
|
Loading…
Reference in New Issue