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-04-04 05:18:44 +00:00
|
|
|
|
#include <QTextStream>
|
2024-04-20 03:34:33 +00:00
|
|
|
|
#include <iostream>
|
2024-06-15 01:18:33 +00:00
|
|
|
|
#include <QTime>
|
2024-06-22 10:53:51 +00:00
|
|
|
|
#include <argsparser.h>
|
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;
|
|
|
|
|
|
2024-06-05 00:27:34 +00:00
|
|
|
|
/*
|
|
|
|
|
* nsc --help
|
2024-06-22 10:53:51 +00:00
|
|
|
|
* nsc -[pw] --path path-to-dir [--out path-to-dir]
|
2024-06-05 00:27:34 +00:00
|
|
|
|
* opts:
|
2024-06-22 10:53:51 +00:00
|
|
|
|
* p print-struct <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ṹ
|
|
|
|
|
* w print-web <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>webҳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
|
2024-06-05 00:27:34 +00:00
|
|
|
|
*/
|
2024-03-17 07:58:28 +00:00
|
|
|
|
int main(int argc, char* argv[]) {
|
2024-04-05 12:51:20 +00:00
|
|
|
|
QCoreApplication a(argc, argv);
|
2024-03-17 07:58:28 +00:00
|
|
|
|
|
2024-06-22 10:53:51 +00:00
|
|
|
|
args_parse::ArgsParser args_parser;
|
|
|
|
|
QList<std::shared_ptr<args_parse::ArgvPack>> args_mode;
|
|
|
|
|
args_mode << std::make_shared<args_parse::IndexParam>(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
args_mode << std::make_shared<args_parse::FloatOption>(u8"--help", u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
args_parser.loadMode(0x000Au, args_mode);
|
|
|
|
|
|
|
|
|
|
args_mode.clear();
|
|
|
|
|
args_mode << std::make_shared<args_parse::IndexParam>(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
args_mode << std::make_shared<args_parse::FloatArgvPack>(u8"--path", u8"Դ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼");
|
2024-06-23 02:50:38 +00:00
|
|
|
|
args_mode << std::make_shared<args_parse::FloatArgvPack>(u8"--dest", u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼");
|
2024-06-22 10:53:51 +00:00
|
|
|
|
args_mode << std::make_shared<args_parse::FloatOption>(u8"--html", u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>html<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>ʽȡ<EFBFBD><EFBFBD>AST", true);
|
|
|
|
|
args_parser.loadMode(0x000Bu, args_mode);
|
2024-06-05 04:12:31 +00:00
|
|
|
|
|
2024-06-22 10:53:51 +00:00
|
|
|
|
|
|
|
|
|
auto parse_result = args_parser.parse(argc, argv);
|
2024-06-23 02:50:38 +00:00
|
|
|
|
switch (std::get<0>(parse_result)) {
|
2024-06-22 10:53:51 +00:00
|
|
|
|
case 0xBu: {
|
|
|
|
|
auto args = std::get<1>(parse_result);
|
|
|
|
|
auto src_dir = std::dynamic_pointer_cast<args_parse::FloatArgvPack>(args_mode[1]);
|
|
|
|
|
auto dst_dir = std::dynamic_pointer_cast<args_parse::FloatArgvPack>(args_mode[2]);
|
2024-06-22 15:19:14 +00:00
|
|
|
|
auto html_opt = std::dynamic_pointer_cast<args_parse::FloatOption>(args_mode[3]);
|
2024-06-22 10:53:51 +00:00
|
|
|
|
|
|
|
|
|
auto source_dir = QDir(src_dir->value());
|
|
|
|
|
if (!source_dir.exists()) {
|
2024-06-23 02:50:38 +00:00
|
|
|
|
std::cout << "%<25><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>Ŀ¼<C4BF><C2BC><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD>" << std::endl;
|
2024-06-22 10:53:51 +00:00
|
|
|
|
exit(0);
|
2024-06-05 04:12:31 +00:00
|
|
|
|
}
|
2024-06-22 10:53:51 +00:00
|
|
|
|
auto destination_dir = QDir::current();
|
|
|
|
|
auto target_output = dst_dir->value();
|
|
|
|
|
if (!target_output.isEmpty() && QDir(target_output).exists()) {
|
|
|
|
|
destination_dir = QDir(target_output);
|
|
|
|
|
}
|
2024-06-22 15:19:14 +00:00
|
|
|
|
else {
|
2024-06-23 02:50:38 +00:00
|
|
|
|
std::cout << "%<25><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼<C4BF><C2BC><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>" << destination_dir.absolutePath().toLocal8Bit().data() << std::endl;
|
2024-06-05 04:12:31 +00:00
|
|
|
|
}
|
2024-03-17 07:58:28 +00:00
|
|
|
|
|
2024-06-22 10:53:51 +00:00
|
|
|
|
auto files = source_dir.entryInfoList(QStringList() << "*.story");
|
|
|
|
|
std::shared_ptr<const ast_gen::ElementAccess> access_ptr = nullptr;
|
|
|
|
|
if (files.size()) {
|
|
|
|
|
try {
|
|
|
|
|
auto parser = std::make_shared<NovelParser>();
|
2024-07-12 22:47:28 +00:00
|
|
|
|
auto docs = parser->parse(files);
|
2024-07-12 09:35:35 +00:00
|
|
|
|
|
2024-07-12 22:47:28 +00:00
|
|
|
|
auto errors_list = parser->parserContext()->errors();
|
2024-07-12 09:35:35 +00:00
|
|
|
|
if (errors_list.size()) {
|
|
|
|
|
for (auto& err : errors_list) {
|
|
|
|
|
qDebug().noquote() << err;
|
|
|
|
|
}
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
2024-07-12 22:47:28 +00:00
|
|
|
|
access_ptr = parser->validsApply(docs);
|
2024-06-22 10:53:51 +00:00
|
|
|
|
}
|
|
|
|
|
catch (lib_syntax::SyntaxException* e) {
|
|
|
|
|
qDebug().noquote() << e->message();
|
|
|
|
|
delete e;
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
catch (lib_parse::CheckException* e) {
|
|
|
|
|
qDebug().noquote() << e->message();
|
|
|
|
|
delete e;
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-15 01:18:33 +00:00
|
|
|
|
|
2024-06-22 15:19:14 +00:00
|
|
|
|
if (html_opt->value().toInt() == 1 && access_ptr) {
|
2024-04-05 12:51:20 +00:00
|
|
|
|
printer::tools_printer tool;
|
2024-07-12 23:13:56 +00:00
|
|
|
|
tool.plain_html_output(access_ptr, destination_dir);
|
2024-04-05 12:51:20 +00:00
|
|
|
|
}
|
2024-06-22 15:19:14 +00:00
|
|
|
|
else if (access_ptr) {
|
2024-06-23 02:50:38 +00:00
|
|
|
|
QTime time_stamp = QTime::currentTime();
|
2024-06-22 15:19:14 +00:00
|
|
|
|
lib_parse::VisitorControl control;
|
2024-09-22 02:18:33 +00:00
|
|
|
|
auto visitor = std::make_shared<printer::AstGenerate>(source_dir);
|
2024-06-22 15:19:14 +00:00
|
|
|
|
control.visitWith(access_ptr, visitor);;
|
|
|
|
|
auto dom_result = visitor->content();
|
2024-06-23 02:28:13 +00:00
|
|
|
|
QFile file(destination_dir.absoluteFilePath(u8"storyline.xast"));
|
|
|
|
|
if (file.open(QIODevice::Text | QIODevice::WriteOnly)) {
|
|
|
|
|
QTextStream tout(&file);
|
|
|
|
|
tout.setCodec("UTF-8");
|
|
|
|
|
tout << dom_result;
|
|
|
|
|
tout.flush();
|
|
|
|
|
}
|
2024-06-23 02:50:38 +00:00
|
|
|
|
auto current_stamp = QTime::currentTime();
|
|
|
|
|
qDebug().noquote() << QString(u8"%AST<53><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>䣺%1 ms<6D><73>").arg(time_stamp.msecsTo(current_stamp));
|
|
|
|
|
qDebug().noquote() << QString(u8"%<25><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD>%1<><31>").arg(QFileInfo(file).absoluteFilePath());
|
2024-06-22 15:19:14 +00:00
|
|
|
|
}
|
2024-06-22 10:53:51 +00:00
|
|
|
|
}break;
|
2024-06-23 02:50:38 +00:00
|
|
|
|
case 0xAu:
|
|
|
|
|
default: {
|
|
|
|
|
std::cout << "nsc(WsNovelStoryCompiler<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߱<EFBFBD><DFB1><EFBFBD><EFBFBD><EFBFBD>)" << std::endl;
|
|
|
|
|
std::cout << "<EFBFBD>汾<EFBFBD><EFBFBD>V1.0.0" << std::endl;
|
2024-06-24 13:25:41 +00:00
|
|
|
|
std::cout << "nsc --path path-to-dir --dest path-to-output [--html]" << std::endl;
|
2024-07-13 05:17:56 +00:00
|
|
|
|
std::cout << "nsc --help" << std::endl;
|
2024-06-23 02:50:38 +00:00
|
|
|
|
}break;
|
2024-04-05 12:51:20 +00:00
|
|
|
|
}
|
2024-05-26 04:11:45 +00:00
|
|
|
|
//return a.exec();
|
2024-06-23 02:50:38 +00:00
|
|
|
|
return 0;
|
2024-03-17 07:58:28 +00:00
|
|
|
|
}
|