Add a StandardComponents.hpp file.

This commit is contained in:
Username404-59 2021-03-06 21:58:47 +01:00
parent 8772be9d5c
commit 80510909f1
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
6 changed files with 33 additions and 11 deletions

View File

@ -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 src/headers/ParseComponents.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/parsing/ParseComponents.hpp src/headers/parsing/StandardComponents.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

View File

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

View File

@ -9,7 +9,11 @@
#include <vector> #include <vector>
using namespace std; using namespace std;
class ParseComponent { #include "../lex.hpp"
class ParseComponent {};
struct ParseTree: public ParseComponent {
private: private:
unsigned int compCount = 0; unsigned int compCount = 0;
protected: protected:
@ -19,10 +23,9 @@ public:
auto& getComponents() { return subComponents; } auto& getComponents() { return subComponents; }
void add(const ParseComponent& component) { subComponents.push_back(component); ++compCount; }; void add(const ParseComponent& component) { subComponents.push_back(component); ++compCount; };
void addAll(const vector<ParseComponent>& components) { for (const auto& comp: components) add(comp); } void addAll(const vector<ParseComponent>& components) { for (const auto& comp: components) add(comp); }
ParseComponent(): subComponents() {}; void operator<<(const ParseComponent& component) { this->add(component); }
~ParseComponent() = default; ParseTree(): subComponents() {};
~ParseTree() = default;
}; };
struct ParseTree: public ParseComponent {};
#endif //YERBACON_PARSECOMPONENTS_HPP #endif //YERBACON_PARSECOMPONENTS_HPP

View File

@ -0,0 +1,18 @@
//
// Created by doggo on 05/03/2021.
//
#ifndef YERBACON_STANDARDCOMPONENTS_HPP
#define YERBACON_STANDARDCOMPONENTS_HPP
#include "ParseComponents.hpp"
namespace comp {
namespace types {
struct String: public ParseComponent {
string content;
explicit String(const string& str) { content = str; }
};
}
}
#endif //YERBACON_STANDARDCOMPONENTS_HPP

View File

@ -2,14 +2,15 @@
// 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" #include "../headers/parsing/ParseComponents.hpp"
#include "../headers/parsing/StandardComponents.hpp"
using namespace std; using namespace std;
ParseTree parseString(const unique_ptr<string>& toParse) { ParseTree parseString(const unique_ptr<string>& toParse) {
ParseTree parseTree = ParseTree(); ParseTree parseTree = ParseTree();
auto lexed = lex(*toParse); auto lexed = lex(*toParse);
for (tok& token: lexed) { for (const tok& token: lexed) {
} }
return parseTree; return parseTree;

View File

@ -20,7 +20,7 @@ pair<LANGUAGE, bool> validLanguage(const string& it) {
} }
return pair<LANGUAGE, bool>(selected, valid); return pair<LANGUAGE, bool>(selected, valid);
} }
#include "../headers/ParseComponents.hpp" #include "src/headers/parsing/ParseComponents.hpp"
string transpile(ParseTree tree, string language) string transpile(ParseTree tree, string language)
{ {