This commit is contained in:
codeboss 2025-02-15 23:47:42 +08:00
parent 8c902fca46
commit b4e1f2a34c
19 changed files with 603 additions and 525 deletions

View File

@ -63,6 +63,12 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="Configuration"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="Configuration">
<ClCompile> <ClCompile>
<MultiProcessorCompilation>true</MultiProcessorCompilation> <MultiProcessorCompilation>true</MultiProcessorCompilation>

View File

@ -6,7 +6,7 @@ using namespace std;
__ArgvPackImpls::__ArgvPackImpls(const QString& means, ParamType t) : means_store(means), type_store(t) { } __ArgvPackImpls::__ArgvPackImpls(const QString& means, ParamType t) : means_store(means), type_store(t) { }
// 通过 IArgvPack 继承 // 通过 IArgvPack 继承
ParamType __ArgvPackImpls::paramType() const { ParamType __ArgvPackImpls::paramType() const {
return type_store; return type_store;
} }
@ -49,7 +49,7 @@ bool FloatKeyValue::parse(const QList<QString> args) {
return false; return false;
auto args_t = args[0]; auto args_t = args[0];
if (args_t == u8"--" + bindKey()) { if (args_t == "--" + bindKey()) {
auto args_v = args[1]; auto args_v = args[1];
setValue(args_v); setValue(args_v);
return true; return true;
@ -97,7 +97,7 @@ bool FloatOption::parse(const QList<QString> args) {
return false; return false;
auto args_t = args[0]; auto args_t = args[0];
if (args_t == u8"--" + bindKey()) { if (args_t == "--" + bindKey()) {
setValue(true); setValue(true);
return true; return true;
} }
@ -108,8 +108,8 @@ MatchMode::MatchMode(int mode_code, const QString& mode)
:_means_explain(mode), code_store(mode_code) { } :_means_explain(mode), code_store(mode_code) { }
/** /**
* @brief * @brief
* @return * @return
*/ */
MatchMode& MatchMode::operator<<(std::shared_ptr<IArgvPack> unit) { MatchMode& MatchMode::operator<<(std::shared_ptr<IArgvPack> unit) {
@ -119,7 +119,7 @@ MatchMode& MatchMode::operator<<(std::shared_ptr<IArgvPack> unit) {
if (u_exist->paramType() == ParamType::FloatParam) { if (u_exist->paramType() == ParamType::FloatParam) {
auto u_cast = std::dynamic_pointer_cast<__FloatArgvImpls>(u_exist); auto u_cast = std::dynamic_pointer_cast<__FloatArgvImpls>(u_exist);
if (u_cast->bindKey() == unit_in->bindKey()) if (u_cast->bindKey() == unit_in->bindKey())
throw new std::exception("重复设置选项"); throw new std::exception("重复设置选项");
} }
} }
} }
@ -135,14 +135,14 @@ int MatchMode::modeCode() const {
QString MatchMode::usageString() const { QString MatchMode::usageString() const {
QString usage_string; QString usage_string;
for (auto& item : args_mode) for (auto& item : args_mode)
usage_string += item->placeHolder() + u8" "; usage_string += item->placeHolder() + " ";
return usage_string; return usage_string;
} }
QString MatchMode::explanString() const { QString MatchMode::explanString() const {
QStringList sections; QStringList sections;
sections << u8" " + _means_explain; sections << " " + _means_explain;
sections << QString(" Switch:"); sections << QString(" Switch:");
for (auto& item : args_mode) { for (auto& item : args_mode) {
@ -163,7 +163,7 @@ QString MatchMode::explanString() const {
} }
/** /**
* @brief * @brief
*/ */
bool MatchMode::parse(const QList<QString>& args) { bool MatchMode::parse(const QList<QString>& args) {
@ -247,14 +247,14 @@ ArgsParser& ArgsParser::operator<<(std::shared_ptr<MatchMode> mode) {
} }
std::shared_ptr<MatchMode> ArgsParser::parse(int argc, char* argv[]) { std::shared_ptr<MatchMode> ArgsParser::parse(int argc, char* argv[]) {
// 聚合参数数组 // 聚合参数数组
QList<QString> args_list; QList<QString> args_list;
for (int idx = 0; idx < argc; idx++) { for (int idx = 0; idx < argc; idx++) {
auto argv_str = QString::fromLocal8Bit(argv[idx]); auto argv_str = QString::fromLocal8Bit(argv[idx]);
args_list.append(argv_str); args_list.append(argv_str);
} }
// 枚举模式匹配 // 枚举模式匹配
for (auto& minst : this->match_modes) { for (auto& minst : this->match_modes) {
if (minst->parse(args_list)) if (minst->parse(args_list))
return minst; return minst;

View File

@ -10,7 +10,7 @@
namespace args_parse { namespace args_parse {
/** /**
* . * .
*/ */
enum class ParamType { enum class ParamType {
IndexParam, IndexParam,
@ -18,37 +18,37 @@ namespace args_parse {
}; };
/** /**
* @brief . * @brief .
*/ */
class IArgvPack { class IArgvPack {
public: public:
virtual ~IArgvPack() = default; virtual ~IArgvPack() = default;
/** /**
* . * .
* *
* \return * \return
*/ */
virtual ParamType paramType() const = 0; virtual ParamType paramType() const = 0;
/** /**
* @brief . * @brief .
* *
* \return * \return
*/ */
virtual QString means() const = 0; virtual QString means() const = 0;
virtual QString placeHolder(bool decorate = true) const = 0; virtual QString placeHolder(bool decorate = true) const = 0;
virtual QVariant value() const = 0; virtual QVariant value() const = 0;
/** /**
* @brief . * @brief .
* *
* \return * \return
*/ */
virtual int matchLenth() const = 0; virtual int matchLenth() const = 0;
/** /**
* @brief . * @brief .
* *
* \param argv * \param argv
* \param start * \param start
* \return * \return
*/ */
virtual bool parse(const QList<QString> args) = 0; virtual bool parse(const QList<QString> args) = 0;
}; };
@ -64,7 +64,7 @@ namespace args_parse {
void setValue(const QVariant &v); void setValue(const QVariant &v);
// 通过 IArgvPack 继承 // 通过 IArgvPack 继承
ParamType paramType() const override; ParamType paramType() const override;
QString means() const override; QString means() const override;
QVariant value() const override; QVariant value() const override;
@ -83,17 +83,17 @@ namespace args_parse {
}; };
/** /**
* @brief key-value解析匹配模式. * @brief key-value解析匹配模式.
* --key value * --key value
*/ */
class ARGSPARSER_EXPORT FloatKeyValue : public __FloatArgvImpls { class ARGSPARSER_EXPORT FloatKeyValue : public __FloatArgvImpls {
public: public:
/** /**
* key-value解析单元. * key-value解析单元.
* *
* \param key * \param key
* \param means * \param means
* \param optional * \param optional
*/ */
explicit FloatKeyValue(const QString& key, const QString &means, bool optional = false); explicit FloatKeyValue(const QString& key, const QString &means, bool optional = false);
virtual ~FloatKeyValue() = default; virtual ~FloatKeyValue() = default;
@ -104,17 +104,17 @@ namespace args_parse {
}; };
/** /**
* @brief key解析匹配模式. * @brief key解析匹配模式.
* --key * --key
*/ */
class ARGSPARSER_EXPORT FloatOption : public __FloatArgvImpls { class ARGSPARSER_EXPORT FloatOption : public __FloatArgvImpls {
public: public:
/** /**
* option解析单元. * option解析单元.
* *
* \param key * \param key
* \param means * \param means
* \param optional * \param optional
*/ */
explicit FloatOption(const QString& key, const QString& means, bool optional = false); explicit FloatOption(const QString& key, const QString& means, bool optional = false);
virtual ~FloatOption() = default; virtual ~FloatOption() = default;
@ -125,7 +125,7 @@ namespace args_parse {
}; };
/** /**
* . * .
*/ */
class ARGSPARSER_EXPORT IndexParam : public __ArgvPackImpls { class ARGSPARSER_EXPORT IndexParam : public __ArgvPackImpls {
private: private:
@ -135,7 +135,7 @@ namespace args_parse {
explicit IndexParam(const QString & place_v, const QString &means); explicit IndexParam(const QString & place_v, const QString &means);
virtual ~IndexParam() = default; virtual ~IndexParam() = default;
// 通过 __ArgvPackImpls 继承 // 通过 __ArgvPackImpls 继承
virtual QString placeHolder(bool decorate = true) const override; virtual QString placeHolder(bool decorate = true) const override;
int matchLenth() const override; int matchLenth() const override;
bool parse(const QList<QString> args) override; bool parse(const QList<QString> args) override;
@ -152,27 +152,27 @@ namespace args_parse {
explicit MatchMode(int mode_code, const QString &explain); explicit MatchMode(int mode_code, const QString &explain);
/** /**
* @brief * @brief
* @return * @return
*/ */
int modeCode()const; int modeCode()const;
/** /**
* . * .
* *
* \return * \return
*/ */
QString usageString() const; QString usageString() const;
/** /**
* . * .
* *
* \return * \return
*/ */
QString explanString() const; QString explanString() const;
/** /**
* . * .
* *
* \param unit * \param unit
* \return * \return
@ -180,12 +180,12 @@ namespace args_parse {
MatchMode& operator<<(std::shared_ptr<IArgvPack> unit); MatchMode& operator<<(std::shared_ptr<IArgvPack> unit);
/** /**
* @brief * @brief
*/ */
bool parse(const QList<QString>& args); bool parse(const QList<QString>& args);
/** /**
* . * .
* *
* \param key * \param key
* \return * \return

View File

@ -10,11 +10,13 @@
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
QCoreApplication a(argc, argv); QCoreApplication a(argc, argv);
QFile in("D:\\Projects\\Cpp\\WsNovelParser\\CoreTest\\syntax_example.txt");
QFile in("D:\\Projects\\Cpp\\WsNovelParser\\x64\\test_file\\description - 副本.story");
in.open(QIODevice::ReadOnly | QIODevice::Text); in.open(QIODevice::ReadOnly | QIODevice::Text);
QTextStream tt(&in); QTextStream tt(&in);
tt.setCodec("UTF-8");
lib_words::WordReader reader; lib_words::WordReader reader;
auto vwords = reader.wordsFrom(tt, "D:\\Projects\\Cpp\\WsNovelParser\\CoreTest\\syntax_example.txt"); auto vwords = reader.wordsFrom(tt, "D:\\Projects\\Cpp\\WsNovelParser\\x64\\test_file\\description - 副本.story");
ast_gen::SyntaxParser parser(example_novel::NovalSyntax::getSyntaxTree()); ast_gen::SyntaxParser parser(example_novel::NovalSyntax::getSyntaxTree());
auto rst = parser.parse(vwords); auto rst = parser.parse(vwords);

View File

@ -14,24 +14,24 @@
故事介绍段落 aldkfjl flwief 故事介绍段落 aldkfjl flwief
} }
{故事 故事名称4 {故事 故事名称5
故事介绍段落 aldkfjl flwief 故事介绍段落 aldkfjl flwief
{剧情 剧情名称} {剧情 剧情名称}
} }
{故事 故事名称4 {故事 故事名称6
故事介绍段落 aldkfjl flwief 故事介绍段落 aldkfjl flwief
{剧情 剧情名称 剧情介绍} {剧情 剧情名称 剧情介绍}
} }
{故事 故事名称4 {故事 故事名称7
故事介绍段落 aldkfjl flwief 故事介绍段落 aldkfjl flwief
{剧情 剧情名称 {剧情 剧情名称
剧情介绍 剧情介绍
} }
} }
{故事 故事名称4 {故事 故事名称8
故事介绍段落 aldkfjl flwief 故事介绍段落 aldkfjl flwief
{剧情 剧情名称 {剧情 剧情名称
剧情介绍 剧情介绍
@ -39,7 +39,7 @@
} }
} }
{故事 故事名称4 {故事 故事名称9
故事介绍段落 aldkfjl flwief 故事介绍段落 aldkfjl flwief
{剧情 剧情名称 {剧情 剧情名称
剧情介绍 剧情介绍
@ -48,7 +48,7 @@
} }
} }
{故事 故事名称4 {故事 故事名称10
故事介绍段落 aldkfjl flwief 故事介绍段落 aldkfjl flwief
{剧情 剧情名称 {剧情 剧情名称
剧情介绍 剧情介绍
@ -58,6 +58,17 @@
} }
} }
{故事 故事名称11
故事介绍段落 aldkfjl flwief
{剧情 剧情名称
剧情介绍
{节点 节点名称
奥龙订饭;爱领克 非两爱看扥
}
{@节点 故事名称10&剧情名称&节点名称}
}
}
{故事 故事名称4 {故事 故事名称4
故事介绍段落 aldkfjl flwief 故事介绍段落 aldkfjl flwief
{剧情 剧情名称 {剧情 剧情名称
@ -65,18 +76,7 @@
{节点 节点名称 {节点 节点名称
奥龙订饭;爱领克 非两爱看扥 奥龙订饭;爱领克 非两爱看扥
} }
{@节点 节点面&发来垦局&零件扥} {@节点 故事名称10&剧情名称&节点名称
}
}
{故事 故事名称4
故事介绍段落 aldkfjl flwief
{剧情 剧情名称
剧情介绍
{节点 节点名称
奥龙订饭;爱领克 非两爱看扥
}
{@节点 节点面&发来垦局&零件扥
asldkfj 来看房莱肯} asldkfj 来看房莱肯}
} }
} }
@ -88,7 +88,7 @@
{节点 节点名称 {节点 节点名称
奥龙订饭;爱领克 非两爱看扥 奥龙订饭;爱领克 非两爱看扥
} }
{@节点 节点面&发来垦局&零件扥 {@节点 故事名称10&剧情名称&节点名称
asldkfj 来看房莱肯 asldkfj 来看房莱肯
} }
} }
@ -116,14 +116,14 @@
{分卷 卷宗名称 {分卷 卷宗名称
拉开茯苓领赛季发啦肯 lakdjf;alfj 拉开茯苓领赛季发啦肯 lakdjf;alfj
{章节 章节名称 昂来看申领发 {章节 章节名称 昂来看申领发
{@节点 故事&剧情&节点} {@节点 故事名称10&剧情名称&节点名称}
} }
} }
{分卷 卷宗名称 {分卷 卷宗名称
拉开茯苓领赛季发啦肯 lakdjf;alfj 拉开茯苓领赛季发啦肯 lakdjf;alfj
{章节 章节名称 昂来看申领发 {章节 章节名称 昂来看申领发
{@节点 故事&剧情&节点 爱;莱肯爱;冷 {@节点 故事名称10&剧情名称&节点名称
森铃但凡拉动垦局} 森铃但凡拉动垦局}
} }
} }

View File

@ -6,6 +6,7 @@ MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WsNovelParser", "WsNovelParser\WsNovelParser.vcxproj", "{1EF577E8-D92D-4926-9207-1567137BB672}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WsNovelParser", "WsNovelParser\WsNovelParser.vcxproj", "{1EF577E8-D92D-4926-9207-1567137BB672}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{1FF80476-26C9-42FB-BFF6-D587C4941964} = {1FF80476-26C9-42FB-BFF6-D587C4941964} {1FF80476-26C9-42FB-BFF6-D587C4941964} = {1FF80476-26C9-42FB-BFF6-D587C4941964}
{386F6D42-C6EB-4973-9511-181472391B21} = {386F6D42-C6EB-4973-9511-181472391B21}
{C3AADEB5-3695-4DF4-B8E1-D37F928F3B2F} = {C3AADEB5-3695-4DF4-B8E1-D37F928F3B2F} {C3AADEB5-3695-4DF4-B8E1-D37F928F3B2F} = {C3AADEB5-3695-4DF4-B8E1-D37F928F3B2F}
{EF557F71-99AA-4F2B-A5F5-1A4518A11C19} = {EF557F71-99AA-4F2B-A5F5-1A4518A11C19} {EF557F71-99AA-4F2B-A5F5-1A4518A11C19} = {EF557F71-99AA-4F2B-A5F5-1A4518A11C19}
EndProjectSection EndProjectSection
@ -17,6 +18,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libSyntax", "libSyntax\libS
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libParse", "libParse\libParse.vcxproj", "{C3AADEB5-3695-4DF4-B8E1-D37F928F3B2F}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libParse", "libParse\libParse.vcxproj", "{C3AADEB5-3695-4DF4-B8E1-D37F928F3B2F}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{386F6D42-C6EB-4973-9511-181472391B21} = {386F6D42-C6EB-4973-9511-181472391B21}
{EF557F71-99AA-4F2B-A5F5-1A4518A11C19} = {EF557F71-99AA-4F2B-A5F5-1A4518A11C19} {EF557F71-99AA-4F2B-A5F5-1A4518A11C19} = {EF557F71-99AA-4F2B-A5F5-1A4518A11C19}
EndProjectSection EndProjectSection
EndProject EndProject
@ -28,13 +30,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "解决方案项", "解决
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ArgsParser", "ArgsParser\ArgsParser.vcxproj", "{1FF80476-26C9-42FB-BFF6-D587C4941964}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ArgsParser", "ArgsParser\ArgsParser.vcxproj", "{1FF80476-26C9-42FB-BFF6-D587C4941964}"
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "StoryPresent", "StoryPresent\StoryPresent.vcxproj", "{48DA8516-26EA-4D59-8913-7EF28E3F87C3}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WsNovelManager", "WsNovelManager\WsNovelManager.vcxproj", "{DD802A96-BBB6-47CD-9B64-3582FD1805F3}"
ProjectSection(ProjectDependencies) = postProject
{1FF80476-26C9-42FB-BFF6-D587C4941964} = {1FF80476-26C9-42FB-BFF6-D587C4941964}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libWords", "libWords\libWords.vcxproj", "{386F6D42-C6EB-4973-9511-181472391B21}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libWords", "libWords\libWords.vcxproj", "{386F6D42-C6EB-4973-9511-181472391B21}"
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CoreTest", "CoreTest\CoreTest.vcxproj", "{9B3EEB2A-26D7-4B2C-B890-505715283400}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CoreTest", "CoreTest\CoreTest.vcxproj", "{9B3EEB2A-26D7-4B2C-B890-505715283400}"
@ -83,22 +78,6 @@ Global
{1FF80476-26C9-42FB-BFF6-D587C4941964}.Release|x64.Build.0 = Release|x64 {1FF80476-26C9-42FB-BFF6-D587C4941964}.Release|x64.Build.0 = Release|x64
{1FF80476-26C9-42FB-BFF6-D587C4941964}.Release|x86.ActiveCfg = Release|x64 {1FF80476-26C9-42FB-BFF6-D587C4941964}.Release|x86.ActiveCfg = Release|x64
{1FF80476-26C9-42FB-BFF6-D587C4941964}.Release|x86.Build.0 = Release|x64 {1FF80476-26C9-42FB-BFF6-D587C4941964}.Release|x86.Build.0 = Release|x64
{48DA8516-26EA-4D59-8913-7EF28E3F87C3}.Debug|x64.ActiveCfg = Debug|x64
{48DA8516-26EA-4D59-8913-7EF28E3F87C3}.Debug|x64.Build.0 = Debug|x64
{48DA8516-26EA-4D59-8913-7EF28E3F87C3}.Debug|x86.ActiveCfg = Debug|x64
{48DA8516-26EA-4D59-8913-7EF28E3F87C3}.Debug|x86.Build.0 = Debug|x64
{48DA8516-26EA-4D59-8913-7EF28E3F87C3}.Release|x64.ActiveCfg = Release|x64
{48DA8516-26EA-4D59-8913-7EF28E3F87C3}.Release|x64.Build.0 = Release|x64
{48DA8516-26EA-4D59-8913-7EF28E3F87C3}.Release|x86.ActiveCfg = Release|x64
{48DA8516-26EA-4D59-8913-7EF28E3F87C3}.Release|x86.Build.0 = Release|x64
{DD802A96-BBB6-47CD-9B64-3582FD1805F3}.Debug|x64.ActiveCfg = Debug|x64
{DD802A96-BBB6-47CD-9B64-3582FD1805F3}.Debug|x64.Build.0 = Debug|x64
{DD802A96-BBB6-47CD-9B64-3582FD1805F3}.Debug|x86.ActiveCfg = Debug|x64
{DD802A96-BBB6-47CD-9B64-3582FD1805F3}.Debug|x86.Build.0 = Debug|x64
{DD802A96-BBB6-47CD-9B64-3582FD1805F3}.Release|x64.ActiveCfg = Release|x64
{DD802A96-BBB6-47CD-9B64-3582FD1805F3}.Release|x64.Build.0 = Release|x64
{DD802A96-BBB6-47CD-9B64-3582FD1805F3}.Release|x86.ActiveCfg = Release|x64
{DD802A96-BBB6-47CD-9B64-3582FD1805F3}.Release|x86.Build.0 = Release|x64
{386F6D42-C6EB-4973-9511-181472391B21}.Debug|x64.ActiveCfg = Debug|x64 {386F6D42-C6EB-4973-9511-181472391B21}.Debug|x64.ActiveCfg = Debug|x64
{386F6D42-C6EB-4973-9511-181472391B21}.Debug|x64.Build.0 = Debug|x64 {386F6D42-C6EB-4973-9511-181472391B21}.Debug|x64.Build.0 = Debug|x64
{386F6D42-C6EB-4973-9511-181472391B21}.Debug|x86.ActiveCfg = Debug|x64 {386F6D42-C6EB-4973-9511-181472391B21}.Debug|x86.ActiveCfg = Debug|x64

View File

@ -61,7 +61,7 @@
</ImportGroup> </ImportGroup>
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<IncludePath>$(SolutionDir)libToken;$(SolutionDir)libSyntax;$(SolutionDir)ArgsParser;$(SolutionDir)libParse;$(IncludePath)</IncludePath> <IncludePath>$(SolutionDir)libWords;$(SolutionDir)libSyntax;$(SolutionDir)ArgsParser;$(SolutionDir)libParse;$(IncludePath)</IncludePath>
<LibraryPath>$(SolutionDir)$(Platform)\$(Configuration)\;$(LibraryPath)</LibraryPath> <LibraryPath>$(SolutionDir)$(Platform)\$(Configuration)\;$(LibraryPath)</LibraryPath>
<TargetName>nsc</TargetName> <TargetName>nsc</TargetName>
</PropertyGroup> </PropertyGroup>
@ -72,10 +72,11 @@
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Link> <Link>
<AdditionalDependencies>libToken.lib;libSyntax.lib;libParse.lib;ArgsParser.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>libWords.lib;libSyntax.lib;libParse.lib;ArgsParser.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
<ClCompile> <ClCompile>
<LanguageStandard>Default</LanguageStandard> <LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile> </ClCompile>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">

View File

@ -3,7 +3,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerWorkingDirectory>$(SolutionDir)$(Platform)\$(Configuration)\</LocalDebuggerWorkingDirectory> <LocalDebuggerWorkingDirectory>$(SolutionDir)$(Platform)\$(Configuration)\</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommandArguments>--path "D:\CustomNovels\科学+修仙+创造世界" --dest E:\</LocalDebuggerCommandArguments> <LocalDebuggerCommandArguments>--path "D:\Projects\Cpp\WsNovelParser\x64\test_file" --dest E:\</LocalDebuggerCommandArguments>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerCommandArguments>--path "D:\CustomNovels\科学+修仙+创造世界" --dest E:\</LocalDebuggerCommandArguments> <LocalDebuggerCommandArguments>--path "D:\CustomNovels\科学+修仙+创造世界" --dest E:\</LocalDebuggerCommandArguments>

File diff suppressed because it is too large Load Diff

View File

@ -9,7 +9,7 @@
namespace printer { namespace printer {
/* /*
* @brief 访线 * @brief 访线
*/ */
class Access : public std::enable_shared_from_this<Access> { class Access : public std::enable_shared_from_this<Access> {
public: public:
@ -17,20 +17,20 @@ namespace printer {
virtual ~Access() = default; virtual ~Access() = default;
/* /*
* @brief * @brief
* @return * @return
*/ */
std::shared_ptr<const ast_gen::ElementAccess> accessPeers() const; std::shared_ptr<const ast_gen::ElementAccess> accessPeers() const;
/* /*
* @brief * @brief
* @param href * @param href
*/ */
void setPageRefers(const QString& href); void setPageRefers(const QString& href);
QString pageRefers() const; QString pageRefers() const;
/* /*
* @brief HTML * @brief HTML
*/ */
virtual void buildPageHTML(QDomElement& doc) const = 0; virtual void buildPageHTML(QDomElement& doc) const = 0;
@ -40,7 +40,7 @@ namespace printer {
}; };
/* /*
* @brief 访 * @brief 访
*/ */
class Element : public Access { class Element : public Access {
public: public:
@ -48,13 +48,13 @@ namespace printer {
virtual ~Element() = default; virtual ~Element() = default;
/* /*
* @brief URL * @brief URL
*/ */
virtual void setSliceRefer(const QString& href); virtual void setSliceRefer(const QString& href);
virtual QString sliceRefers() const; virtual QString sliceRefers() const;
/* /*
* @brief HTML * @brief HTML
*/ */
virtual void buildSliceHTML(QDomElement &doc) const = 0; virtual void buildSliceHTML(QDomElement &doc) const = 0;
@ -63,7 +63,7 @@ namespace printer {
}; };
/* /*
* @brief 访线 * @brief 访线
*/ */
class Group : public Access { class Group : public Access {
public: public:
@ -82,7 +82,7 @@ namespace printer {
public: public:
StoryLine(std::shared_ptr<const ast_gen::ElementAccess> handle); StoryLine(std::shared_ptr<const ast_gen::ElementAccess> handle);
// 通过 Group 继承 // 通过 Group 继承
void buildPageHTML(QDomElement& doc) const override; void buildPageHTML(QDomElement& doc) const override;
}; };
@ -91,13 +91,13 @@ namespace printer {
public: public:
StoryVolume(std::shared_ptr<const ast_gen::ElementAccess> handle); StoryVolume(std::shared_ptr<const ast_gen::ElementAccess> handle);
// 通过 Group 继承 // 通过 Group 继承
void buildPageHTML(QDomElement& doc) const override; void buildPageHTML(QDomElement& doc) const override;
}; };
class Fragment; class Fragment;
/* /*
* @brief * @brief
*/ */
class FragmentRef : public Element { class FragmentRef : public Element {
public: public:
@ -106,10 +106,10 @@ namespace printer {
void setHost(std::shared_ptr<Fragment> frag_inst); void setHost(std::shared_ptr<Fragment> frag_inst);
std::shared_ptr<Fragment> hostFragment() const; std::shared_ptr<Fragment> hostFragment() const;
// 通过 Access 继承 // 通过 Access 继承
void buildPageHTML(QDomElement& doc) const override; void buildPageHTML(QDomElement& doc) const override;
// 通过 Element 继承 // 通过 Element 继承
void buildSliceHTML(QDomElement& doc) const override; void buildSliceHTML(QDomElement& doc) const override;
private: private:
@ -117,7 +117,7 @@ namespace printer {
}; };
/* /*
* @brief * @brief
*/ */
class Fragment : public Element{ class Fragment : public Element{
private: private:
@ -129,10 +129,10 @@ namespace printer {
void appendRefers(std::shared_ptr<FragmentRef> inst); void appendRefers(std::shared_ptr<FragmentRef> inst);
QList<std::shared_ptr<FragmentRef>> additionals() const; QList<std::shared_ptr<FragmentRef>> additionals() const;
// 通过 Access 继承 // 通过 Access 继承
void buildPageHTML(QDomElement& doc) const override; void buildPageHTML(QDomElement& doc) const override;
// 通过 Element 继承 // 通过 Element 继承
void buildSliceHTML(QDomElement& doc) const override; void buildSliceHTML(QDomElement& doc) const override;
}; };
@ -161,6 +161,9 @@ namespace printer {
void plain_html_output(const std::shared_ptr<const ast_gen::ElementAccess> root, const QDir &destinationdir) const; void plain_html_output(const std::shared_ptr<const ast_gen::ElementAccess> root, const QDir &destinationdir) const;
}; };
/**
* @brief Ast输出构建器.
*/
class AstGenerate : public lib_parse::TreeVisitor { class AstGenerate : public lib_parse::TreeVisitor {
private: private:
QDir src_root; QDir src_root;
@ -174,8 +177,8 @@ namespace printer {
QString content() const; QString content() const;
// 通过 TreeVisitor 继承 // 通过 TreeVisitor 继承
lib_parse::VisitMode mode() const override; lib_parse::VisitMode mode() const override;
bool visit(std::shared_ptr<const ast_gen::ElementAccess> syntax_element) override; bool visit(std::shared_ptr<const ast_gen::ElementAccess> ast_element) override;
}; };
} }

View File

@ -25,35 +25,35 @@ int main(int argc, char* argv[]) {
QCoreApplication a(argc, argv); QCoreApplication a(argc, argv);
ArgsParser args_parser; ArgsParser args_parser;
auto help_mode = make_shared<MatchMode>(0x000Au, u8"打印帮助信息"); auto help_mode = make_shared<MatchMode>(0x000Au, "打印帮助信息");
args_parser << help_mode; args_parser << help_mode;
*help_mode << make_shared<IndexParam>(u8"nsc", u8"程序名称") *help_mode << make_shared<IndexParam>("nsc", "程序名称")
<< make_shared<FloatOption>(u8"help", u8"帮助"); << make_shared<FloatOption>("help", "帮助");
auto build_mode = make_shared<MatchMode>(0x000Bu, u8"执行故事线编译任务"); auto build_mode = make_shared<MatchMode>(0x000Bu, "执行故事线编译任务");
args_parser << build_mode; args_parser << build_mode;
*build_mode << make_shared<IndexParam>(u8"nsc", u8"程序名称") *build_mode << make_shared<IndexParam>("nsc", "程序名称")
<< make_shared<FloatKeyValue>(u8"path", u8"指定源代码目录") << make_shared<FloatKeyValue>("path", "指定源代码目录")
<< make_shared<FloatKeyValue>(u8"dest", u8"指定生成目录") << make_shared<FloatKeyValue>("dest", "指定生成目录")
<< make_shared<FloatOption>(u8"html", u8"生成html文件格式取代AST", true); << make_shared<FloatOption>("html", "生成html文件格式取代AST", true);
auto p_result = args_parser.parse(argc, argv); auto p_result = args_parser.parse(argc, argv);
if (!p_result) { if (!p_result) {
qDebug().noquote() << u8"命令行参数错误!"; qDebug().noquote() << "命令行参数错误!";
qDebug().noquote() << args_parser.helperDoc(); qDebug().noquote() << args_parser.helperDoc();
} }
else { else {
switch (p_result->modeCode()) { switch (p_result->modeCode()) {
case 0xBu: case 0xBu:
{ {
auto src_dir = dynamic_pointer_cast<FloatKeyValue>(p_result->getUnitViaKey(u8"path")); auto src_dir = dynamic_pointer_cast<FloatKeyValue>(p_result->getUnitViaKey("path"));
auto dst_dir = dynamic_pointer_cast<FloatKeyValue>(p_result->getUnitViaKey(u8"dest")); auto dst_dir = dynamic_pointer_cast<FloatKeyValue>(p_result->getUnitViaKey("dest"));
auto html_opt = dynamic_pointer_cast<FloatOption>(p_result->getUnitViaKey(u8"html")); auto html_opt = dynamic_pointer_cast<FloatOption>(p_result->getUnitViaKey("html"));
auto source_dir = QDir(src_dir->value().toString()); auto source_dir = QDir(src_dir->value().toString());
if (!source_dir.exists()) { if (!source_dir.exists()) {
cout << "%编译指定的源代码目录不存在!" << endl; cout << "%编译指定的源代码目录不存在!" << endl;
exit(0); exit(0);
} }
auto destination_dir = QDir::current(); auto destination_dir = QDir::current();
@ -62,7 +62,7 @@ int main(int argc, char* argv[]) {
destination_dir = QDir(target_output.toString()); destination_dir = QDir(target_output.toString());
} }
else { else {
cout << "%编译指定的生成目录不存在,重置为:" << destination_dir.absolutePath().toLocal8Bit().data() << endl; cout << "%编译指定的生成目录不存在,重置为:" << destination_dir.absolutePath().toLocal8Bit().data() << endl;
} }
auto files = source_dir.entryInfoList(QStringList() << "*.story"); auto files = source_dir.entryInfoList(QStringList() << "*.story");
@ -81,7 +81,7 @@ int main(int argc, char* argv[]) {
} }
access_ptr = parser->validsApply(docs); access_ptr = parser->validsApply(docs);
} }
catch (SyntaxException* e) { catch (lib_syntax::SyntaxException* e) {
qDebug().noquote() << e->message(); qDebug().noquote() << e->message();
delete e; delete e;
exit(0); exit(0);
@ -99,11 +99,11 @@ int main(int argc, char* argv[]) {
} }
else if (access_ptr) { else if (access_ptr) {
QTime time_stamp = QTime::currentTime(); QTime time_stamp = QTime::currentTime();
lib_parse::VisitorControl control; lib_parse::VisitEntry control;
auto visitor = make_shared<printer::AstGenerate>(source_dir); auto visitor = make_shared<printer::AstGenerate>(source_dir);
control.visitWith(access_ptr, visitor);; control.visitWith(access_ptr, visitor);
auto dom_result = visitor->content(); auto dom_result = visitor->content();
QFile file(destination_dir.absoluteFilePath(u8"storyline.xast")); QFile file(destination_dir.absoluteFilePath("storyline.xast"));
if (file.open(QIODevice::Text | QIODevice::WriteOnly)) { if (file.open(QIODevice::Text | QIODevice::WriteOnly)) {
QTextStream tout(&file); QTextStream tout(&file);
tout.setCodec("UTF-8"); tout.setCodec("UTF-8");
@ -111,8 +111,8 @@ int main(int argc, char* argv[]) {
tout.flush(); tout.flush();
} }
auto current_stamp = QTime::currentTime(); auto current_stamp = QTime::currentTime();
qDebug().noquote() << QString(u8"%AST构建消耗时间%1 ms。").arg(time_stamp.msecsTo(current_stamp)); qDebug().noquote() << QString("%AST构建消耗时间%1 ms。").arg(time_stamp.msecsTo(current_stamp));
qDebug().noquote() << QString(u8"%编译成功:%1。").arg(QFileInfo(file).absoluteFilePath()); qDebug().noquote() << QString("%编译成功:%1。").arg(QFileInfo(file).absoluteFilePath());
} }
}break; }break;
case 0xAu: case 0xAu:

View File

@ -9,63 +9,71 @@
using namespace example_novel; using namespace example_novel;
using namespace lib_parse; using namespace lib_parse;
NovelParser::NovelParser() NovelParser::NovelParser() {
{ checker_list << std::make_shared<FragmentExistsCheck>();
this->syntax_defines = NovalSyntax::getSyntaxTree(); checker_list << std::make_shared<StoryOrderCheck>();
checker_list << std::make_shared<FragmentExistsCheck>(); checker_list << std::make_shared<PointGraphCheck>();
checker_list << std::make_shared<StoryOrderCheck>();
checker_list << std::make_shared<FragmentGraphCheck>();
analyzer_ref = std::make_shared<Analyzer>(checker_list); analyzer_ref = std::make_shared<Analyzer>(checker_list);
} }
QList<std::shared_ptr<const FragmentGraphHelper>> NovelParser::fragmentsSorted() const QList<std::shared_ptr<const PointGraphHelper>> NovelParser::fragmentsSorted() const {
{ return std::dynamic_pointer_cast<const PointGraphCheck>(checker_list[1])->pointsSequence();
return std::dynamic_pointer_cast<const FragmentGraphCheck>(checker_list[1])->fragmentsSequence();
} }
QString NovelParser::version() const QString NovelParser::version() const {
{ return "1.0.0";
return "1.0.0";
} }
std::shared_ptr<IContext> NovelParser::parserContext() const std::shared_ptr<example_novel::NGlobalElement> NovelParser::parserContext() const {
{ return context;
return context;
} }
QList<std::shared_ptr<const IExprInstance>> NovelParser::parse(const QFileInfoList source_list) const { std::shared_ptr<const example_novel::NGlobalElement> NovelParser::parse(const QFileInfoList source_list) const {
const_cast<NovelParser*>(this)->context = std::make_shared<ast_gen::GlobalElement>(u8"小说"); const_cast<NovelParser*>(this)->context = std::make_shared<example_novel::NGlobalElement>("小说");
auto word_reader = std::make_shared<lib_words::WordReader>();
auto time_stamp = QTime::currentTime(); auto time_stamp = QTime::currentTime();
for (auto& file : source_list) { for (auto finfo : source_list) {
context->setCurrentFile(file.canonicalFilePath()); // 载入指定文件内容
auto words = word_reader->wordsFrom(file.canonicalFilePath()); QFile file_target(finfo.absoluteFilePath());
this->syntax_defines->parse(context, words); if (!file_target.open(QIODevice::ReadOnly | QIODevice::Text)) {
} throw new lib_parse::CheckException(QString("DeviceError[0x00001]指定文件无法打开:%1。").arg(finfo.absoluteFilePath()));
}
QTextStream intext(&file_target);
intext.setCodec("UTF-8");
auto word_reader = std::make_shared<lib_words::WordReader>();
auto word_head = word_reader->wordsFrom(intext, finfo.canonicalFilePath());
QList<std::shared_ptr<const IExprInstance>> forst_root = context->getDocInsts(); // 文件语法解析
auto current_stamp = QTime::currentTime(); ast_gen::SyntaxParser proc(example_novel::NovalSyntax::getSyntaxTree());
qDebug().noquote() << QString(u8"%词法解析+语法解析消耗时间:%1 ms。").arg(time_stamp.msecsTo(current_stamp)); auto rst = proc.parse(word_head);
return forst_root; if (rst.first()->totalErrorCount()) {
auto pos_mark = rst.first()->token()->position();
for (auto item : rst)
if (item->token()->position() == pos_mark)
const_cast<NovelParser*>(this)->context->appendError(item->totalErrors());
break;
}
else {
proc.getAst(rst.first(), const_cast<NovelParser*>(this)->context);
}
}
auto current_stamp = QTime::currentTime();
qDebug().noquote() << QString("%词法解析+语法解析消耗时间:%1 ms。").arg(time_stamp.msecsTo(current_stamp));
return this->context;
} }
std::shared_ptr<const ast_gen::ElementAccess> NovelParser::validsApply(QList<std::shared_ptr<const IExprInstance>> forst_root) const { std::shared_ptr<const ast_gen::ElementAccess> NovelParser::validsApply(std::shared_ptr<const example_novel::NGlobalElement> ast_root) const {
auto time_stamp = QTime::currentTime(); auto 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 access_root = std::make_shared<ast_gen::ElementAccess>(ast_root);
auto novel_accesstree = std::make_shared<ast_gen::ElementAccess>(x_root); auto results = analyzer_ref->validCheckWith(access_root);
auto current_stamp = QTime::currentTime();
qDebug().noquote() << QString(u8"%程序结构重建消耗时间:%1 ms。").arg(time_stamp.msecsTo(current_stamp));
return analyzer_ref->validCheckWith(novel_accesstree); auto current_stamp = QTime::currentTime();
qDebug().noquote() << QString("%程序校验消耗时间:%1 ms。").arg(time_stamp.msecsTo(current_stamp));
return results;
} }

View File

@ -6,23 +6,26 @@
#include <libparse.h> #include <libparse.h>
namespace example_novel { namespace example_novel {
class FragmentGraphHelper; class PointGraphHelper;
class NGlobalElement;
} }
/**
* @brief .
*/
class NovelParser class NovelParser
{ {
private: private:
std::shared_ptr<ast_gen::GlobalElement> context = nullptr; std::shared_ptr<example_novel::NGlobalElement> context = nullptr;
std::shared_ptr<const ExprRule> syntax_defines;
QList<std::shared_ptr<const lib_parse::CheckProvider>> checker_list; QList<std::shared_ptr<const lib_parse::CheckProvider>> checker_list;
std::shared_ptr<const lib_parse::Analyzer> analyzer_ref; std::shared_ptr<const lib_parse::Analyzer> analyzer_ref;
public: public:
NovelParser(); NovelParser();
QList<std::shared_ptr<const example_novel::FragmentGraphHelper>> fragmentsSorted() const; QList<std::shared_ptr<const example_novel::PointGraphHelper>> fragmentsSorted() const;
virtual QString version() const; virtual QString version() const;
std::shared_ptr<IContext> parserContext() const; std::shared_ptr<example_novel::NGlobalElement> parserContext() const;
QList<std::shared_ptr<const IExprInstance>> parse(const QFileInfoList souurce_list) const; std::shared_ptr<const example_novel::NGlobalElement> parse(const QFileInfoList souurce_list) const;
std::shared_ptr<const ast_gen::ElementAccess> validsApply(QList<std::shared_ptr<const IExprInstance>> docs_list) const; std::shared_ptr<const ast_gen::ElementAccess> validsApply(std::shared_ptr<const example_novel::NGlobalElement> root) const;
}; };

View File

@ -53,6 +53,10 @@ void FragmentExistsCheck::exists_check(std::shared_ptr<ElementsCache> root, std:
} }
} }
example_novel::FragmentExistsCheck::FragmentExistsCheck()
:_nodes_cache(std::make_shared<ElementsCache>()) {
}
void FragmentExistsCheck::validCheck(std::shared_ptr<const ElementAccess> root) const { void FragmentExistsCheck::validCheck(std::shared_ptr<const ElementAccess> root) const {
const_cast<FragmentExistsCheck*>(this)->nodes_regist(this->_nodes_cache, root); const_cast<FragmentExistsCheck*>(this)->nodes_regist(this->_nodes_cache, root);
this->exists_check(this->_nodes_cache, root); this->exists_check(this->_nodes_cache, root);
@ -62,7 +66,7 @@ QString FragmentExistsCheck::name() const {
return "情节引用有效性检查器"; return "情节引用有效性检查器";
} }
QList<std::shared_ptr<PointGraphHelper>> FragmentGraphCheck::refers_cycle_check( QList<std::shared_ptr<PointGraphHelper>> PointGraphCheck::refers_cycle_check(
std::shared_ptr<PointGraphHelper> item, QList<std::shared_ptr<PointGraphHelper>> prevs) const { std::shared_ptr<PointGraphHelper> item, QList<std::shared_ptr<PointGraphHelper>> prevs) const {
if (prevs.contains(item)) { if (prevs.contains(item)) {
return prevs << item; return prevs << item;
@ -81,19 +85,19 @@ QList<std::shared_ptr<PointGraphHelper>> FragmentGraphCheck::refers_cycle_check(
return QList<std::shared_ptr<PointGraphHelper>>(); return QList<std::shared_ptr<PointGraphHelper>>();
} }
void FragmentGraphCheck::setElement(std::shared_ptr<PointGraphHelper> inst) { void PointGraphCheck::setElement(std::shared_ptr<PointGraphHelper> inst) {
elements_store[inst->nodePeer()->signature()] = inst; elements_store[inst->nodePeer()->signature()] = inst;
} }
QList<std::shared_ptr<const PointGraphHelper>> FragmentGraphCheck::fragmentsSequence() const { QList<std::shared_ptr<const PointGraphHelper>> PointGraphCheck::pointsSequence() const {
return fragments_sort_list; return fragments_sort_list;
} }
std::shared_ptr<PointGraphHelper> FragmentGraphCheck::getElement(const QString& signature) const { std::shared_ptr<PointGraphHelper> PointGraphCheck::getElement(const QString& signature) const {
return elements_store[signature]; return elements_store[signature];
} }
QList<std::shared_ptr<PointGraphHelper>> FragmentGraphCheck::getHangoutNodes() { QList<std::shared_ptr<PointGraphHelper>> PointGraphCheck::getHangoutNodes() {
QList<std::shared_ptr<PointGraphHelper>> values; QList<std::shared_ptr<PointGraphHelper>> values;
for (auto node_item : elements_store) { for (auto node_item : elements_store) {
@ -109,7 +113,7 @@ QList<std::shared_ptr<PointGraphHelper>> FragmentGraphCheck::getHangoutNodes() {
return values; return values;
} }
bool FragmentGraphCheck::nodeDismantle(std::shared_ptr<PointGraphHelper> inst) { bool PointGraphCheck::nodeDismantle(std::shared_ptr<PointGraphHelper> inst) {
bool flag = false; bool flag = false;
for (auto item : inst->nextList()) { for (auto item : inst->nextList()) {
@ -120,9 +124,9 @@ bool FragmentGraphCheck::nodeDismantle(std::shared_ptr<PointGraphHelper> inst) {
return flag; return flag;
} }
void FragmentGraphCheck::validCheck(std::shared_ptr<const ElementAccess> root) const { void PointGraphCheck::validCheck(std::shared_ptr<const ElementAccess> root) const {
const_cast<FragmentGraphCheck*>(this)->fragments_sort_list.clear(); const_cast<PointGraphCheck*>(this)->fragments_sort_list.clear();
auto self = std::const_pointer_cast<FragmentGraphCheck>(this->shared_from_this()); auto self = std::const_pointer_cast<PointGraphCheck>(this->shared_from_this());
std::function<QList<std::shared_ptr<const ElementAccess>>(std::shared_ptr<const ElementAccess>)> story_peak std::function<QList<std::shared_ptr<const ElementAccess>>(std::shared_ptr<const ElementAccess>)> story_peak
= [&](std::shared_ptr<const ElementAccess> root)->QList<std::shared_ptr<const ElementAccess>> { = [&](std::shared_ptr<const ElementAccess> root)->QList<std::shared_ptr<const ElementAccess>> {
@ -163,7 +167,7 @@ void FragmentGraphCheck::validCheck(std::shared_ptr<const ElementAccess> root) c
return return_temp; return return_temp;
}; };
// 获取所有故事线 // 获取所有故事线
auto all_story = story_peak(root); auto all_story = story_peak(root);
@ -257,10 +261,10 @@ void FragmentGraphCheck::validCheck(std::shared_ptr<const ElementAccess> root) c
} }
for (auto& inst : values) for (auto& inst : values)
const_cast<FragmentGraphCheck*>(this)->fragments_sort_list.append(inst); const_cast<PointGraphCheck*>(this)->fragments_sort_list.append(inst);
} }
QString FragmentGraphCheck::name() const { QString PointGraphCheck::name() const {
return "情节网络有效性检查器"; return "情节网络有效性检查器";
} }

View File

@ -39,6 +39,8 @@ namespace example_novel {
void exists_check(std::shared_ptr<ElementsCache> cache, std::shared_ptr<const ast_gen::ElementAccess> target) const; void exists_check(std::shared_ptr<ElementsCache> cache, std::shared_ptr<const ast_gen::ElementAccess> target) const;
public: public:
FragmentExistsCheck();
// 通过 CheckProvider 继承 // 通过 CheckProvider 继承
virtual QString name() const override; virtual QString name() const override;
virtual void validCheck(std::shared_ptr<const ast_gen::ElementAccess> root) const override; virtual void validCheck(std::shared_ptr<const ast_gen::ElementAccess> root) const override;
@ -47,7 +49,7 @@ namespace example_novel {
/** /**
* @brief . * @brief .
*/ */
class LIBPARSE_EXPORT FragmentGraphCheck : public lib_parse::CheckProvider, public std::enable_shared_from_this<FragmentGraphCheck> { class LIBPARSE_EXPORT PointGraphCheck : public lib_parse::CheckProvider, public std::enable_shared_from_this<PointGraphCheck> {
private: private:
QHash<QString, std::shared_ptr<PointGraphHelper>> elements_store; QHash<QString, std::shared_ptr<PointGraphHelper>> elements_store;
QList<std::shared_ptr<const PointGraphHelper>> fragments_sort_list; QList<std::shared_ptr<const PointGraphHelper>> fragments_sort_list;
@ -62,7 +64,7 @@ namespace example_novel {
QList<std::shared_ptr<PointGraphHelper>> getHangoutNodes(); QList<std::shared_ptr<PointGraphHelper>> getHangoutNodes();
bool nodeDismantle(std::shared_ptr<PointGraphHelper> inst); bool nodeDismantle(std::shared_ptr<PointGraphHelper> inst);
QList<std::shared_ptr<const PointGraphHelper>> fragmentsSequence() const; QList<std::shared_ptr<const PointGraphHelper>> pointsSequence() const;
// CheckProvider interface // CheckProvider interface
public: public:

View File

@ -28,9 +28,18 @@ QList<std::shared_ptr<const IExprInstance>> ExprInstance::children() const {
} }
void ExprInstance::addChild(std::shared_ptr<const IExprInstance> inst) { void ExprInstance::addChild(std::shared_ptr<const IExprInstance> inst) {
std::const_pointer_cast<IExprInstance>(inst)->setParent(shared_from_this());
this->children_store.append(inst); this->children_store.append(inst);
} }
void ast_basic::ExprInstance::setParent(std::weak_ptr<const IExprInstance> pinst) {
this->_parent_bind = pinst;
}
std::weak_ptr<const IExprInstance> ast_basic::ExprInstance::parentExpr() const {
return this->_parent_bind;
}
QList<std::shared_ptr<const IToken>> ExprInstance::tokens() const { QList<std::shared_ptr<const IToken>> ExprInstance::tokens() const {
return this->tokens_bind; return this->tokens_bind;
} }
@ -56,5 +65,12 @@ QList<std::shared_ptr<const IExprInstance>> ExprProgram::children() const {
} }
void ExprProgram::addChild(std::shared_ptr<const IExprInstance> inst) { void ExprProgram::addChild(std::shared_ptr<const IExprInstance> inst) {
std::const_pointer_cast<IExprInstance>(inst)->setParent(shared_from_this());
_children_store.append(inst); _children_store.append(inst);
} }
void ast_basic::ExprProgram::setParent(std::weak_ptr<const IExprInstance> pinst) { }
std::weak_ptr<const IExprInstance> ast_basic::ExprProgram::parentExpr() const {
return std::weak_ptr<const IExprInstance>();
}

View File

@ -52,6 +52,13 @@ namespace ast_basic {
* \param inst * \param inst
*/ */
virtual void addChild(std::shared_ptr<const IExprInstance> inst) = 0; virtual void addChild(std::shared_ptr<const IExprInstance> inst) = 0;
/**
* @brief .
*
* \param pinst
*/
virtual void setParent(std::weak_ptr<const IExprInstance> pinst) = 0;
virtual std::weak_ptr<const IExprInstance> parentExpr() const = 0;
}; };
@ -61,6 +68,8 @@ namespace ast_basic {
*/ */
class LIBSYNTAX_EXPORT ExprInstance : public IExprInstance, public std::enable_shared_from_this<ExprInstance> { class LIBSYNTAX_EXPORT ExprInstance : public IExprInstance, public std::enable_shared_from_this<ExprInstance> {
private: private:
std::weak_ptr<const IExprInstance > _parent_bind;
std::shared_ptr<const lib_syntax::ExprRule> _expr_rule; std::shared_ptr<const lib_syntax::ExprRule> _expr_rule;
QList<std::shared_ptr<const IExprInstance>> children_store; QList<std::shared_ptr<const IExprInstance>> children_store;
QList<std::shared_ptr<const lib_token::IToken>> tokens_bind; QList<std::shared_ptr<const lib_token::IToken>> tokens_bind;
@ -77,6 +86,9 @@ namespace ast_basic {
QList<std::shared_ptr<const IExprInstance>> children() const override; QList<std::shared_ptr<const IExprInstance>> children() const override;
void addChild(std::shared_ptr<const IExprInstance> inst) override; void addChild(std::shared_ptr<const IExprInstance> inst) override;
virtual void setParent(std::weak_ptr<const IExprInstance> pinst) override;
virtual std::weak_ptr<const IExprInstance> parentExpr() const override;
}; };
/** /**
@ -97,5 +109,7 @@ namespace ast_basic {
void addToken(std::shared_ptr<const lib_token::IToken> token_inst) override; void addToken(std::shared_ptr<const lib_token::IToken> token_inst) override;
QList<std::shared_ptr<const IExprInstance>> children() const override; QList<std::shared_ptr<const IExprInstance>> children() const override;
void addChild(std::shared_ptr<const IExprInstance> inst) override; void addChild(std::shared_ptr<const IExprInstance> inst) override;
void setParent(std::weak_ptr<const IExprInstance> pinst) override;
std::weak_ptr<const IExprInstance> parentExpr() const override;
}; };
} }

View File

@ -34,11 +34,11 @@ void PointRefers::setStoryRefer(const QString& refer) {
} }
QString PointRefers::sliceRefer() const { QString PointRefers::sliceRefer() const {
return story_refs; return slice_ref;
} }
void PointRefers::setSliceRefer(const QString& refer) { void PointRefers::setSliceRefer(const QString& refer) {
story_refs = refer; slice_ref = refer;
} }
QString PointRefers::pointRefer() const { QString PointRefers::pointRefer() const {
@ -192,14 +192,19 @@ std::weak_ptr<const SyntaxElement> NGlobalElement::parent() const {
return std::weak_ptr<const SyntaxElement>(); return std::weak_ptr<const SyntaxElement>();
} }
void NGlobalElement::setParent(std::shared_ptr<const SyntaxElement> inst) { }
QList<std::shared_ptr<const TokenAccess>> NGlobalElement::selfTokens() const { QList<std::shared_ptr<const TokenAccess>> NGlobalElement::selfTokens() const {
return QList<std::shared_ptr<const TokenAccess>>(); return QList<std::shared_ptr<const TokenAccess>>();
} }
NGlobalElement::NGlobalElement(const QString& root): ExprProgram(root) { } NGlobalElement::NGlobalElement(const QString& root): ExprProgram(root) { }
void example_novel::NGlobalElement::appendError(const QList<QString>& errors) {
_errors_store.append(errors);
}
QList<QString> example_novel::NGlobalElement::errors() const {
return _errors_store;
}
using namespace ast_gen; using namespace ast_gen;

View File

@ -51,12 +51,6 @@ namespace ast_gen {
* @return parentnullptr * @return parentnullptr
*/ */
virtual std::weak_ptr<const SyntaxElement> parent() const = 0; virtual std::weak_ptr<const SyntaxElement> parent() const = 0;
/**
* @brief .
*
* \param inst
*/
virtual void setParent(std::shared_ptr<const SyntaxElement> inst) = 0;
/** /**
* @brief Token集合 * @brief Token集合
@ -160,10 +154,7 @@ namespace example_novel {
return ExprInstance::filePath(); return ExprInstance::filePath();
} }
virtual std::weak_ptr<const ast_gen::SyntaxElement> parent() const override { virtual std::weak_ptr<const ast_gen::SyntaxElement> parent() const override {
return this->parent_store; return std::dynamic_pointer_cast<const ast_gen::SyntaxElement>(ExprInstance::parentExpr().lock());
}
virtual void setParent(std::shared_ptr<const ast_gen::SyntaxElement> inst) override {
this->parent_store = inst;
} }
virtual QList<std::shared_ptr<const ast_gen::TokenAccess>> selfTokens() const override { virtual QList<std::shared_ptr<const ast_gen::TokenAccess>> selfTokens() const override {
auto tokensx = ExprInstance::tokens(); auto tokensx = ExprInstance::tokens();
@ -337,8 +328,14 @@ namespace example_novel {
* @brief * @brief
*/ */
class LIBSYNTAX_EXPORT NGlobalElement : public ast_basic::ExprProgram, public ast_gen::SyntaxElement { class LIBSYNTAX_EXPORT NGlobalElement : public ast_basic::ExprProgram, public ast_gen::SyntaxElement {
private:
QList<QString> _errors_store;
public: public:
NGlobalElement(const QString &root); NGlobalElement(const QString& root);
void appendError(const QList<QString>& errors);
QList<QString> errors() const;
// 通过 SyntaxElement 继承 // 通过 SyntaxElement 继承
std::shared_ptr<const ast_basic::IExprInstance> bindExpression() const override; std::shared_ptr<const ast_basic::IExprInstance> bindExpression() const override;
@ -347,7 +344,6 @@ namespace example_novel {
QString path() const override; QString path() const override;
QString signature() const override; QString signature() const override;
std::weak_ptr<const SyntaxElement> parent() const override; std::weak_ptr<const SyntaxElement> parent() const override;
void setParent(std::shared_ptr<const SyntaxElement> inst) override;
QList<std::shared_ptr<const ast_gen::TokenAccess>> selfTokens() const override; QList<std::shared_ptr<const ast_gen::TokenAccess>> selfTokens() const override;
}; };
} }