Start tokenizing markdown files
This commit is contained in:
parent
11a30a87a8
commit
6bf1b7179a
4 changed files with 62 additions and 7 deletions
|
@ -1,4 +1,6 @@
|
|||
#ifndef _CHIMNEY_HPP__
|
||||
#define _CHIMNEY_HPP__
|
||||
|
||||
#include <chimney/markdown.hpp>
|
||||
|
||||
#endif
|
||||
|
|
13
include/chimney/markdown.hpp
Normal file
13
include/chimney/markdown.hpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#ifndef _CHIMNEY_MARKDOWN_HPP__
|
||||
#define _CHIMNEY_MARKDOWN_HPP__
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace chimney {
|
||||
class MarkdownFile {
|
||||
public:
|
||||
MarkdownFile(std::string contents);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,21 +1,22 @@
|
|||
#include <algorithm>
|
||||
#include <chimney.hpp>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
/*
|
||||
* config stub
|
||||
* Configuration stub
|
||||
*/
|
||||
|
||||
std::vector<std::string> ignored_dirs { ".git" };
|
||||
std::vector<std::string> ignored_files { "README.md", "LICENSE" };
|
||||
|
||||
/*
|
||||
* argument parser stub
|
||||
* Argument parser stub
|
||||
*/
|
||||
|
||||
std::string dir = ".";
|
||||
|
@ -25,19 +26,19 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
/*
|
||||
* directory tree builder
|
||||
* Directory tree builder & compiler
|
||||
*/
|
||||
|
||||
auto entry = fs::recursive_directory_iterator(dir);
|
||||
|
||||
for(; entry != fs::recursive_directory_iterator(); entry++) {
|
||||
std::string filename = entry->path().filename();
|
||||
auto haystack = ignored_files;
|
||||
std::vector<std::string> haystack = ignored_files;
|
||||
|
||||
if(entry->is_directory()) {
|
||||
haystack = ignored_dirs;
|
||||
}
|
||||
|
||||
std::string filename = entry->path().filename();
|
||||
auto iter = std::find(haystack.begin(), haystack.end(), filename);
|
||||
bool ignored = iter != haystack.end();
|
||||
|
||||
|
@ -45,7 +46,11 @@ int main(int argc, char **argv) {
|
|||
entry.disable_recursion_pending();
|
||||
} else if(!entry->is_directory()) {
|
||||
if(entry->path().extension() == ".md") {
|
||||
// process markdown file
|
||||
std::ifstream reader { entry->path().c_str() };
|
||||
std::string contents(entry->file_size(), ' ');
|
||||
reader.read(&contents[0], entry->file_size());
|
||||
// Loading the file into memory might need a bit of refactoring.
|
||||
chimney::MarkdownFile md_file { contents };
|
||||
} else {
|
||||
// copy file to output directory
|
||||
}
|
||||
|
|
35
src/markdown.cpp
Normal file
35
src/markdown.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include <cctype>
|
||||
#include <chimney/markdown.hpp>
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
class MarkdownWord {
|
||||
public:
|
||||
bool start;
|
||||
bool end;
|
||||
std::string word;
|
||||
|
||||
MarkdownWord(bool start, bool end, std::string word)
|
||||
: start(start), end(end), word(word) { }
|
||||
};
|
||||
}
|
||||
|
||||
chimney::MarkdownFile::MarkdownFile(std::string contents) {
|
||||
std::vector<MarkdownWord> words;
|
||||
std::string word;
|
||||
bool start = true;
|
||||
|
||||
for(auto rune: contents) {
|
||||
if(!std::isspace(rune)) {
|
||||
word += rune;
|
||||
} else if(!word.empty()) {
|
||||
words.push_back(MarkdownWord {
|
||||
start, rune == '\n', word
|
||||
});
|
||||
|
||||
start = rune == '\n';
|
||||
word.clear();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue