#include "novelparser.h" #include #include #include #include #include using namespace example_novel; using namespace lib_parse; NovelParser::NovelParser() { this->syntax_defines = NovalSyntax::getParseTree(); checker_list << std::make_shared(); checker_list << std::make_shared(); checker_list << std::make_shared(); analyzer_ref = std::make_shared(checker_list); } QList> NovelParser::fragmentsSorted() const { return std::dynamic_pointer_cast(checker_list[1])->fragmentsSequence(); } QString NovelParser::version() const { return "1.0.0"; } std::shared_ptr NovelParser::parse(const QFileInfoList source_list) const { QList> forst_root; auto word_reader = std::make_shared(); auto context = std::make_shared(u8"小说"); auto time_stamp = QTime::currentTime(); for (auto& file : source_list) { context->setCurrentFile(file.canonicalFilePath()); auto words = word_reader->wordsFrom(file.canonicalFilePath()); auto exprs_result = this->syntax_defines->parse(context, words); forst_root.append(std::get<0>(exprs_result)); } auto current_stamp = QTime::currentTime(); qDebug().noquote() << QString(u8"%词法解析+语法解析消耗时间:%1 ms。").arg(time_stamp.msecsTo(current_stamp)); time_stamp = QTime::currentTime(); QList> docs_node; for (auto &it : forst_root) { auto xitem = std::dynamic_pointer_cast(it); docs_node.append(std::const_pointer_cast(xitem)); context->addChild(docs_node.last()); } auto x_root = NovalSyntax::tidy(context, docs_node); auto novel_accesstree = std::make_shared(x_root); current_stamp = QTime::currentTime(); qDebug().noquote() << QString(u8"%程序结构重建消耗时间:%1 ms。").arg(time_stamp.msecsTo(current_stamp)); return analyzer_ref->validCheckWith(novel_accesstree); }