From a01f15e1cee3bf1d8c8008ec887de02197592c5c Mon Sep 17 00:00:00 2001 From: dx Date: Sat, 23 May 2020 21:37:32 +0100 Subject: +compile_file function This will read the file (filename) then compile it line by line. --- Compiler/src/compiler.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'Compiler/src') 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 +#include +#include #include 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 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("

"); + paragraphing = false; + } + else if (line[0] == '\0' || line[0] == '\n') + { + if (paragraphing) + v.push_back("

"); + else + v.push_back("

"); + 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; +} -- cgit v1.2.3-13-gbd6f