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-07-12 22:47:28 +00:00
|
|
|
|
std::shared_ptr<lib_syntax::IContext> NovelParser::parserContext() const
|
|
|
|
|
{
|
|
|
|
|
return context;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<std::shared_ptr<const ast_basic::IExprInst>> NovelParser::parse(const QFileInfoList source_list) const {
|
|
|
|
|
const_cast<NovelParser*>(this)->context = std::make_shared<ast_gen::GlobalElement>(u8"С˵");
|
2024-06-20 13:36:46 +00:00
|
|
|
|
auto word_reader = std::make_shared<lib_token::WordReader>();
|
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) {
|
2024-06-20 13:36:46 +00:00
|
|
|
|
context->setCurrentFile(file.canonicalFilePath());
|
|
|
|
|
auto words = word_reader->wordsFrom(file.canonicalFilePath());
|
2024-07-12 04:53:43 +00:00
|
|
|
|
this->syntax_defines->parse(context, words);
|
2024-03-17 07:58:28 +00:00
|
|
|
|
}
|
2024-07-12 04:53:43 +00:00
|
|
|
|
|
2024-07-12 22:47:28 +00:00
|
|
|
|
QList<std::shared_ptr<const ast_basic::IExprInst>> forst_root = context->getDocInsts();
|
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-07-12 22:47:28 +00:00
|
|
|
|
return forst_root;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<const ast_gen::ElementAccess> NovelParser::validsApply(QList<std::shared_ptr<const ast_basic::IExprInst>> forst_root) const {
|
|
|
|
|
auto time_stamp = QTime::currentTime();
|
2024-06-18 03:54:36 +00:00
|
|
|
|
QList<std::shared_ptr<ast_gen::SyntaxElement>> docs_node;
|
2024-07-12 22:47:28 +00:00
|
|
|
|
for (auto& it : forst_root) {
|
2024-06-18 03:54:36 +00:00
|
|
|
|
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-07-12 22:47:28 +00:00
|
|
|
|
auto 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);
|
|
|
|
|
}
|
|
|
|
|
|