update
This commit is contained in:
parent
8c902fca46
commit
b4e1f2a34c
|
@ -63,6 +63,12 @@
|
|||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
</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">
|
||||
<ClCompile>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
|
|
|
@ -6,7 +6,7 @@ using namespace std;
|
|||
|
||||
__ArgvPackImpls::__ArgvPackImpls(const QString& means, ParamType t) : means_store(means), type_store(t) { }
|
||||
|
||||
// 通过 IArgvPack 继承
|
||||
// 通过 IArgvPack 继承
|
||||
ParamType __ArgvPackImpls::paramType() const {
|
||||
return type_store;
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ bool FloatKeyValue::parse(const QList<QString> args) {
|
|||
return false;
|
||||
|
||||
auto args_t = args[0];
|
||||
if (args_t == u8"--" + bindKey()) {
|
||||
if (args_t == "--" + bindKey()) {
|
||||
auto args_v = args[1];
|
||||
setValue(args_v);
|
||||
return true;
|
||||
|
@ -97,7 +97,7 @@ bool FloatOption::parse(const QList<QString> args) {
|
|||
return false;
|
||||
|
||||
auto args_t = args[0];
|
||||
if (args_t == u8"--" + bindKey()) {
|
||||
if (args_t == "--" + bindKey()) {
|
||||
setValue(true);
|
||||
return true;
|
||||
}
|
||||
|
@ -108,8 +108,8 @@ MatchMode::MatchMode(int mode_code, const QString& mode)
|
|||
:_means_explain(mode), code_store(mode_code) { }
|
||||
|
||||
/**
|
||||
* @brief 获取模式代码
|
||||
* @return 模式代码
|
||||
* @brief 获取模式代码
|
||||
* @return 模式代码
|
||||
*/
|
||||
|
||||
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) {
|
||||
auto u_cast = std::dynamic_pointer_cast<__FloatArgvImpls>(u_exist);
|
||||
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 usage_string;
|
||||
for (auto& item : args_mode)
|
||||
usage_string += item->placeHolder() + u8" ";
|
||||
usage_string += item->placeHolder() + " ";
|
||||
|
||||
return usage_string;
|
||||
}
|
||||
|
||||
QString MatchMode::explanString() const {
|
||||
QStringList sections;
|
||||
sections << u8" " + _means_explain;
|
||||
sections << " " + _means_explain;
|
||||
sections << QString(" Switch:");
|
||||
|
||||
for (auto& item : args_mode) {
|
||||
|
@ -163,7 +163,7 @@ QString MatchMode::explanString() const {
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief 解析匹配参数
|
||||
* @brief 解析匹配参数
|
||||
*/
|
||||
|
||||
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[]) {
|
||||
// 聚合参数数组
|
||||
// 聚合参数数组
|
||||
QList<QString> args_list;
|
||||
for (int idx = 0; idx < argc; idx++) {
|
||||
auto argv_str = QString::fromLocal8Bit(argv[idx]);
|
||||
args_list.append(argv_str);
|
||||
}
|
||||
|
||||
// 枚举模式匹配
|
||||
// 枚举模式匹配
|
||||
for (auto& minst : this->match_modes) {
|
||||
if (minst->parse(args_list))
|
||||
return minst;
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
namespace args_parse {
|
||||
/**
|
||||
* 参数类型.
|
||||
* 参数类型.
|
||||
*/
|
||||
enum class ParamType {
|
||||
IndexParam,
|
||||
|
@ -18,37 +18,37 @@ namespace args_parse {
|
|||
};
|
||||
|
||||
/**
|
||||
* @brief 命令行参数包.
|
||||
* @brief 命令行参数包.
|
||||
*/
|
||||
class IArgvPack {
|
||||
public:
|
||||
virtual ~IArgvPack() = default;
|
||||
/**
|
||||
* 参数包类型.
|
||||
* 参数包类型.
|
||||
*
|
||||
* \return
|
||||
*/
|
||||
virtual ParamType paramType() const = 0;
|
||||
/**
|
||||
* @brief 参数解释.
|
||||
* @brief 参数解释.
|
||||
*
|
||||
* \return 解释
|
||||
* \return 解释
|
||||
*/
|
||||
virtual QString means() const = 0;
|
||||
virtual QString placeHolder(bool decorate = true) const = 0;
|
||||
virtual QVariant value() const = 0;
|
||||
/**
|
||||
* @brief 匹配长度.
|
||||
* @brief 匹配长度.
|
||||
*
|
||||
* \return 长度
|
||||
* \return 长度
|
||||
*/
|
||||
virtual int matchLenth() const = 0;
|
||||
/**
|
||||
* @brief 解析.
|
||||
* @brief 解析.
|
||||
*
|
||||
* \param argv 输入
|
||||
* \param start 起始解析
|
||||
* \return 匹配成功
|
||||
* \param argv 输入
|
||||
* \param start 起始解析
|
||||
* \return 匹配成功
|
||||
*/
|
||||
virtual bool parse(const QList<QString> args) = 0;
|
||||
};
|
||||
|
@ -64,7 +64,7 @@ namespace args_parse {
|
|||
|
||||
void setValue(const QVariant &v);
|
||||
|
||||
// 通过 IArgvPack 继承
|
||||
// 通过 IArgvPack 继承
|
||||
ParamType paramType() const override;
|
||||
QString means() const override;
|
||||
QVariant value() const override;
|
||||
|
@ -83,17 +83,17 @@ namespace args_parse {
|
|||
};
|
||||
|
||||
/**
|
||||
* @brief 命令行key-value解析匹配模式.
|
||||
* @brief 命令行key-value解析匹配模式.
|
||||
* --key value
|
||||
*/
|
||||
class ARGSPARSER_EXPORT FloatKeyValue : public __FloatArgvImpls {
|
||||
public:
|
||||
/**
|
||||
* 浮动key-value解析单元.
|
||||
* 浮动key-value解析单元.
|
||||
*
|
||||
* \param key 键名
|
||||
* \param means 参数解释
|
||||
* \param optional 是否可选
|
||||
* \param key 键名
|
||||
* \param means 参数解释
|
||||
* \param optional 是否可选
|
||||
*/
|
||||
explicit FloatKeyValue(const QString& key, const QString &means, bool optional = false);
|
||||
virtual ~FloatKeyValue() = default;
|
||||
|
@ -104,17 +104,17 @@ namespace args_parse {
|
|||
};
|
||||
|
||||
/**
|
||||
* @brief 命令行key解析匹配模式.
|
||||
* @brief 命令行key解析匹配模式.
|
||||
* --key
|
||||
*/
|
||||
class ARGSPARSER_EXPORT FloatOption : public __FloatArgvImpls {
|
||||
public:
|
||||
/**
|
||||
* 浮动option解析单元.
|
||||
* 浮动option解析单元.
|
||||
*
|
||||
* \param key 键名
|
||||
* \param means 参数解释
|
||||
* \param optional 是否可选
|
||||
* \param key 键名
|
||||
* \param means 参数解释
|
||||
* \param optional 是否可选
|
||||
*/
|
||||
explicit FloatOption(const QString& key, const QString& means, bool optional = false);
|
||||
virtual ~FloatOption() = default;
|
||||
|
@ -125,7 +125,7 @@ namespace args_parse {
|
|||
};
|
||||
|
||||
/**
|
||||
* 序列索引参数.
|
||||
* 序列索引参数.
|
||||
*/
|
||||
class ARGSPARSER_EXPORT IndexParam : public __ArgvPackImpls {
|
||||
private:
|
||||
|
@ -135,7 +135,7 @@ namespace args_parse {
|
|||
explicit IndexParam(const QString & place_v, const QString &means);
|
||||
virtual ~IndexParam() = default;
|
||||
|
||||
// 通过 __ArgvPackImpls 继承
|
||||
// 通过 __ArgvPackImpls 继承
|
||||
virtual QString placeHolder(bool decorate = true) const override;
|
||||
int matchLenth() const override;
|
||||
bool parse(const QList<QString> args) override;
|
||||
|
@ -152,27 +152,27 @@ namespace args_parse {
|
|||
explicit MatchMode(int mode_code, const QString &explain);
|
||||
|
||||
/**
|
||||
* @brief 获取模式代码
|
||||
* @return 模式代码
|
||||
* @brief 获取模式代码
|
||||
* @return 模式代码
|
||||
*/
|
||||
int modeCode()const;
|
||||
|
||||
/**
|
||||
* 获取用例字符串.
|
||||
* 获取用例字符串.
|
||||
*
|
||||
* \return
|
||||
*/
|
||||
QString usageString() const;
|
||||
|
||||
/**
|
||||
* 返回模式解析字符串.
|
||||
* 返回模式解析字符串.
|
||||
*
|
||||
* \return
|
||||
*/
|
||||
QString explanString() const;
|
||||
|
||||
/**
|
||||
* 添加参数解析单元.
|
||||
* 添加参数解析单元.
|
||||
*
|
||||
* \param unit
|
||||
* \return
|
||||
|
@ -180,12 +180,12 @@ namespace args_parse {
|
|||
MatchMode& operator<<(std::shared_ptr<IArgvPack> unit);
|
||||
|
||||
/**
|
||||
* @brief 解析匹配参数
|
||||
* @brief 解析匹配参数
|
||||
*/
|
||||
bool parse(const QList<QString>& args);
|
||||
|
||||
/**
|
||||
* 获取解析单元.
|
||||
* 获取解析单元.
|
||||
*
|
||||
* \param key
|
||||
* \return
|
||||
|
|
|
@ -10,11 +10,13 @@
|
|||
int main(int argc, char* 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);
|
||||
QTextStream tt(&in);
|
||||
tt.setCodec("UTF-8");
|
||||
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());
|
||||
auto rst = parser.parse(vwords);
|
||||
|
|
|
@ -14,24 +14,24 @@
|
|||
故事介绍段落 aldkfjl flwief
|
||||
}
|
||||
|
||||
{故事 故事名称4
|
||||
{故事 故事名称5
|
||||
故事介绍段落 aldkfjl flwief
|
||||
{剧情 剧情名称}
|
||||
}
|
||||
|
||||
{故事 故事名称4
|
||||
{故事 故事名称6
|
||||
故事介绍段落 aldkfjl flwief
|
||||
{剧情 剧情名称 剧情介绍}
|
||||
}
|
||||
|
||||
{故事 故事名称4
|
||||
{故事 故事名称7
|
||||
故事介绍段落 aldkfjl flwief
|
||||
{剧情 剧情名称
|
||||
剧情介绍
|
||||
}
|
||||
}
|
||||
|
||||
{故事 故事名称4
|
||||
{故事 故事名称8
|
||||
故事介绍段落 aldkfjl flwief
|
||||
{剧情 剧情名称
|
||||
剧情介绍
|
||||
|
@ -39,7 +39,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
{故事 故事名称4
|
||||
{故事 故事名称9
|
||||
故事介绍段落 aldkfjl flwief
|
||||
{剧情 剧情名称
|
||||
剧情介绍
|
||||
|
@ -48,7 +48,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
{故事 故事名称4
|
||||
{故事 故事名称10
|
||||
故事介绍段落 aldkfjl flwief
|
||||
{剧情 剧情名称
|
||||
剧情介绍
|
||||
|
@ -58,6 +58,17 @@
|
|||
}
|
||||
}
|
||||
|
||||
{故事 故事名称11
|
||||
故事介绍段落 aldkfjl flwief
|
||||
{剧情 剧情名称
|
||||
剧情介绍
|
||||
{节点 节点名称
|
||||
奥龙订饭;爱领克 非两爱看扥
|
||||
}
|
||||
{@节点 故事名称10&剧情名称&节点名称}
|
||||
}
|
||||
}
|
||||
|
||||
{故事 故事名称4
|
||||
故事介绍段落 aldkfjl flwief
|
||||
{剧情 剧情名称
|
||||
|
@ -65,18 +76,7 @@
|
|||
{节点 节点名称
|
||||
奥龙订饭;爱领克 非两爱看扥
|
||||
}
|
||||
{@节点 节点面&发来垦局&零件扥}
|
||||
}
|
||||
}
|
||||
|
||||
{故事 故事名称4
|
||||
故事介绍段落 aldkfjl flwief
|
||||
{剧情 剧情名称
|
||||
剧情介绍
|
||||
{节点 节点名称
|
||||
奥龙订饭;爱领克 非两爱看扥
|
||||
}
|
||||
{@节点 节点面&发来垦局&零件扥
|
||||
{@节点 故事名称10&剧情名称&节点名称
|
||||
asldkfj 来看房莱肯}
|
||||
}
|
||||
}
|
||||
|
@ -88,7 +88,7 @@
|
|||
{节点 节点名称
|
||||
奥龙订饭;爱领克 非两爱看扥
|
||||
}
|
||||
{@节点 节点面&发来垦局&零件扥
|
||||
{@节点 故事名称10&剧情名称&节点名称
|
||||
asldkfj 来看房莱肯
|
||||
}
|
||||
}
|
||||
|
@ -116,14 +116,14 @@
|
|||
{分卷 卷宗名称
|
||||
拉开茯苓领赛季发啦肯 lakdjf;alfj
|
||||
{章节 章节名称 昂来看申领发
|
||||
{@节点 故事&剧情&节点}
|
||||
{@节点 故事名称10&剧情名称&节点名称}
|
||||
}
|
||||
}
|
||||
|
||||
{分卷 卷宗名称
|
||||
拉开茯苓领赛季发啦肯 lakdjf;alfj
|
||||
{章节 章节名称 昂来看申领发
|
||||
{@节点 故事&剧情&节点 爱;莱肯爱;冷
|
||||
{@节点 故事名称10&剧情名称&节点名称
|
||||
森铃但凡拉动垦局}
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ MinimumVisualStudioVersion = 10.0.40219.1
|
|||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WsNovelParser", "WsNovelParser\WsNovelParser.vcxproj", "{1EF577E8-D92D-4926-9207-1567137BB672}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{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}
|
||||
{EF557F71-99AA-4F2B-A5F5-1A4518A11C19} = {EF557F71-99AA-4F2B-A5F5-1A4518A11C19}
|
||||
EndProjectSection
|
||||
|
@ -17,6 +18,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libSyntax", "libSyntax\libS
|
|||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libParse", "libParse\libParse.vcxproj", "{C3AADEB5-3695-4DF4-B8E1-D37F928F3B2F}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{386F6D42-C6EB-4973-9511-181472391B21} = {386F6D42-C6EB-4973-9511-181472391B21}
|
||||
{EF557F71-99AA-4F2B-A5F5-1A4518A11C19} = {EF557F71-99AA-4F2B-A5F5-1A4518A11C19}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
|
@ -28,13 +30,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "解决方案项", "解决
|
|||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ArgsParser", "ArgsParser\ArgsParser.vcxproj", "{1FF80476-26C9-42FB-BFF6-D587C4941964}"
|
||||
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}"
|
||||
EndProject
|
||||
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|x86.ActiveCfg = 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.Build.0 = Debug|x64
|
||||
{386F6D42-C6EB-4973-9511-181472391B21}.Debug|x86.ActiveCfg = Debug|x64
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<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>
|
||||
<TargetName>nsc</TargetName>
|
||||
</PropertyGroup>
|
||||
|
@ -72,10 +72,11 @@
|
|||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Link>
|
||||
<AdditionalDependencies>libToken.lib;libSyntax.lib;libParse.lib;ArgsParser.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>libWords.lib;libSyntax.lib;libParse.lib;ArgsParser.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<ClCompile>
|
||||
<LanguageStandard>Default</LanguageStandard>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LocalDebuggerWorkingDirectory>$(SolutionDir)$(Platform)\$(Configuration)\</LocalDebuggerWorkingDirectory>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
<LocalDebuggerCommandArguments>--path "D:\CustomNovels\科学+修仙+创造世界" --dest E:\</LocalDebuggerCommandArguments>
|
||||
<LocalDebuggerCommandArguments>--path "D:\Projects\Cpp\WsNovelParser\x64\test_file" --dest E:\</LocalDebuggerCommandArguments>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LocalDebuggerCommandArguments>--path "D:\CustomNovels\科学+修仙+创造世界" --dest E:\</LocalDebuggerCommandArguments>
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -9,7 +9,7 @@
|
|||
|
||||
namespace printer {
|
||||
/*
|
||||
* @brief 所有可访问元素的基类:卷宗、故事线、情节等
|
||||
* @brief 所有可访问元素的基类:卷宗、故事线、剧情、节点等
|
||||
*/
|
||||
class Access : public std::enable_shared_from_this<Access> {
|
||||
public:
|
||||
|
@ -17,20 +17,20 @@ namespace printer {
|
|||
virtual ~Access() = default;
|
||||
|
||||
/*
|
||||
* @brief 获取绑定的语法元素
|
||||
* @return 元素内存指针
|
||||
* @brief 获取绑定的语法元素
|
||||
* @return 元素内存指针
|
||||
*/
|
||||
std::shared_ptr<const ast_gen::ElementAccess> accessPeers() const;
|
||||
|
||||
/*
|
||||
* @brief 设置汇总页面路径
|
||||
* @param href 页面路径
|
||||
* @brief 设置汇总页面路径
|
||||
* @param href 页面路径
|
||||
*/
|
||||
void setPageRefers(const QString& href);
|
||||
QString pageRefers() const;
|
||||
|
||||
/*
|
||||
* @brief 获取汇总页面的HTML
|
||||
* @brief 获取汇总页面的HTML
|
||||
*/
|
||||
virtual void buildPageHTML(QDomElement& doc) const = 0;
|
||||
|
||||
|
@ -40,7 +40,7 @@ namespace printer {
|
|||
};
|
||||
|
||||
/*
|
||||
* @brief 可访问片段元素:故事片段本篇,故事片段引用
|
||||
* @brief 可访问片段元素:故事片段本篇,故事片段引用
|
||||
*/
|
||||
class Element : public Access {
|
||||
public:
|
||||
|
@ -48,13 +48,13 @@ namespace printer {
|
|||
virtual ~Element() = default;
|
||||
|
||||
/*
|
||||
* @brief 设置片段URL,从故事汇总页面跳转回出处页面
|
||||
* @brief 设置片段URL,从故事汇总页面跳转回出处页面
|
||||
*/
|
||||
virtual void setSliceRefer(const QString& href);
|
||||
virtual QString sliceRefers() const;
|
||||
|
||||
/*
|
||||
* @brief 获取故事片段出处的节点HTML
|
||||
* @brief 获取故事片段出处的节点HTML
|
||||
*/
|
||||
virtual void buildSliceHTML(QDomElement &doc) const = 0;
|
||||
|
||||
|
@ -63,7 +63,7 @@ namespace printer {
|
|||
};
|
||||
|
||||
/*
|
||||
* @brief 可访问集合的基类:故事线、故事卷宗
|
||||
* @brief 可访问集合的基类:故事线、剧情节点、故事卷宗
|
||||
*/
|
||||
class Group : public Access {
|
||||
public:
|
||||
|
@ -82,7 +82,7 @@ namespace printer {
|
|||
public:
|
||||
StoryLine(std::shared_ptr<const ast_gen::ElementAccess> handle);
|
||||
|
||||
// 通过 Group 继承
|
||||
// 通过 Group 继承
|
||||
void buildPageHTML(QDomElement& doc) const override;
|
||||
|
||||
};
|
||||
|
@ -91,13 +91,13 @@ namespace printer {
|
|||
public:
|
||||
StoryVolume(std::shared_ptr<const ast_gen::ElementAccess> handle);
|
||||
|
||||
// 通过 Group 继承
|
||||
// 通过 Group 继承
|
||||
void buildPageHTML(QDomElement& doc) const override;
|
||||
|
||||
};
|
||||
class Fragment;
|
||||
/*
|
||||
* @brief 情节片段引用定义
|
||||
* @brief 情节片段引用定义
|
||||
*/
|
||||
class FragmentRef : public Element {
|
||||
public:
|
||||
|
@ -106,10 +106,10 @@ namespace printer {
|
|||
void setHost(std::shared_ptr<Fragment> frag_inst);
|
||||
std::shared_ptr<Fragment> hostFragment() const;
|
||||
|
||||
// 通过 Access 继承
|
||||
// 通过 Access 继承
|
||||
void buildPageHTML(QDomElement& doc) const override;
|
||||
|
||||
// 通过 Element 继承
|
||||
// 通过 Element 继承
|
||||
void buildSliceHTML(QDomElement& doc) const override;
|
||||
|
||||
private:
|
||||
|
@ -117,7 +117,7 @@ namespace printer {
|
|||
};
|
||||
|
||||
/*
|
||||
* @brief 情节片段本篇定义,存储情节引用定义
|
||||
* @brief 情节片段本篇定义,存储情节引用定义
|
||||
*/
|
||||
class Fragment : public Element{
|
||||
private:
|
||||
|
@ -129,10 +129,10 @@ namespace printer {
|
|||
void appendRefers(std::shared_ptr<FragmentRef> inst);
|
||||
QList<std::shared_ptr<FragmentRef>> additionals() const;
|
||||
|
||||
// 通过 Access 继承
|
||||
// 通过 Access 继承
|
||||
void buildPageHTML(QDomElement& doc) const override;
|
||||
|
||||
// 通过 Element 继承
|
||||
// 通过 Element 继承
|
||||
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;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Ast输出构建器.
|
||||
*/
|
||||
class AstGenerate : public lib_parse::TreeVisitor {
|
||||
private:
|
||||
QDir src_root;
|
||||
|
@ -174,8 +177,8 @@ namespace printer {
|
|||
|
||||
QString content() const;
|
||||
|
||||
// 通过 TreeVisitor 继承
|
||||
// 通过 TreeVisitor 继承
|
||||
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;
|
||||
};
|
||||
}
|
|
@ -25,35 +25,35 @@ int main(int argc, char* argv[]) {
|
|||
QCoreApplication a(argc, argv);
|
||||
|
||||
ArgsParser args_parser;
|
||||
auto help_mode = make_shared<MatchMode>(0x000Au, u8"打印帮助信息");
|
||||
auto help_mode = make_shared<MatchMode>(0x000Au, "打印帮助信息");
|
||||
args_parser << help_mode;
|
||||
*help_mode << make_shared<IndexParam>(u8"nsc", u8"程序名称")
|
||||
<< make_shared<FloatOption>(u8"help", u8"帮助");
|
||||
*help_mode << make_shared<IndexParam>("nsc", "程序名称")
|
||||
<< make_shared<FloatOption>("help", "帮助");
|
||||
|
||||
auto build_mode = make_shared<MatchMode>(0x000Bu, u8"执行故事线编译任务");
|
||||
auto build_mode = make_shared<MatchMode>(0x000Bu, "执行故事线编译任务");
|
||||
args_parser << build_mode;
|
||||
*build_mode << make_shared<IndexParam>(u8"nsc", u8"程序名称")
|
||||
<< make_shared<FloatKeyValue>(u8"path", u8"指定源代码目录")
|
||||
<< make_shared<FloatKeyValue>(u8"dest", u8"指定生成目录")
|
||||
<< make_shared<FloatOption>(u8"html", u8"生成html文件格式取代AST", true);
|
||||
*build_mode << make_shared<IndexParam>("nsc", "程序名称")
|
||||
<< make_shared<FloatKeyValue>("path", "指定源代码目录")
|
||||
<< make_shared<FloatKeyValue>("dest", "指定生成目录")
|
||||
<< make_shared<FloatOption>("html", "生成html文件格式取代AST", true);
|
||||
|
||||
|
||||
auto p_result = args_parser.parse(argc, argv);
|
||||
if (!p_result) {
|
||||
qDebug().noquote() << u8"命令行参数错误!";
|
||||
qDebug().noquote() << "命令行参数错误!";
|
||||
qDebug().noquote() << args_parser.helperDoc();
|
||||
}
|
||||
else {
|
||||
switch (p_result->modeCode()) {
|
||||
case 0xBu:
|
||||
{
|
||||
auto src_dir = dynamic_pointer_cast<FloatKeyValue>(p_result->getUnitViaKey(u8"path"));
|
||||
auto dst_dir = dynamic_pointer_cast<FloatKeyValue>(p_result->getUnitViaKey(u8"dest"));
|
||||
auto html_opt = dynamic_pointer_cast<FloatOption>(p_result->getUnitViaKey(u8"html"));
|
||||
auto src_dir = dynamic_pointer_cast<FloatKeyValue>(p_result->getUnitViaKey("path"));
|
||||
auto dst_dir = dynamic_pointer_cast<FloatKeyValue>(p_result->getUnitViaKey("dest"));
|
||||
auto html_opt = dynamic_pointer_cast<FloatOption>(p_result->getUnitViaKey("html"));
|
||||
|
||||
auto source_dir = QDir(src_dir->value().toString());
|
||||
if (!source_dir.exists()) {
|
||||
cout << "%编译指定的源代码目录不存在!" << endl;
|
||||
cout << "%编译指定的源代码目录不存在!" << endl;
|
||||
exit(0);
|
||||
}
|
||||
auto destination_dir = QDir::current();
|
||||
|
@ -62,7 +62,7 @@ int main(int argc, char* argv[]) {
|
|||
destination_dir = QDir(target_output.toString());
|
||||
}
|
||||
else {
|
||||
cout << "%编译指定的生成目录不存在,重置为:" << destination_dir.absolutePath().toLocal8Bit().data() << endl;
|
||||
cout << "%编译指定的生成目录不存在,重置为:" << destination_dir.absolutePath().toLocal8Bit().data() << endl;
|
||||
}
|
||||
|
||||
auto files = source_dir.entryInfoList(QStringList() << "*.story");
|
||||
|
@ -81,7 +81,7 @@ int main(int argc, char* argv[]) {
|
|||
}
|
||||
access_ptr = parser->validsApply(docs);
|
||||
}
|
||||
catch (SyntaxException* e) {
|
||||
catch (lib_syntax::SyntaxException* e) {
|
||||
qDebug().noquote() << e->message();
|
||||
delete e;
|
||||
exit(0);
|
||||
|
@ -99,11 +99,11 @@ int main(int argc, char* argv[]) {
|
|||
}
|
||||
else if (access_ptr) {
|
||||
QTime time_stamp = QTime::currentTime();
|
||||
lib_parse::VisitorControl control;
|
||||
lib_parse::VisitEntry control;
|
||||
auto visitor = make_shared<printer::AstGenerate>(source_dir);
|
||||
control.visitWith(access_ptr, visitor);;
|
||||
control.visitWith(access_ptr, visitor);
|
||||
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)) {
|
||||
QTextStream tout(&file);
|
||||
tout.setCodec("UTF-8");
|
||||
|
@ -111,8 +111,8 @@ int main(int argc, char* argv[]) {
|
|||
tout.flush();
|
||||
}
|
||||
auto current_stamp = QTime::currentTime();
|
||||
qDebug().noquote() << QString(u8"%AST构建消耗时间:%1 ms。").arg(time_stamp.msecsTo(current_stamp));
|
||||
qDebug().noquote() << QString(u8"%编译成功:%1。").arg(QFileInfo(file).absoluteFilePath());
|
||||
qDebug().noquote() << QString("%AST构建消耗时间:%1 ms。").arg(time_stamp.msecsTo(current_stamp));
|
||||
qDebug().noquote() << QString("%编译成功:%1。").arg(QFileInfo(file).absoluteFilePath());
|
||||
}
|
||||
}break;
|
||||
case 0xAu:
|
||||
|
|
|
@ -9,63 +9,71 @@
|
|||
using namespace example_novel;
|
||||
using namespace lib_parse;
|
||||
|
||||
NovelParser::NovelParser()
|
||||
{
|
||||
this->syntax_defines = NovalSyntax::getSyntaxTree();
|
||||
checker_list << std::make_shared<FragmentExistsCheck>();
|
||||
checker_list << std::make_shared<StoryOrderCheck>();
|
||||
checker_list << std::make_shared<FragmentGraphCheck>();
|
||||
NovelParser::NovelParser() {
|
||||
checker_list << std::make_shared<FragmentExistsCheck>();
|
||||
checker_list << std::make_shared<StoryOrderCheck>();
|
||||
checker_list << std::make_shared<PointGraphCheck>();
|
||||
|
||||
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
|
||||
{
|
||||
return std::dynamic_pointer_cast<const FragmentGraphCheck>(checker_list[1])->fragmentsSequence();
|
||||
QList<std::shared_ptr<const PointGraphHelper>> NovelParser::fragmentsSorted() const {
|
||||
return std::dynamic_pointer_cast<const PointGraphCheck>(checker_list[1])->pointsSequence();
|
||||
}
|
||||
|
||||
QString NovelParser::version() const
|
||||
{
|
||||
return "1.0.0";
|
||||
QString NovelParser::version() const {
|
||||
return "1.0.0";
|
||||
}
|
||||
|
||||
std::shared_ptr<IContext> NovelParser::parserContext() const
|
||||
{
|
||||
return context;
|
||||
std::shared_ptr<example_novel::NGlobalElement> NovelParser::parserContext() const {
|
||||
return context;
|
||||
}
|
||||
|
||||
QList<std::shared_ptr<const IExprInstance>> NovelParser::parse(const QFileInfoList source_list) const {
|
||||
const_cast<NovelParser*>(this)->context = std::make_shared<ast_gen::GlobalElement>(u8"小说");
|
||||
auto word_reader = std::make_shared<lib_words::WordReader>();
|
||||
std::shared_ptr<const example_novel::NGlobalElement> NovelParser::parse(const QFileInfoList source_list) const {
|
||||
const_cast<NovelParser*>(this)->context = std::make_shared<example_novel::NGlobalElement>("小说");
|
||||
|
||||
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);
|
||||
}
|
||||
auto time_stamp = QTime::currentTime();
|
||||
for (auto finfo : source_list) {
|
||||
// 载入指定文件内容
|
||||
QFile file_target(finfo.absoluteFilePath());
|
||||
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();
|
||||
qDebug().noquote() << QString(u8"%词法解析+语法解析消耗时间:%1 ms。").arg(time_stamp.msecsTo(current_stamp));
|
||||
// 文件语法解析
|
||||
ast_gen::SyntaxParser proc(example_novel::NovalSyntax::getSyntaxTree());
|
||||
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 {
|
||||
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());
|
||||
}
|
||||
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 x_root = NovalSyntax::tidy(context, docs_node);
|
||||
auto novel_accesstree = std::make_shared<ast_gen::ElementAccess>(x_root);
|
||||
auto current_stamp = QTime::currentTime();
|
||||
qDebug().noquote() << QString(u8"%程序结构重建消耗时间:%1 ms。").arg(time_stamp.msecsTo(current_stamp));
|
||||
auto access_root = std::make_shared<ast_gen::ElementAccess>(ast_root);
|
||||
auto results = analyzer_ref->validCheckWith(access_root);
|
||||
|
||||
return analyzer_ref->validCheckWith(novel_accesstree);
|
||||
auto current_stamp = QTime::currentTime();
|
||||
qDebug().noquote() << QString("%程序校验消耗时间:%1 ms。").arg(time_stamp.msecsTo(current_stamp));
|
||||
return results;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,23 +6,26 @@
|
|||
#include <libparse.h>
|
||||
|
||||
namespace example_novel {
|
||||
class FragmentGraphHelper;
|
||||
class PointGraphHelper;
|
||||
class NGlobalElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 集成编译器.
|
||||
*/
|
||||
class NovelParser
|
||||
{
|
||||
private:
|
||||
std::shared_ptr<ast_gen::GlobalElement> context = nullptr;
|
||||
std::shared_ptr<const ExprRule> syntax_defines;
|
||||
std::shared_ptr<example_novel::NGlobalElement> context = nullptr;
|
||||
QList<std::shared_ptr<const lib_parse::CheckProvider>> checker_list;
|
||||
std::shared_ptr<const lib_parse::Analyzer> analyzer_ref;
|
||||
|
||||
public:
|
||||
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;
|
||||
std::shared_ptr<IContext> parserContext() const;
|
||||
QList<std::shared_ptr<const IExprInstance>> 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<example_novel::NGlobalElement> parserContext() const;
|
||||
std::shared_ptr<const example_novel::NGlobalElement> parse(const QFileInfoList souurce_list) const;
|
||||
std::shared_ptr<const ast_gen::ElementAccess> validsApply(std::shared_ptr<const example_novel::NGlobalElement> root) const;
|
||||
};
|
|
@ -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 {
|
||||
const_cast<FragmentExistsCheck*>(this)->nodes_regist(this->_nodes_cache, root);
|
||||
this->exists_check(this->_nodes_cache, root);
|
||||
|
@ -62,7 +66,7 @@ QString FragmentExistsCheck::name() const {
|
|||
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 {
|
||||
if (prevs.contains(item)) {
|
||||
return prevs << item;
|
||||
|
@ -81,19 +85,19 @@ QList<std::shared_ptr<PointGraphHelper>> FragmentGraphCheck::refers_cycle_check(
|
|||
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;
|
||||
}
|
||||
|
||||
QList<std::shared_ptr<const PointGraphHelper>> FragmentGraphCheck::fragmentsSequence() const {
|
||||
QList<std::shared_ptr<const PointGraphHelper>> PointGraphCheck::pointsSequence() const {
|
||||
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];
|
||||
}
|
||||
|
||||
QList<std::shared_ptr<PointGraphHelper>> FragmentGraphCheck::getHangoutNodes() {
|
||||
QList<std::shared_ptr<PointGraphHelper>> PointGraphCheck::getHangoutNodes() {
|
||||
QList<std::shared_ptr<PointGraphHelper>> values;
|
||||
|
||||
for (auto node_item : elements_store) {
|
||||
|
@ -109,7 +113,7 @@ QList<std::shared_ptr<PointGraphHelper>> FragmentGraphCheck::getHangoutNodes() {
|
|||
return values;
|
||||
}
|
||||
|
||||
bool FragmentGraphCheck::nodeDismantle(std::shared_ptr<PointGraphHelper> inst) {
|
||||
bool PointGraphCheck::nodeDismantle(std::shared_ptr<PointGraphHelper> inst) {
|
||||
bool flag = false;
|
||||
|
||||
for (auto item : inst->nextList()) {
|
||||
|
@ -120,9 +124,9 @@ bool FragmentGraphCheck::nodeDismantle(std::shared_ptr<PointGraphHelper> inst) {
|
|||
return flag;
|
||||
}
|
||||
|
||||
void FragmentGraphCheck::validCheck(std::shared_ptr<const ElementAccess> root) const {
|
||||
const_cast<FragmentGraphCheck*>(this)->fragments_sort_list.clear();
|
||||
auto self = std::const_pointer_cast<FragmentGraphCheck>(this->shared_from_this());
|
||||
void PointGraphCheck::validCheck(std::shared_ptr<const ElementAccess> root) const {
|
||||
const_cast<PointGraphCheck*>(this)->fragments_sort_list.clear();
|
||||
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::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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// 获取所有故事线
|
||||
auto all_story = story_peak(root);
|
||||
|
@ -257,10 +261,10 @@ void FragmentGraphCheck::validCheck(std::shared_ptr<const ElementAccess> root) c
|
|||
}
|
||||
|
||||
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 "情节网络有效性检查器";
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,8 @@ namespace example_novel {
|
|||
void exists_check(std::shared_ptr<ElementsCache> cache, std::shared_ptr<const ast_gen::ElementAccess> target) const;
|
||||
|
||||
public:
|
||||
FragmentExistsCheck();
|
||||
|
||||
// 通过 CheckProvider 继承
|
||||
virtual QString name() const override;
|
||||
virtual void validCheck(std::shared_ptr<const ast_gen::ElementAccess> root) const override;
|
||||
|
@ -47,7 +49,7 @@ namespace example_novel {
|
|||
/**
|
||||
* @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:
|
||||
QHash<QString, std::shared_ptr<PointGraphHelper>> elements_store;
|
||||
QList<std::shared_ptr<const PointGraphHelper>> fragments_sort_list;
|
||||
|
@ -62,7 +64,7 @@ namespace example_novel {
|
|||
QList<std::shared_ptr<PointGraphHelper>> getHangoutNodes();
|
||||
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
|
||||
public:
|
||||
|
|
|
@ -28,9 +28,18 @@ QList<std::shared_ptr<const IExprInstance>> ExprInstance::children() const {
|
|||
}
|
||||
|
||||
void ExprInstance::addChild(std::shared_ptr<const IExprInstance> inst) {
|
||||
std::const_pointer_cast<IExprInstance>(inst)->setParent(shared_from_this());
|
||||
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 {
|
||||
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) {
|
||||
std::const_pointer_cast<IExprInstance>(inst)->setParent(shared_from_this());
|
||||
_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>();
|
||||
}
|
||||
|
|
|
@ -52,6 +52,13 @@ namespace ast_basic {
|
|||
* \param inst 子表达式实例
|
||||
*/
|
||||
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> {
|
||||
private:
|
||||
std::weak_ptr<const IExprInstance > _parent_bind;
|
||||
|
||||
std::shared_ptr<const lib_syntax::ExprRule> _expr_rule;
|
||||
QList<std::shared_ptr<const IExprInstance>> children_store;
|
||||
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;
|
||||
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;
|
||||
QList<std::shared_ptr<const IExprInstance>> children() const 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;
|
||||
};
|
||||
}
|
|
@ -34,11 +34,11 @@ void PointRefers::setStoryRefer(const QString& refer) {
|
|||
}
|
||||
|
||||
QString PointRefers::sliceRefer() const {
|
||||
return story_refs;
|
||||
return slice_ref;
|
||||
}
|
||||
|
||||
void PointRefers::setSliceRefer(const QString& refer) {
|
||||
story_refs = refer;
|
||||
slice_ref = refer;
|
||||
}
|
||||
|
||||
QString PointRefers::pointRefer() const {
|
||||
|
@ -192,14 +192,19 @@ std::weak_ptr<const SyntaxElement> NGlobalElement::parent() const {
|
|||
return std::weak_ptr<const SyntaxElement>();
|
||||
}
|
||||
|
||||
void NGlobalElement::setParent(std::shared_ptr<const SyntaxElement> inst) { }
|
||||
|
||||
QList<std::shared_ptr<const TokenAccess>> NGlobalElement::selfTokens() const {
|
||||
return QList<std::shared_ptr<const TokenAccess>>();
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
|
@ -51,12 +51,6 @@ namespace ast_gen {
|
|||
* @return 未设置parent,返回nullptr
|
||||
*/
|
||||
virtual std::weak_ptr<const SyntaxElement> parent() const = 0;
|
||||
/**
|
||||
* @brief 重置父指针.
|
||||
*
|
||||
* \param inst
|
||||
*/
|
||||
virtual void setParent(std::shared_ptr<const SyntaxElement> inst) = 0;
|
||||
|
||||
/**
|
||||
* @brief 定义元素自身的Token集合
|
||||
|
@ -160,10 +154,7 @@ namespace example_novel {
|
|||
return ExprInstance::filePath();
|
||||
}
|
||||
virtual std::weak_ptr<const ast_gen::SyntaxElement> parent() const override {
|
||||
return this->parent_store;
|
||||
}
|
||||
virtual void setParent(std::shared_ptr<const ast_gen::SyntaxElement> inst) override {
|
||||
this->parent_store = inst;
|
||||
return std::dynamic_pointer_cast<const ast_gen::SyntaxElement>(ExprInstance::parentExpr().lock());
|
||||
}
|
||||
virtual QList<std::shared_ptr<const ast_gen::TokenAccess>> selfTokens() const override {
|
||||
auto tokensx = ExprInstance::tokens();
|
||||
|
@ -337,8 +328,14 @@ namespace example_novel {
|
|||
* @brief 全局根元素
|
||||
*/
|
||||
class LIBSYNTAX_EXPORT NGlobalElement : public ast_basic::ExprProgram, public ast_gen::SyntaxElement {
|
||||
private:
|
||||
QList<QString> _errors_store;
|
||||
|
||||
public:
|
||||
NGlobalElement(const QString &root);
|
||||
NGlobalElement(const QString& root);
|
||||
|
||||
void appendError(const QList<QString>& errors);
|
||||
QList<QString> errors() const;
|
||||
|
||||
// 通过 SyntaxElement 继承
|
||||
std::shared_ptr<const ast_basic::IExprInstance> bindExpression() const override;
|
||||
|
@ -347,7 +344,6 @@ namespace example_novel {
|
|||
QString path() const override;
|
||||
QString signature() 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;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue