Remove the parameter of Target.get(), add it to Target as a property and rename Target.get() to Target.on()
This commit is contained in:
parent
664a6a92be
commit
079d99e08a
|
@ -2,7 +2,7 @@
|
||||||
#define YERBACON_MISC_HPP
|
#define YERBACON_MISC_HPP
|
||||||
|
|
||||||
string getFileContent(const string& file);
|
string getFileContent(const string& file);
|
||||||
void outputFileContent(const string& file, const string_view content);
|
void outputFileContent(const string& file, string_view content);
|
||||||
|
|
||||||
#include "lex.hpp"
|
#include "lex.hpp"
|
||||||
#include "parsing/Parser.hpp"
|
#include "parsing/Parser.hpp"
|
||||||
|
|
|
@ -9,29 +9,30 @@
|
||||||
|
|
||||||
#include "../parsing/ParseComponents.hpp"
|
#include "../parsing/ParseComponents.hpp"
|
||||||
|
|
||||||
#define GETCOMP(X) virtual void get(const X& parseComponent, std::stringstream& output) {}
|
#define INCLUDECOMPONENT(X) virtual void on(const X& parseComponent) {}
|
||||||
class Target {
|
class Target {
|
||||||
protected:
|
protected:
|
||||||
GETCOMP(StandardComponents::Define);
|
std::stringstream output;
|
||||||
GETCOMP(StandardComponents::Reference);
|
INCLUDECOMPONENT(StandardComponents::Define);
|
||||||
GETCOMP(StandardComponents::Class);
|
INCLUDECOMPONENT(StandardComponents::Reference);
|
||||||
|
INCLUDECOMPONENT(StandardComponents::Class);
|
||||||
public:
|
public:
|
||||||
static shared_ptr<Target> forName(string_view name);
|
static shared_ptr<Target> forName(string_view name);
|
||||||
|
|
||||||
#define with(X) if (id == typeid(X)) { this->get(reinterpret_cast<X&>(*component), result); continue; }
|
#define with(X) if (id == typeid(X)) { this->on(reinterpret_cast<X&>(*component)); continue; }
|
||||||
string transpileWithTree(const ParseTree& tree) {
|
string transpileWithTree(const ParseTree& tree) {
|
||||||
stringstream result;
|
output.str(string());
|
||||||
for (const unique_ptr<ParseComponent>& component: tree) {
|
for (const unique_ptr<ParseComponent>& component: tree) {
|
||||||
const type_info& id = (*component).getId();
|
const type_info& id = (*component).getId();
|
||||||
with(StandardComponents::Define);
|
with(StandardComponents::Define);
|
||||||
with(StandardComponents::Reference);
|
with(StandardComponents::Reference);
|
||||||
with(StandardComponents::Class);
|
with(StandardComponents::Class);
|
||||||
}
|
}
|
||||||
return result.str();
|
return output.str();
|
||||||
};
|
};
|
||||||
#undef with
|
#undef with
|
||||||
};
|
};
|
||||||
#undef GETCOMP
|
#undef INCLUDECOMPONENT
|
||||||
|
|
||||||
inline string transpile(const ParseTree& tree, const string_view& language) {
|
inline string transpile(const ParseTree& tree, const string_view& language) {
|
||||||
return Target::forName(language)->transpileWithTree(tree);
|
return Target::forName(language)->transpileWithTree(tree);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#define JS_HPP JsTarget
|
#define JS_HPP JsTarget
|
||||||
|
|
||||||
struct JsTarget: Target {
|
struct JsTarget: Target {
|
||||||
void get(const StandardComponents::Define &parseComponent, std::stringstream &output) override {
|
void on(const StandardComponents::Define &parseComponent) override {
|
||||||
output << (parseComponent.final ? "const " : "let ") << parseComponent.name << " = ";
|
output << (parseComponent.final ? "const " : "let ") << parseComponent.name << " = ";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#define LUA_HPP LuaTarget
|
#define LUA_HPP LuaTarget
|
||||||
|
|
||||||
struct LuaTarget: Target {
|
struct LuaTarget: Target {
|
||||||
void get(const StandardComponents::Define &parseComponent, std::stringstream& output) override {
|
void on(const StandardComponents::Define &parseComponent) override {
|
||||||
if (parseComponent.final) output << "local ";
|
if (parseComponent.final) output << "local ";
|
||||||
output << parseComponent.name;
|
output << parseComponent.name;
|
||||||
if (parseComponent.final) output << " <const>"; // TODO Find an alternative to <const> for lua >5.4
|
if (parseComponent.final) output << " <const>"; // TODO Find an alternative to <const> for lua >5.4
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#define PY_HPP PyTarget
|
#define PY_HPP PyTarget
|
||||||
|
|
||||||
struct PyTarget: Target {
|
struct PyTarget: Target {
|
||||||
void get(const StandardComponents::Define &parseComponent, std::stringstream &output) override {
|
void on(const StandardComponents::Define &parseComponent) override {
|
||||||
output << parseComponent.name << " = ";
|
output << parseComponent.name << " = ";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue