WsParser_VS/WsNovelParser/novelparser.cpp

63 lines
2.2 KiB
C++
Raw Normal View History

2024-03-17 07:58:28 +00:00
#include "novelparser.h"
#include <syntax_novel.h>
#include <ast_novel.h>
#include <parse_novel.h>
2024-06-15 01:18:33 +00:00
#include <QTime>
#include <QDebug>
2024-03-17 07:58:28 +00:00
using namespace example_novel;
2024-06-20 14:13:06 +00:00
using namespace lib_parse;
2024-03-17 07:58:28 +00:00
NovelParser::NovelParser()
{
2024-06-20 14:13:06 +00:00
this->syntax_defines = NovalSyntax::getParseTree();
checker_list << std::make_shared<FragmentExistsCheck>();
checker_list << std::make_shared<StoryOrderCheck>();
checker_list << std::make_shared<FragmentGraphCheck>();
2024-03-17 07:58:28 +00:00
2024-06-20 14:13:06 +00:00
analyzer_ref = std::make_shared<Analyzer>(checker_list);
}
QList<std::shared_ptr<const FragmentGraphHelper>> NovelParser::fragmentsSorted() const
{
return std::dynamic_pointer_cast<const FragmentGraphCheck>(checker_list[1])->fragmentsSequence();
2024-03-17 07:58:28 +00:00
}
QString NovelParser::version() const
{
return "1.0.0";
}
2024-06-15 15:08:23 +00:00
std::shared_ptr<const ast_gen::ElementAccess> NovelParser::parse(const QFileInfoList source_list) const {
QList<std::shared_ptr<const ast_basic::Expression>> forst_root;
auto word_reader = std::make_shared<lib_token::WordReader>();
auto context = std::make_shared<ast_gen::GlobalElement>(u8"С˵");
2024-03-17 07:58:28 +00:00
2024-06-15 01:18:33 +00:00
auto time_stamp = QTime::currentTime();
2024-03-17 07:58:28 +00:00
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);
2024-06-18 17:09:45 +00:00
forst_root.append(std::get<0>(exprs_result));
2024-03-17 07:58:28 +00:00
}
2024-06-15 01:18:33 +00:00
auto current_stamp = QTime::currentTime();
2024-06-22 15:19:14 +00:00
qDebug().noquote() << QString(u8"%<25>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD><EFBFBD>+<2B><EFBFBD><EFB7A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>䣺%1 ms<6D><73>").arg(time_stamp.msecsTo(current_stamp));
2024-03-17 07:58:28 +00:00
2024-06-15 01:18:33 +00:00
time_stamp = QTime::currentTime();
QList<std::shared_ptr<ast_gen::SyntaxElement>> docs_node;
for (auto &it : forst_root) {
auto xitem = std::dynamic_pointer_cast<const ast_gen::SyntaxElement>(it);
docs_node.append(std::const_pointer_cast<ast_gen::SyntaxElement>(xitem));
context->addChild(docs_node.last());
}
auto x_root = NovalSyntax::tidy(context, docs_node);
auto novel_accesstree = std::make_shared<ast_gen::ElementAccess>(x_root);
2024-06-15 01:18:33 +00:00
current_stamp = QTime::currentTime();
2024-06-22 15:19:14 +00:00
qDebug().noquote() << QString(u8"%<25><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؽ<EFBFBD><D8BD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>䣺%1 ms<6D><73>").arg(time_stamp.msecsTo(current_stamp));
2024-03-17 07:58:28 +00:00
return analyzer_ref->validCheckWith(novel_accesstree);
}