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}")
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

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;
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) {
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<LANGUAGE>(i);
valid = true;
selected = static_cast<LANGUAGE>(i + 1);
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;
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;
}