Add a misc.hpp file.

This commit is contained in:
Username404-59 2021-03-03 19:47:25 +01:00
parent eb821b9f22
commit 6d2c23bb39
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
4 changed files with 26 additions and 9 deletions

View File

@ -1,6 +1,10 @@
// //
// Created by doggo on 04/02/2021. // Created by doggo on 04/02/2021.
// //
#ifndef YERBACON_LEX_H
#define YERBACON_LEX_H
#include <memory> #include <memory>
#include <vector> #include <vector>
#include <sstream> #include <sstream>
@ -20,3 +24,5 @@ struct tok {
friend std::ostream& operator<<(std::ostream& output, const tok& it) { return output << it.toktext; } friend std::ostream& operator<<(std::ostream& output, const tok& it) { return output << it.toktext; }
}; };
std::vector<tok>& lex(const std::string& in); std::vector<tok>& lex(const std::string& in);
#endif //YERBACON_TEST_H

15
src/headers/misc.hpp Normal file
View File

@ -0,0 +1,15 @@
//
// Created by doggo on 03/03/2021.
//
#ifndef YERBACON_MISC_HPP
#define YERBACON_MISC_HPP
#ifndef YBCON_VERSION
#define YBCON_VERSION "UNKNOWN"
#endif
#include <string>
std::string getVersion() noexcept { return YBCON_VERSION; }
#endif //YERBACON_MISC_HPP

View File

@ -2,18 +2,15 @@
#include <memory> #include <memory>
using namespace std; using namespace std;
#ifndef YBCON_VERSION
#define YBCON_VERSION "UNKNOWN"
#endif
extern string getFileContent(const string& file); extern string getFileContent(const string& file);
extern void setOutputFileContent(const string& language, const string& file, const string& content); extern void setOutputFileContent(const string& language, const string& file, const string& content);
extern string parseString(unique_ptr<string> toParse); extern string parseString(unique_ptr<string> toParse);
extern string transpile(string toTranspile, string language); extern string transpile(string toTranspile, string language);
#include "headers/misc.hpp"
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
if ((argc == 2) && (((string) argv[1]) == "--version")) { cout << YBCON_VERSION << endl; exit(EXIT_SUCCESS); } if ((argc == 2) && (((string) argv[1]) == "--version")) { cout << getVersion() << endl; exit(EXIT_SUCCESS); }
string fileName = (argv[argc - 1] != nullptr) ? argv[argc - 1] : "none" ; string fileName = (argv[argc - 1] != nullptr) ? argv[argc - 1] : "none" ;
if (fileName != "none" and fileName.ends_with(".ybcon")) if (fileName != "none" and fileName.ends_with(".ybcon"))
{ {

View File

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