aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Compiler/includes/compiler.hpp1
-rw-r--r--Compiler/src/compiler.cpp45
2 files changed, 46 insertions, 0 deletions
diff --git a/Compiler/includes/compiler.hpp b/Compiler/includes/compiler.hpp
index d761dcf..bd97a8e 100644
--- a/Compiler/includes/compiler.hpp
+++ b/Compiler/includes/compiler.hpp
@@ -14,5 +14,6 @@ enum Type
};
std::string compile_line(const char *raw);
+std::string compile_file(const char *filename);
#endif // __COMPILER_H_
diff --git a/Compiler/src/compiler.cpp b/Compiler/src/compiler.cpp
index 1220457..4be30e0 100644
--- a/Compiler/src/compiler.cpp
+++ b/Compiler/src/compiler.cpp
@@ -1,4 +1,7 @@
#include "../includes/compiler.hpp"
+#include <vector>
+#include <iostream>
+#include <fstream>
#include <regex>
static const unsigned short N_ITEMS = 4;
@@ -39,3 +42,45 @@ std::string compile_line(const char *raw)
return result;
}
+
+std::string compile_file(const char *filename)
+{
+ std::vector<std::string> v;
+ std::ifstream fp(filename);
+
+ if (!fp.is_open())
+ {
+ std::cerr << "File " << filename << " not found" << std::endl;
+ exit(1);
+ }
+
+ bool paragraphing = false;
+ std::string line;
+ for (int i = 0; std::getline(fp, line) ; ++i) {
+ std::cout << "Compiled " << i + 1 << " of " << filename << "\n";
+ if (line[0] == '#' || line[0] == '-')
+ {
+ if (paragraphing)
+ v.push_back("</p>");
+ paragraphing = false;
+ }
+ else if (line[0] == '\0' || line[0] == '\n')
+ {
+ if (paragraphing)
+ v.push_back("</p>");
+ else
+ v.push_back("<p>");
+ paragraphing = !paragraphing;
+ continue;
+ }
+
+ v.push_back(compile_line(line.c_str()));
+ }
+ fp.close();
+
+ std::string result = "";
+ for (auto i : v)
+ result += i + "\n";
+
+ return result;
+}