Add a (definetly incomplete) ParseComponents.hpp file and move the extern declarations of main.cpp to misc.hpp.

This commit is contained in:
Username404-59 2021-03-04 11:16:59 +01:00
parent f95d1c2497
commit 5972f0ef4c
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
6 changed files with 46 additions and 15 deletions

View File

@ -45,7 +45,7 @@ set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${CMAKE_PROJECT_VERSION}-${TI
set(CPACK_STRIP_FILES TRUE)
include_directories(${CMAKE_CURRENT_LIST_DIR})
add_executable(ybcon src/main.cpp resources/Yerbacon.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)
add_executable(ybcon src/main.cpp resources/Yerbacon.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/ParseComponents.hpp)
target_compile_definitions(ybcon PRIVATE YBCON_VERSION="${PROJECT_VERSION}")
# lpkg = linux package, wpkg = windows package

View File

@ -0,0 +1,27 @@
//
// Created by doggo on 03/03/2021.
//
#ifndef YERBACON_PARSECOMPONENTS_HPP
#define YERBACON_PARSECOMPONENTS_HPP
#include <iostream>
#include <vector>
using namespace std;
class ParseComponent {
public:
};
class ParseTree {
protected:
vector<ParseComponent> subComponents;
public:
auto getComponents() { return subComponents; }
void add(const ParseComponent component) { subComponents.emplace_back(component); };
void addAll(const vector<ParseComponent>& components) { for (const auto& comp: components) add(comp); }
ParseTree(): subComponents() {};
};
#endif //YERBACON_PARSECOMPONENTS_HPP

View File

@ -12,4 +12,11 @@
#include <string>
std::string getVersion() noexcept { return YBCON_VERSION; }
string getFileContent(const string& file);
void setOutputFileContent(const string& language, const string& file, const string& content);
#include "ParseComponents.hpp"
ParseTree parseString(unique_ptr<string> toParse);
string transpile(ParseTree toTranspile, string language);
#endif //YERBACON_MISC_HPP

View File

@ -2,11 +2,6 @@
#include <memory>
using namespace std;
extern string getFileContent(const string& file);
extern void setOutputFileContent(const string& language, const string& file, const string& content);
extern string parseString(unique_ptr<string> toParse);
extern string transpile(string toTranspile, string language);
#include "headers/misc.hpp"
int main(int argc, char* argv[]) {
@ -23,8 +18,8 @@ int main(int argc, char* argv[]) {
if ((currentArg == "--printresult") || (currentArg == "-p")) printResult = true;
else if (currentArg.starts_with("--target=")) target = '.' + currentArg.erase(0, 9);
}
const string parsedString = parseString(make_unique<string>(getFileContent(fileName)));
const string transpiledString = transpile(parsedString, target);
const auto parsedTree = parseString(make_unique<string>(getFileContent(fileName)));
const string transpiledString = transpile(parsedTree, target);
if (printResult) cout << "~~~~[Yerbacon compilation result]~~~~\n\n" << "[WIP]\n" << transpiledString << "\n\n";
setOutputFileContent(target, fileName.erase(fileName.find(".ybcon")) + target, transpiledString);
}

View File

@ -2,16 +2,16 @@
// Created by username404 on 11/12/2020.
//
#include "../headers/lex.hpp"
#include "../headers/ParseComponents.hpp"
using namespace std;
string parseString(unique_ptr<string> toParse) {
stringstream tmpStream;
ParseTree parseString(unique_ptr<string> toParse) {
ParseTree parseTree = ParseTree();
auto lexed = lex(*toParse);
for (tok& token: lexed) {
tmpStream << token;
}
*toParse = tmpStream.str();
return *toParse;
return parseTree;
// TODO Actually parse
}

View File

@ -20,9 +20,11 @@ pair<LANGUAGE, bool> validLanguage(const string& it) {
}
return pair<LANGUAGE, bool>(selected, valid);
}
#include "../headers/ParseComponents.hpp"
string transpile(string toTranspile, string language)
string transpile(ParseTree tree, string language)
{
string transpiled;
auto valided = validLanguage(language);
if (valided.second) {
switch (valided.first) {
@ -39,5 +41,5 @@ string transpile(string toTranspile, string language)
cout << '"' << (char) toupper(language.at(1)) << language.erase(0, 2) << "\" is not a valid target.";
exit(1);
}
return toTranspile;
return transpiled;
}