Add a Targets.hpp file and shorten MainTranspile.cpp.

This commit is contained in:
Username404 2021-06-25 20:58:07 +02:00
parent 9f5a6c1631
commit 5de2a28f93
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
3 changed files with 32 additions and 24 deletions

View File

@ -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}") set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${CMAKE_PROJECT_VERSION}-${TIME}")
include_directories(${CMAKE_CURRENT_LIST_DIR}) 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}") target_compile_definitions(ybcon PRIVATE YBCON_VERSION="${CODENAME} ${PROJECT_VERSION}")
# lpkg = linux package, wpkg = windows package # lpkg = linux package, wpkg = windows package

View File

@ -0,0 +1,11 @@
#ifndef YERBACON_TARGETS_HPP
#define YERBACON_TARGETS_HPP
#include <vector>
#include <string_view>
struct Target {
virtual vector<string_view> getExtensions() = 0;
};
#endif //YERBACON_TARGETS_HPP

View File

@ -2,41 +2,38 @@
using namespace std; 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<LANGUAGE, bool> validLanguage(const string_view& it) { LANGUAGE validLanguage(const string_view& it) {
static const string_view languages[3] = {".lua", ".js", ".py"}; LANGUAGE selected = NONE;
LANGUAGE selected = LUA;
bool valid = false;
for (unsigned short i = 0; (i <= (languages->size() - 2)); ++i) { for (unsigned short i = 0; (i <= (languages->size() - 2)); ++i) {
if (it == languages[i]) { if (it == languages[i]) {
selected = static_cast<LANGUAGE>(i); selected = static_cast<LANGUAGE>(i + 1);
valid = true;
break; break;
} }
} }
return pair<LANGUAGE, bool>(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; string transpiled;
auto valided = validLanguage(language); auto valided = validLanguage(language);
if (valided.second) { switch (valided) {
switch (valided.first) {
// TODO Complete this part
case LUA: case LUA:
break; break;
case JS: case JS:
break; break;
case PY: case PY:
break; break;
} default: {
// TODO Actually transpile
} else {
cout << '"' << (char) toupper(language.at(1)) << language.erase(0, 2) << "\" is not a valid target." << endl; cout << '"' << (char) toupper(language.at(1)) << language.erase(0, 2) << "\" is not a valid target." << endl;
exit(0); exit(0);
} }
}
return transpiled; return transpiled;
} }