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)
|
set(CPACK_STRIP_FILES TRUE)
|
||||||
|
|
||||||
include_directories(${CMAKE_CURRENT_LIST_DIR})
|
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}")
|
target_compile_definitions(ybcon PRIVATE YBCON_VERSION="${PROJECT_VERSION}")
|
||||||
|
|
||||||
# lpkg = linux package, wpkg = windows package
|
# lpkg = linux package, wpkg = windows package
|
||||||
|
27
src/headers/ParseComponents.hpp
Normal file
27
src/headers/ParseComponents.hpp
Normal 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
|
@ -12,4 +12,11 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
std::string getVersion() noexcept { return YBCON_VERSION; }
|
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
|
#endif //YERBACON_MISC_HPP
|
||||||
|
@ -2,11 +2,6 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
using namespace std;
|
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"
|
#include "headers/misc.hpp"
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
@ -23,8 +18,8 @@ int main(int argc, char* argv[]) {
|
|||||||
if ((currentArg == "--printresult") || (currentArg == "-p")) printResult = true;
|
if ((currentArg == "--printresult") || (currentArg == "-p")) printResult = true;
|
||||||
else if (currentArg.starts_with("--target=")) target = '.' + currentArg.erase(0, 9);
|
else if (currentArg.starts_with("--target=")) target = '.' + currentArg.erase(0, 9);
|
||||||
}
|
}
|
||||||
const string parsedString = parseString(make_unique<string>(getFileContent(fileName)));
|
const auto parsedTree = parseString(make_unique<string>(getFileContent(fileName)));
|
||||||
const string transpiledString = transpile(parsedString, target);
|
const string transpiledString = transpile(parsedTree, target);
|
||||||
if (printResult) cout << "~~~~[Yerbacon compilation result]~~~~\n\n" << "[WIP]\n" << transpiledString << "\n\n";
|
if (printResult) cout << "~~~~[Yerbacon compilation result]~~~~\n\n" << "[WIP]\n" << transpiledString << "\n\n";
|
||||||
setOutputFileContent(target, fileName.erase(fileName.find(".ybcon")) + target, transpiledString);
|
setOutputFileContent(target, fileName.erase(fileName.find(".ybcon")) + target, transpiledString);
|
||||||
}
|
}
|
||||||
|
@ -2,16 +2,16 @@
|
|||||||
// Created by username404 on 11/12/2020.
|
// Created by username404 on 11/12/2020.
|
||||||
//
|
//
|
||||||
#include "../headers/lex.hpp"
|
#include "../headers/lex.hpp"
|
||||||
|
#include "../headers/ParseComponents.hpp"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
string parseString(unique_ptr<string> toParse) {
|
ParseTree parseString(unique_ptr<string> toParse) {
|
||||||
stringstream tmpStream;
|
ParseTree parseTree = ParseTree();
|
||||||
auto lexed = lex(*toParse);
|
auto lexed = lex(*toParse);
|
||||||
for (tok& token: lexed) {
|
for (tok& token: lexed) {
|
||||||
tmpStream << token;
|
|
||||||
}
|
}
|
||||||
*toParse = tmpStream.str();
|
return parseTree;
|
||||||
return *toParse;
|
|
||||||
// TODO Actually parse
|
// TODO Actually parse
|
||||||
}
|
}
|
@ -20,9 +20,11 @@ pair<LANGUAGE, bool> validLanguage(const string& it) {
|
|||||||
}
|
}
|
||||||
return pair<LANGUAGE, bool>(selected, valid);
|
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);
|
auto valided = validLanguage(language);
|
||||||
if (valided.second) {
|
if (valided.second) {
|
||||||
switch (valided.first) {
|
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.";
|
cout << '"' << (char) toupper(language.at(1)) << language.erase(0, 2) << "\" is not a valid target.";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
return toTranspile;
|
return transpiled;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user