Add a (definetly incomplete) ParseComponents.hpp file and move the extern declarations of main.cpp to misc.hpp.
This commit is contained in:
parent
f95d1c2497
commit
5972f0ef4c
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue