#include #include #include #include #include #include #include #include #include #include #include #include "novelparser.h" #include "htmlprint.h" using namespace example_novel; int main(int argc, char* argv[]) { QCoreApplication a(argc, argv); try { QFileInfoList files; files.append(QFileInfo("D:\\Projects\\Cpp\\WsNovelParser\\x64\\test_file\\description.txt")); auto parser = std::make_shared(); auto novel_accesstree = parser->parse(files); printer::tools_printer tool; tool.build_fragments(novel_accesstree); tool.build_refers_network(novel_accesstree); tool.fragments_anchors_define(tool.fragment_defines.values(), QDir::current()); tool.storylines_anchors_define(tool.storyline_defines.values(), QDir::current()); tool.volumes_anchors_define(tool.volume_defines.values(), QDir::current()); std::function)> html_output = [](std::shared_ptr inst) { auto target_path = inst->pageRefers(); QFile tfile(target_path); if (tfile.open(QIODevice::WriteOnly | QIODevice::Text)) { QDomDocument doc_inst(QDomImplementation().createDocumentType(u8"html", QString(), QString())); auto html = doc_inst.createElement(u8"html"); doc_inst.appendChild(html); auto body = doc_inst.createElement(u8"body"); html.appendChild(body); inst->buildPageHTML(body); QTextStream tout(&tfile); doc_inst.save(tout, 2); tout.flush(); } }; for (auto& node : tool.fragment_defines) html_output(node); for (auto& node : tool.storyline_defines) html_output(node); for (auto& node : tool.volume_defines) html_output(node); std::function, int)> tnode_print = [&](std::shared_ptr node, int intend) { auto name = node->element()->signature(); auto text = QString(intend * 2, ' ') + name; for (auto& t : node->tokens()) { text += " " + t->token()->content(); } qDebug() << text; for (auto& c_n : node->children()) { tnode_print(c_n, intend + 1); } }; tnode_print(novel_accesstree, 0); } catch (lib_syntax::SyntaxException* e) { qDebug().noquote() << e->message(); delete e; } catch (lib_parse::CheckException* e) { qDebug().noquote() << e->message(); delete e; } return a.exec(); }