#include "novelparser.h" #include #include #include #include #include using namespace example_novel; using namespace lib_parse; NovelParser::NovelParser() { this->syntax_defines = NovalSyntax::getSyntaxTree(); 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::parserContext() const { return context; } QList> NovelParser::parse(const QFileInfoList source_list) const { const_cast(this)->context = std::make_shared(u8"小说"); auto word_reader = std::make_shared(); auto time_stamp = QTime::currentTime(); for (auto& file : source_list) { context->setCurrentFile(file.canonicalFilePath()); auto words = word_reader->wordsFrom(file.canonicalFilePath()); this->syntax_defines->parse(context, words); } QList> forst_root = context->getDocInsts(); auto current_stamp = QTime::currentTime(); qDebug().noquote() << QString(u8"%词法解析+语法解析消耗时间:%1 ms。").arg(time_stamp.msecsTo(current_stamp)); return forst_root; } std::shared_ptr NovelParser::validsApply(QList> forst_root) const { auto 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); auto current_stamp = QTime::currentTime(); qDebug().noquote() << QString(u8"%程序结构重建消耗时间:%1 ms。").arg(time_stamp.msecsTo(current_stamp)); return analyzer_ref->validCheckWith(novel_accesstree); }