WsParser_VS/WsNovelParser/main.cpp

61 lines
1.8 KiB
C++
Raw Normal View History

2024-03-17 07:58:28 +00:00
#include <QtCore/QCoreApplication>
#include <QCoreApplication>
#include <QDebug>
#include <QFileInfoList>
#include <ast_gen.h>
#include <ast_novel.h>
#include <libtoken.h>
#include <syntax_novel.h>
#include <tokens_novel.h>
2024-03-31 05:59:17 +00:00
#include <QDir>
2024-03-17 07:58:28 +00:00
#include "novelparser.h"
2024-03-31 05:59:17 +00:00
#include "htmlprint.h"
2024-03-17 07:58:28 +00:00
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<NovelParser>();
auto novel_accesstree = parser->parse(files);
2024-03-31 05:59:17 +00:00
printer::tools_printer tool;
tool.build_fragments(novel_accesstree);
tool.build_refers_network(novel_accesstree);
2024-04-02 12:39:25 +00:00
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());
2024-03-31 05:59:17 +00:00
2024-03-17 07:58:28 +00:00
std::function<void(std::shared_ptr<const ast_gen::ElementAccess>, int)> tnode_print =
[&](std::shared_ptr<const ast_gen::ElementAccess> 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();
}