diff --git a/CMakeLists.txt b/CMakeLists.txt index 8afa8d7..210101f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,7 +79,7 @@ set(CPACK_PACKAGE_INSTALL_DIRECTORY "Yerbacon ${CMAKE_PROJECT_VERSION_MAJOR}.${C set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${CMAKE_PROJECT_VERSION}-${TIME}") include_directories(${CMAKE_CURRENT_LIST_DIR}) -add_executable(${EXENAME} src/main.cpp ${CMAKE_CURRENT_BINARY_DIR}/processed/${PROJECT_NAME}.rc src/parser/MainParse.cpp src/transpiler/MainTranspile.cpp src/etc/filefuncs.cpp src/etc/lexer.cpp src/headers/lex.hpp src/headers/misc.hpp src/headers/parsing/ParseComponents.hpp) +add_executable(${EXENAME} src/main.cpp ${CMAKE_CURRENT_BINARY_DIR}/processed/${PROJECT_NAME}.rc src/parser/MainParse.cpp src/transpiler/MainTranspile.cpp src/etc/filefuncs.cpp src/etc/lexer.cpp src/headers/lex.hpp src/headers/misc.hpp src/headers/parsing/ParseComponents.hpp src/headers/transpiler/Targets.hpp) target_compile_definitions(ybcon PRIVATE YBCON_VERSION="${CODENAME} ${PROJECT_VERSION}") # lpkg = linux package, wpkg = windows package diff --git a/src/headers/transpiler/Targets.hpp b/src/headers/transpiler/Targets.hpp new file mode 100644 index 0000000..cbc2823 --- /dev/null +++ b/src/headers/transpiler/Targets.hpp @@ -0,0 +1,11 @@ +#ifndef YERBACON_TARGETS_HPP +#define YERBACON_TARGETS_HPP + +#include +#include + +struct Target { + virtual vector getExtensions() = 0; +}; + +#endif //YERBACON_TARGETS_HPP \ No newline at end of file diff --git a/src/transpiler/MainTranspile.cpp b/src/transpiler/MainTranspile.cpp index ebd1bd2..f9e3d93 100644 --- a/src/transpiler/MainTranspile.cpp +++ b/src/transpiler/MainTranspile.cpp @@ -2,41 +2,38 @@ using namespace std; -enum LANGUAGE: unsigned short {LUA=0,JS=1,PY=2}; +enum LANGUAGE: unsigned short { NONE, LUA, JS, PY }; +const string_view languages[3] = { ".lua", ".js", ".py"}; -pair validLanguage(const string_view& it) { - static const string_view languages[3] = {".lua", ".js", ".py"}; - LANGUAGE selected = LUA; - bool valid = false; +LANGUAGE validLanguage(const string_view& it) { + LANGUAGE selected = NONE; for (unsigned short i = 0; (i <= (languages->size() - 2)); ++i) { if (it == languages[i]) { - selected = static_cast(i); - valid = true; + selected = static_cast(i + 1); break; } } - return pair(selected, valid); + return selected; } -#include "../headers/parsing/ParseComponents.hpp" -string transpile(ParseTree tree, string language) +#include "../headers/parsing/ParseComponents.hpp" +#include "../headers/transpiler/Targets.hpp" + +string transpile(const ParseTree tree, string language) { string transpiled; auto valided = validLanguage(language); - if (valided.second) { - switch (valided.first) { - // TODO Complete this part - case LUA: - break; - case JS: - break; - case PY: - break; + switch (valided) { + case LUA: + break; + case JS: + break; + case PY: + break; + default: { + cout << '"' << (char) toupper(language.at(1)) << language.erase(0, 2) << "\" is not a valid target." << endl; + exit(0); } - // TODO Actually transpile - } else { - cout << '"' << (char) toupper(language.at(1)) << language.erase(0, 2) << "\" is not a valid target." << endl; - exit(0); } return transpiled; } \ No newline at end of file