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>
|
||||
|
|
|
@ -7,15 +7,23 @@ using namespace printer;
|
|||
using namespace lib_parse;
|
||||
|
||||
Access::Access(std::shared_ptr<const ast_gen::ElementAccess> handle)
|
||||
:access_handle(handle) {}
|
||||
:access_handle(handle) {
|
||||
}
|
||||
|
||||
std::shared_ptr<const ast_gen::ElementAccess> Access::accessPeers() const { return access_handle; }
|
||||
std::shared_ptr<const ast_gen::ElementAccess> Access::accessPeers() const {
|
||||
return access_handle;
|
||||
}
|
||||
|
||||
void Access::setPageRefers(const QString& href) { this->summary_refer_store = href; }
|
||||
void Access::setPageRefers(const QString& href) {
|
||||
this->summary_refer_store = href;
|
||||
}
|
||||
|
||||
QString Access::pageRefers() const { return this->summary_refer_store; }
|
||||
QString Access::pageRefers() const {
|
||||
return this->summary_refer_store;
|
||||
}
|
||||
|
||||
Element::Element(std::shared_ptr<const ast_gen::ElementAccess> handle) :Access(handle) {}
|
||||
Element::Element(std::shared_ptr<const ast_gen::ElementAccess> handle) :Access(handle) {
|
||||
}
|
||||
|
||||
void printer::Element::setSliceRefer(const QString& href) {
|
||||
this->refer_store = href;
|
||||
|
@ -25,20 +33,18 @@ QString printer::Element::sliceRefers() const {
|
|||
return refer_store;
|
||||
}
|
||||
|
||||
Group::Group(std::shared_ptr<const ast_gen::ElementAccess> handle) : Access(handle) {}
|
||||
Group::Group(std::shared_ptr<const ast_gen::ElementAccess> handle) : Access(handle) {
|
||||
}
|
||||
|
||||
void Group::append(std::shared_ptr<Element> elm)
|
||||
{
|
||||
void Group::append(std::shared_ptr<Element> elm) {
|
||||
element_store.append(elm);
|
||||
}
|
||||
|
||||
QList<std::shared_ptr<Element>> Group::elements() const
|
||||
{
|
||||
QList<std::shared_ptr<Element>> Group::elements() const {
|
||||
return this->element_store;
|
||||
}
|
||||
|
||||
std::shared_ptr<Element> printer::Group::getElement(const QString& signature) const
|
||||
{
|
||||
std::shared_ptr<Element> printer::Group::getElement(const QString& signature) const {
|
||||
for (auto& it : elements()) {
|
||||
if (it->accessPeers()->element()->signature() == signature)
|
||||
return it;
|
||||
|
@ -46,7 +52,8 @@ std::shared_ptr<Element> printer::Group::getElement(const QString& signature) co
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
StoryLine::StoryLine(std::shared_ptr<const ast_gen::ElementAccess> handle) :Group(handle) {}
|
||||
StoryLine::StoryLine(std::shared_ptr<const ast_gen::ElementAccess> handle) :Group(handle) {
|
||||
}
|
||||
|
||||
void StoryLine::buildPageHTML(QDomElement& parent) const {
|
||||
auto syntax_access = this->accessPeers();
|
||||
|
@ -62,14 +69,16 @@ void StoryLine::buildPageHTML(QDomElement& parent) const {
|
|||
|
||||
for (auto& inst_c : syntax_access->children()) {
|
||||
switch ((NovelNode) inst_c->element()->typeMark()) {
|
||||
case NovelNode::TextSection: {
|
||||
case NovelNode::TextSection:
|
||||
{
|
||||
auto text_inst = std::dynamic_pointer_cast<const TextSection>(inst_c->element());
|
||||
auto dom_p = doc.createElement("p");
|
||||
dom_p.appendChild(doc.createTextNode(text_inst->content()));
|
||||
dom_storyline.appendChild(dom_p);
|
||||
}break;
|
||||
case NovelNode::PointRefers:
|
||||
case NovelNode::PointDefines: {
|
||||
case NovelNode::PointDefines:
|
||||
{
|
||||
auto element_inst = this->getElement(inst_c->element()->signature());
|
||||
element_inst->buildSliceHTML(dom_storyline);
|
||||
}break;
|
||||
|
@ -79,7 +88,8 @@ void StoryLine::buildPageHTML(QDomElement& parent) const {
|
|||
}
|
||||
}
|
||||
|
||||
StoryVolume::StoryVolume(std::shared_ptr<const ast_gen::ElementAccess> handle) : Group(handle) {}
|
||||
StoryVolume::StoryVolume(std::shared_ptr<const ast_gen::ElementAccess> handle) : Group(handle) {
|
||||
}
|
||||
|
||||
void StoryVolume::buildPageHTML(QDomElement& parent) const {
|
||||
auto syntax_access = this->accessPeers();
|
||||
|
@ -98,23 +108,26 @@ void StoryVolume::buildPageHTML(QDomElement& parent) const {
|
|||
for (auto& child : children) {
|
||||
auto doc_ins = parent_element.ownerDocument();
|
||||
switch ((NovelNode) child->element()->typeMark()) {
|
||||
case NovelNode::TextSection: {
|
||||
case NovelNode::TextSection:
|
||||
{
|
||||
auto text_inst = std::dynamic_pointer_cast<const TextSection>(child->element());
|
||||
auto dom_p = doc_ins.createElement("p");
|
||||
dom_p.appendChild(doc_ins.createTextNode(text_inst->content()));
|
||||
parent_element.appendChild(dom_p);
|
||||
}break;
|
||||
case NovelNode::ArticleDefine: {
|
||||
case NovelNode::ArticleDefine:
|
||||
{
|
||||
auto article_inst = std::dynamic_pointer_cast<const ArticleDefine>(child->element());
|
||||
auto article_group = doc_ins.createElement("div");
|
||||
auto article_head = doc_ins.createElement("h2");
|
||||
article_head.appendChild(doc_ins.createTextNode(article_inst->name() + u8"{"));
|
||||
article_head.appendChild(doc_ins.createTextNode(article_inst->name() + "{"));
|
||||
article_group.appendChild(article_head);
|
||||
rich_refer_build(article_group, child->children());
|
||||
article_group.appendChild(doc_ins.createTextNode(u8"}"));
|
||||
article_group.appendChild(doc_ins.createTextNode("}"));
|
||||
parent_element.appendChild(article_group);
|
||||
}break;
|
||||
case NovelNode::PointRefers:{
|
||||
case NovelNode::PointRefers:
|
||||
{
|
||||
auto fragment_inst = std::dynamic_pointer_cast<const PointRefers>(child->element());
|
||||
auto refer_inst = this->getElement(fragment_inst->signature());
|
||||
refer_inst->buildSliceHTML(parent_element);
|
||||
|
@ -128,15 +141,14 @@ void StoryVolume::buildPageHTML(QDomElement& parent) const {
|
|||
rich_refer_build(dom_volume, syntax_access->children());
|
||||
}
|
||||
|
||||
FragmentRef::FragmentRef(std::shared_ptr<const ast_gen::ElementAccess> handle) : Element(handle) {}
|
||||
FragmentRef::FragmentRef(std::shared_ptr<const ast_gen::ElementAccess> handle) : Element(handle) {
|
||||
}
|
||||
|
||||
void printer::FragmentRef::setHost(std::shared_ptr<Fragment> frag_inst)
|
||||
{
|
||||
void printer::FragmentRef::setHost(std::shared_ptr<Fragment> frag_inst) {
|
||||
this->host_inst = frag_inst;
|
||||
}
|
||||
|
||||
std::shared_ptr<Fragment> printer::FragmentRef::hostFragment() const
|
||||
{
|
||||
std::shared_ptr<Fragment> printer::FragmentRef::hostFragment() const {
|
||||
return this->host_inst.lock();
|
||||
}
|
||||
|
||||
|
@ -147,16 +159,16 @@ void FragmentRef::buildSliceHTML(QDomElement& dom_parent) const {
|
|||
auto jump_to_host = this->hostFragment()->pageRefers();
|
||||
auto doc = dom_parent.ownerDocument();
|
||||
|
||||
auto dom_reference = doc.createElement(u8"div");
|
||||
auto dom_reference = doc.createElement("div");
|
||||
dom_reference.setAttribute("id", QString::number((qulonglong) refer_element.get()));
|
||||
dom_parent.appendChild(dom_reference);
|
||||
|
||||
auto dom_title = doc.createElement(u8"h2");
|
||||
auto dom_title = doc.createElement("h2");
|
||||
dom_reference.appendChild(dom_title);
|
||||
|
||||
auto dom_href = doc.createElement(u8"a");
|
||||
auto dom_href = doc.createElement("a");
|
||||
dom_href.appendChild(doc.createTextNode(refer_element->referSignature()));
|
||||
dom_href.setAttribute("href", u8"file:///"+jump_to_host);
|
||||
dom_href.setAttribute("href", "file:///" + jump_to_host);
|
||||
dom_title.appendChild(dom_href);
|
||||
|
||||
std::function<void(QDomElement&, const QList<std::shared_ptr<const ast_gen::ElementAccess>>&)> rich_refer_build =
|
||||
|
@ -164,20 +176,22 @@ void FragmentRef::buildSliceHTML(QDomElement& dom_parent) const {
|
|||
for (auto& child : children) {
|
||||
auto doc_ins = parent_element.ownerDocument();
|
||||
switch ((NovelNode) child->element()->typeMark()) {
|
||||
case NovelNode::TextSection: {
|
||||
case NovelNode::TextSection:
|
||||
{
|
||||
auto text_inst = std::dynamic_pointer_cast<const TextSection>(child->element());
|
||||
auto dom_p = doc_ins.createElement("p");
|
||||
dom_p.appendChild(doc_ins.createTextNode(text_inst->content()));
|
||||
parent_element.appendChild(dom_p);
|
||||
}break;
|
||||
case NovelNode::ArticleDefine: {
|
||||
case NovelNode::ArticleDefine:
|
||||
{
|
||||
auto article_inst = std::dynamic_pointer_cast<const ArticleDefine>(child->element());
|
||||
auto article_group = doc_ins.createElement("div");
|
||||
auto article_head = doc_ins.createElement("h2");
|
||||
article_head.appendChild(doc_ins.createTextNode(article_inst->name() + u8"{"));
|
||||
article_head.appendChild(doc_ins.createTextNode(article_inst->name() + "{"));
|
||||
article_group.appendChild(article_head);
|
||||
rich_refer_build(article_group, child->children());
|
||||
article_group.appendChild(doc_ins.createTextNode(u8"}"));
|
||||
article_group.appendChild(doc_ins.createTextNode("}"));
|
||||
parent_element.appendChild(article_group);
|
||||
}break;
|
||||
default:
|
||||
|
@ -195,14 +209,14 @@ void FragmentRef::buildPageHTML(QDomElement& parent) const {
|
|||
|
||||
auto doc = parent.ownerDocument();
|
||||
|
||||
auto refers_dom = doc.createElement(u8"div");
|
||||
auto refers_dom = doc.createElement("div");
|
||||
parent.appendChild(refers_dom);
|
||||
|
||||
auto title_block = doc.createElement(u8"h2");
|
||||
auto title_block = doc.createElement("h2");
|
||||
refers_dom.appendChild(title_block);
|
||||
auto title_refer = doc.createElement(u8"a");
|
||||
auto title_refer = doc.createElement("a");
|
||||
title_refer.appendChild(doc.createTextNode(refer_element->signature()));
|
||||
title_refer.setAttribute("href", u8"file:///"+this->sliceRefers());
|
||||
title_refer.setAttribute("href", "file:///" + this->sliceRefers());
|
||||
title_block.appendChild(title_refer);
|
||||
|
||||
std::function<void(QList<std::shared_ptr<const ast_gen::ElementAccess>>)> build_cascade =
|
||||
|
@ -223,7 +237,8 @@ void FragmentRef::buildPageHTML(QDomElement& parent) const {
|
|||
build_cascade(syntax_access->children());
|
||||
}
|
||||
|
||||
Fragment::Fragment(std::shared_ptr<const ast_gen::ElementAccess> handle) : Element(handle) {}
|
||||
Fragment::Fragment(std::shared_ptr<const ast_gen::ElementAccess> handle) : Element(handle) {
|
||||
}
|
||||
|
||||
void Fragment::appendRefers(std::shared_ptr<FragmentRef> inst) {
|
||||
this->additionals_store.append(inst);
|
||||
|
@ -248,7 +263,7 @@ void Fragment::buildSliceHTML(QDomElement& parent) const {
|
|||
|
||||
auto dom_href = doc.createElement("a");
|
||||
dom_href.appendChild(doc.createTextNode(fragment_inst->name()));
|
||||
dom_href.setAttribute("href", u8"file:///"+this->pageRefers());
|
||||
dom_href.setAttribute("href", "file:///" + this->pageRefers());
|
||||
dom_title.appendChild(dom_href);
|
||||
|
||||
for (auto& inst_c : syntax_access->children()) {
|
||||
|
@ -275,7 +290,7 @@ void Fragment::buildPageHTML(QDomElement& parent) const {
|
|||
|
||||
auto dom_href = doc.createElement("a");
|
||||
dom_href.appendChild(doc.createTextNode(fragment_inst->signature()));
|
||||
dom_href.setAttribute("href", u8"file:///" + this->sliceRefers());
|
||||
dom_href.setAttribute("href", "file:///" + this->sliceRefers());
|
||||
dom_title.appendChild(dom_href);
|
||||
|
||||
for (auto& inst_c : syntax_access->children()) {
|
||||
|
@ -293,8 +308,7 @@ void Fragment::buildPageHTML(QDomElement& parent) const {
|
|||
}
|
||||
|
||||
#include <ast_novel.h>
|
||||
void tools_printer::build_fragments(std::shared_ptr<const ast_gen::ElementAccess> novel_root)
|
||||
{
|
||||
void tools_printer::build_fragments(std::shared_ptr<const ast_gen::ElementAccess> novel_root) {
|
||||
if (novel_root->element()->typeMark() == (int) NovelNode::PointDefines) {
|
||||
auto inst = std::make_shared<Fragment>(novel_root);
|
||||
auto name = novel_root->element()->signature();
|
||||
|
@ -306,15 +320,16 @@ void tools_printer::build_fragments(std::shared_ptr<const ast_gen::ElementAccess
|
|||
}
|
||||
}
|
||||
|
||||
void tools_printer::build_refers_network(std::shared_ptr<const ast_gen::ElementAccess> novel_node)
|
||||
{
|
||||
void tools_printer::build_refers_network(std::shared_ptr<const ast_gen::ElementAccess> novel_node) {
|
||||
switch ((NovelNode) novel_node->element()->typeMark()) {
|
||||
case NovelNode::StoryDefine: {
|
||||
case NovelNode::StoryDefine:
|
||||
{
|
||||
auto storyinst = std::make_shared<StoryLine>(novel_node);
|
||||
this->storyline_defines[novel_node->element()->signature()] = storyinst;
|
||||
build_storyline(storyinst);
|
||||
}return;
|
||||
case NovelNode::VolumeDefine: {
|
||||
case NovelNode::VolumeDefine:
|
||||
{
|
||||
auto volumeinst = std::make_shared<StoryVolume>(novel_node);
|
||||
this->volume_defines[novel_node->element()->signature()] = volumeinst;
|
||||
build_volumeline(volumeinst);
|
||||
|
@ -325,21 +340,21 @@ void tools_printer::build_refers_network(std::shared_ptr<const ast_gen::ElementA
|
|||
build_refers_network(inst_c);
|
||||
}
|
||||
|
||||
void tools_printer::build_storyline(std::shared_ptr<StoryLine> line, std::shared_ptr<const ast_gen::ElementAccess> novel_node)
|
||||
{
|
||||
void tools_printer::build_storyline(std::shared_ptr<StoryLine> line, std::shared_ptr<const ast_gen::ElementAccess> novel_node) {
|
||||
if (!novel_node) {
|
||||
for (auto& inst_c : line->accessPeers()->children()) {
|
||||
build_storyline(line, inst_c);
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch ((NovelNode)novel_node->element()->typeMark())
|
||||
switch ((NovelNode) novel_node->element()->typeMark()) {
|
||||
case NovelNode::PointDefines:
|
||||
{
|
||||
case NovelNode::PointDefines: {
|
||||
auto inst = this->fragment_defines[novel_node->element()->signature()];
|
||||
line->append(inst);
|
||||
}return;
|
||||
case NovelNode::PointRefers: {
|
||||
case NovelNode::PointRefers:
|
||||
{
|
||||
auto refer_node = std::dynamic_pointer_cast<const PointRefers>(novel_node->element());
|
||||
auto refer_fragment = this->fragment_defines[refer_node->referSignature()];
|
||||
auto inst = std::make_shared<FragmentRef>(novel_node);
|
||||
|
@ -353,8 +368,7 @@ void tools_printer::build_storyline(std::shared_ptr<StoryLine> line, std::shared
|
|||
}
|
||||
}
|
||||
|
||||
void tools_printer::build_volumeline(std::shared_ptr<StoryVolume> volume, std::shared_ptr<const ast_gen::ElementAccess> novel_node)
|
||||
{
|
||||
void tools_printer::build_volumeline(std::shared_ptr<StoryVolume> volume, std::shared_ptr<const ast_gen::ElementAccess> novel_node) {
|
||||
if (!novel_node) {
|
||||
for (auto& inst_c : volume->accessPeers()->children())
|
||||
build_volumeline(volume, inst_c);
|
||||
|
@ -390,7 +404,7 @@ std::function<void(const QList<std::shared_ptr<Element>>&, const QString&)> refe
|
|||
[&](const QList<std::shared_ptr<Element>>& items, const QString& summary_href) {
|
||||
for (auto& item : items) {
|
||||
auto element_addr = QString::number((qulonglong) item->accessPeers()->element().get());
|
||||
item->setSliceRefer(summary_href + u8"#" + element_addr);
|
||||
item->setSliceRefer(summary_href + "#" + element_addr);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -423,7 +437,7 @@ void tools_printer::volumes_anchors_define(const QList<std::shared_ptr<StoryVolu
|
|||
}
|
||||
|
||||
auto get_node_name = [](const std::shared_ptr<Access> item) {
|
||||
return u8"node_" + QString::number((qulonglong)item->accessPeers()->element().get());
|
||||
return "node_" + QString::number((qulonglong) item->accessPeers()->element().get());
|
||||
};
|
||||
|
||||
QString printer::tools_printer::storylines_paint(const QList<std::shared_ptr<StoryLine>>& lines) {
|
||||
|
@ -432,7 +446,7 @@ QString printer::tools_printer::storylines_paint(const QList<std::shared_ptr<Sto
|
|||
for (auto& story : lines) {
|
||||
auto story_elem = std::dynamic_pointer_cast<const example_novel::StoryDefine>(story->accessPeers()->element());
|
||||
node_records[story_elem->signature()] = story;
|
||||
nodes_description += get_node_name(story) + QString(u8"[fillcolor=pink,label=\"%1{%2}\",shape=\"cds\"]\n").arg(story_elem->name()).arg(story_elem->sort());
|
||||
nodes_description += get_node_name(story) + QString("[fillcolor=pink,label=\"%1{%2}\",shape=\"cds\"]\n").arg(story_elem->name()).arg(story_elem->sort());
|
||||
|
||||
for (auto& frag : story->elements()) {
|
||||
auto fragment_peers = frag->accessPeers()->element();
|
||||
|
@ -441,7 +455,7 @@ QString printer::tools_printer::storylines_paint(const QList<std::shared_ptr<Sto
|
|||
auto node_name = fragment_elem->signature();
|
||||
node_records[node_name] = frag;
|
||||
|
||||
nodes_description += get_node_name(frag) + QString(u8"[label=\"{%2}::%1\",shape=\"rect\"]\n")
|
||||
nodes_description += get_node_name(frag) + QString("[label=\"{%2}::%1\",shape=\"rect\"]\n")
|
||||
.arg(fragment_elem->name()).arg(story_elem->sort());
|
||||
}
|
||||
}
|
||||
|
@ -454,21 +468,21 @@ QString printer::tools_printer::storylines_paint(const QList<std::shared_ptr<Sto
|
|||
QString previous_node = get_node_name(story);
|
||||
for (auto& frag : story->elements()) {
|
||||
if (example_novel::NovelNode::PointDefines == (example_novel::NovelNode) frag->accessPeers()->element()->typeMark()) {
|
||||
arrows_link += previous_node + u8"->" + get_node_name(frag) + QString(u8"[label=\"%1{%2}\"]\n")
|
||||
arrows_link += previous_node + "->" + get_node_name(frag) + QString("[label=\"%1{%2}\"]\n")
|
||||
.arg(story_elem->name()).arg(story_elem->sort());
|
||||
previous_node = get_node_name(frag);
|
||||
}
|
||||
else if (example_novel::NovelNode::PointRefers == (example_novel::NovelNode) frag->accessPeers()->element()->typeMark()) {
|
||||
auto frag_refer = std::dynamic_pointer_cast<const example_novel::PointRefers>(frag->accessPeers()->element());
|
||||
auto frag_src = node_records[frag_refer->referSignature()];
|
||||
arrows_link += previous_node + u8"->" + get_node_name(frag_src) + QString(u8"[label=\"%1{%2}\"]\n")
|
||||
arrows_link += previous_node + "->" + get_node_name(frag_src) + QString("[label=\"%1{%2}\"]\n")
|
||||
.arg(story_elem->name()).arg(story_elem->sort());
|
||||
previous_node = get_node_name(frag_src);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return QString(u8"digraph{ rankdir = LR \n node[style=filled] \n %1\n %2 }").arg(nodes_description).arg(arrows_link);
|
||||
return QString("digraph{ rankdir = LR \n node[style=filled] \n %1\n %2 }").arg(nodes_description).arg(arrows_link);
|
||||
}
|
||||
|
||||
QString printer::tools_printer::volumes_paint(const QList<std::shared_ptr<StoryVolume>>& vols, const QList<std::shared_ptr<StoryLine>>& lines) {
|
||||
|
@ -482,30 +496,29 @@ QString printer::tools_printer::volumes_paint(const QList<std::shared_ptr<StoryV
|
|||
if (fragment_peers->typeMark() == (int) example_novel::NovelNode::PointDefines) {
|
||||
auto fragment_elem = std::dynamic_pointer_cast<const example_novel::PointDefines>(fragment_peers);
|
||||
node_records[fragment_elem->signature()] = frag;
|
||||
nodes_description += get_node_name(frag) + QString(u8"[label=\"%1\",shape=\"ellipse\"]\n").arg(fragment_elem->name());
|
||||
nodes_description += get_node_name(frag) + QString("[label=\"%1\",shape=\"ellipse\"]\n").arg(fragment_elem->name());
|
||||
}
|
||||
}
|
||||
|
||||
auto story_elem = std::dynamic_pointer_cast<const example_novel::StoryDefine>(story->accessPeers()->element());
|
||||
clusters_description += QString(u8"subgraph cluster_%1 { label=%3 \n %2 }")
|
||||
clusters_description += QString("subgraph cluster_%1 { label=%3 \n %2 }")
|
||||
.arg((qulonglong) story_elem.get()).arg(nodes_description).arg(story_elem->name());
|
||||
}
|
||||
|
||||
|
||||
auto article_cluster = [&node_records](
|
||||
const std::shared_ptr<const ast_gen::ElementAccess> article_access, QList<QString> &arrows_out)->QString {
|
||||
auto article_cluster = [&node_records](const std::shared_ptr<const ast_gen::ElementAccess> article_access, QList<QString>& arrows_out)->QString {
|
||||
QString nodes_description;
|
||||
for (auto& fragment_access : article_access->children()) {
|
||||
if (fragment_access->element()->typeMark() == (int) example_novel::NovelNode::PointRefers) {
|
||||
auto refer_fragment = std::dynamic_pointer_cast<const example_novel::PointRefers>(fragment_access->element());
|
||||
nodes_description += QString(u8"fragment_%1[label=\"%2\",shape=\"plaintext\"]\n")
|
||||
.arg((qulonglong)refer_fragment.get()).arg(refer_fragment->fragmentRefer());
|
||||
nodes_description += QString("fragment_%1[label=\"%2\",shape=\"plaintext\"]\n")
|
||||
.arg((qulonglong) refer_fragment.get()).arg(refer_fragment->sliceRefer());
|
||||
auto symbo_refer = node_records[refer_fragment->referSignature()];
|
||||
arrows_out << QString(u8"fragment_%1 -- %2[color=\"red\"]\n").arg((qulonglong)refer_fragment.get()).arg(get_node_name(symbo_refer));
|
||||
arrows_out << QString("fragment_%1 -- %2[color=\"red\"]\n").arg((qulonglong) refer_fragment.get()).arg(get_node_name(symbo_refer));
|
||||
}
|
||||
}
|
||||
auto article_define = std::dynamic_pointer_cast<const example_novel::ArticleDefine>(article_access->element());
|
||||
return QString(u8"subgraph cluster_%1{ label=%2 \n %3 }\n").arg((qulonglong)article_access->element().get())
|
||||
return QString("subgraph cluster_%1{ label=%2 \n %3 }\n").arg((qulonglong) article_access->element().get())
|
||||
.arg(article_define->name()).arg(nodes_description);
|
||||
};
|
||||
|
||||
|
@ -527,7 +540,7 @@ QString printer::tools_printer::volumes_paint(const QList<std::shared_ptr<StoryV
|
|||
}
|
||||
|
||||
auto volume_elem = std::dynamic_pointer_cast<const example_novel::VolumeDefine>(vol->accessPeers()->element());
|
||||
clusters_description += QString(u8"subgraph cluster_%1 { label=%3 \n %2 }")
|
||||
clusters_description += QString("subgraph cluster_%1 { label=%3 \n %2 }")
|
||||
.arg((qulonglong) volume_elem.get()).arg(members_description).arg(volume_elem->name());
|
||||
}
|
||||
|
||||
|
@ -537,8 +550,7 @@ QString printer::tools_printer::volumes_paint(const QList<std::shared_ptr<StoryV
|
|||
#include <QTextStream>
|
||||
#include <QTime>
|
||||
#include <QDebug>
|
||||
void printer::tools_printer::plain_html_output(const std::shared_ptr<const ast_gen::ElementAccess> access_ptr, const QDir& destination_dir) const
|
||||
{
|
||||
void printer::tools_printer::plain_html_output(const std::shared_ptr<const ast_gen::ElementAccess> access_ptr, const QDir& destination_dir) const {
|
||||
QTime time_stamp = QTime::currentTime();
|
||||
auto tool = *this;
|
||||
tool.build_fragments(access_ptr);
|
||||
|
@ -553,11 +565,11 @@ void printer::tools_printer::plain_html_output(const std::shared_ptr<const ast_g
|
|||
auto target_path = inst->pageRefers();
|
||||
QFile tfile(target_path);
|
||||
if (tfile.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
QDomDocument doc_inst(QDomImplementation().createDocumentType(u8"html", QString(), QString()));
|
||||
auto html = doc_inst.createElement(u8"html");
|
||||
QDomDocument doc_inst(QDomImplementation().createDocumentType("html", QString(), QString()));
|
||||
auto html = doc_inst.createElement("html");
|
||||
doc_inst.appendChild(html);
|
||||
|
||||
auto body = doc_inst.createElement(u8"body");
|
||||
auto body = doc_inst.createElement("body");
|
||||
html.appendChild(body);
|
||||
|
||||
inst->buildPageHTML(body);
|
||||
|
@ -577,20 +589,20 @@ void printer::tools_printer::plain_html_output(const std::shared_ptr<const ast_g
|
|||
|
||||
QDir::setCurrent(destination_dir.canonicalPath());
|
||||
auto dot_src = tool.storylines_paint(tool.storyline_defines.values());
|
||||
QFile dot_file(QDir::current().filePath(u8"relates.dot"));
|
||||
QFile dot_file(QDir::current().filePath("relates.dot"));
|
||||
if (dot_file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
QTextStream txt(&dot_file);
|
||||
txt.setCodec(u8"UTF-8");
|
||||
txt.setCodec("UTF-8");
|
||||
txt << dot_src;
|
||||
txt.flush();
|
||||
}
|
||||
system("dot -Tsvg relates.dot -o relates.svg");
|
||||
|
||||
auto vols_src = tool.volumes_paint(tool.volume_defines.values(), tool.storyline_defines.values());
|
||||
QFile vols_file(QDir::current().filePath(u8"volumes_group.dot"));
|
||||
QFile vols_file(QDir::current().filePath("volumes_group.dot"));
|
||||
if (vols_file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
QTextStream txt(&vols_file);
|
||||
txt.setCodec(u8"UTF-8");
|
||||
txt.setCodec("UTF-8");
|
||||
txt << vols_src;
|
||||
txt.flush();
|
||||
}
|
||||
|
@ -600,16 +612,16 @@ void printer::tools_printer::plain_html_output(const std::shared_ptr<const ast_g
|
|||
{
|
||||
QFile tfile("./index.html");
|
||||
if (tfile.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
QDomDocument doc_inst(QDomImplementation().createDocumentType(u8"html", QString(), QString()));
|
||||
auto html = doc_inst.createElement(u8"html");
|
||||
QDomDocument doc_inst(QDomImplementation().createDocumentType("html", QString(), QString()));
|
||||
auto html = doc_inst.createElement("html");
|
||||
doc_inst.appendChild(html);
|
||||
|
||||
auto body = doc_inst.createElement(u8"body");
|
||||
auto body = doc_inst.createElement("body");
|
||||
html.appendChild(body);
|
||||
|
||||
auto dom_storyline = doc_inst.createElement("div");
|
||||
auto dom_storyline_title = doc_inst.createElement("h2");
|
||||
dom_storyline_title.appendChild(doc_inst.createTextNode(u8"故事脉络"));
|
||||
dom_storyline_title.appendChild(doc_inst.createTextNode("故事脉络"));
|
||||
dom_storyline.appendChild(dom_storyline_title);
|
||||
body.appendChild(dom_storyline);
|
||||
|
||||
|
@ -624,15 +636,15 @@ void printer::tools_printer::plain_html_output(const std::shared_ptr<const ast_g
|
|||
dom_storyline.appendChild(dom_line);
|
||||
|
||||
auto line_href = doc_inst.createElement("a");
|
||||
line_href.setAttribute(u8"href", u8"file:///" + inst_line->pageRefers());
|
||||
line_href.setAttribute("href", "file:///" + inst_line->pageRefers());
|
||||
auto a_elm = std::dynamic_pointer_cast<const example_novel::StoryDefine>(inst_line->accessPeers()->element());
|
||||
line_href.appendChild(doc_inst.createTextNode(QString(u8"%1.%2").arg(a_elm->sort()).arg(a_elm->signature())));
|
||||
line_href.appendChild(doc_inst.createTextNode(QString("%1.%2").arg(a_elm->sort()).arg(a_elm->signature())));
|
||||
dom_line.appendChild(line_href);
|
||||
}
|
||||
|
||||
auto dom_volume = doc_inst.createElement("div");
|
||||
auto dom_volume_title = doc_inst.createElement("h2");
|
||||
dom_volume_title.appendChild(doc_inst.createTextNode(u8"分卷内容"));
|
||||
dom_volume_title.appendChild(doc_inst.createTextNode("分卷内容"));
|
||||
dom_volume.appendChild(dom_volume_title);
|
||||
body.appendChild(dom_volume);
|
||||
|
||||
|
@ -641,25 +653,25 @@ void printer::tools_printer::plain_html_output(const std::shared_ptr<const ast_g
|
|||
dom_volume.appendChild(dom_volume_ref);
|
||||
|
||||
auto volume_href = doc_inst.createElement("a");
|
||||
volume_href.setAttribute(u8"href", u8"file:///" + inst_volume->pageRefers());
|
||||
volume_href.setAttribute("href", "file:///" + inst_volume->pageRefers());
|
||||
volume_href.appendChild(doc_inst.createTextNode(inst_volume->accessPeers()->element()->signature()));
|
||||
dom_volume_ref.appendChild(volume_href);
|
||||
}
|
||||
|
||||
auto dom_fragment = doc_inst.createElement("div");
|
||||
auto dom_fragment_title = doc_inst.createElement("h2");
|
||||
dom_fragment_title.appendChild(doc_inst.createTextNode(u8"情节集合"));
|
||||
dom_fragment_title.appendChild(doc_inst.createTextNode("情节集合"));
|
||||
dom_fragment.appendChild(dom_fragment_title);
|
||||
body.appendChild(dom_fragment);
|
||||
|
||||
auto table_cube = doc_inst.createElement(u8"table");
|
||||
auto table_cube = doc_inst.createElement("table");
|
||||
dom_fragment.appendChild(table_cube);
|
||||
|
||||
int row_ctrl = 0;
|
||||
QDomElement elm_row;
|
||||
for (auto& inst_frag : tool.fragment_defines) {
|
||||
if (row_ctrl++ % 4 == 0) {
|
||||
elm_row = doc_inst.createElement(u8"tr");
|
||||
elm_row = doc_inst.createElement("tr");
|
||||
table_cube.appendChild(elm_row);
|
||||
}
|
||||
|
||||
|
@ -667,23 +679,23 @@ void printer::tools_printer::plain_html_output(const std::shared_ptr<const ast_g
|
|||
elm_row.appendChild(dom_fragment_ref);
|
||||
|
||||
auto frag_href = doc_inst.createElement("a");
|
||||
frag_href.setAttribute(u8"href", u8"file:///" + inst_frag->pageRefers());
|
||||
frag_href.setAttribute("href", "file:///" + inst_frag->pageRefers());
|
||||
frag_href.appendChild(doc_inst.createTextNode(inst_frag->accessPeers()->element()->signature()));
|
||||
dom_fragment_ref.appendChild(frag_href);
|
||||
}
|
||||
|
||||
auto dom_relate = doc_inst.createElement(u8"div");
|
||||
auto dom_relate_title = doc_inst.createElement(u8"h2");
|
||||
dom_relate_title.appendChild(doc_inst.createTextNode(u8"联系图"));
|
||||
auto dom_relate = doc_inst.createElement("div");
|
||||
auto dom_relate_title = doc_inst.createElement("h2");
|
||||
dom_relate_title.appendChild(doc_inst.createTextNode("联系图"));
|
||||
dom_relate.appendChild(dom_relate_title);
|
||||
body.appendChild(dom_relate);
|
||||
|
||||
auto img = doc_inst.createElement(u8"img");
|
||||
img.setAttribute(u8"src", u8"file:///" + QDir::current().filePath(u8"relates.svg"));
|
||||
auto img = doc_inst.createElement("img");
|
||||
img.setAttribute("src", "file:///" + QDir::current().filePath("relates.svg"));
|
||||
dom_relate.appendChild(img);
|
||||
dom_relate.appendChild(doc_inst.createElement("br"));
|
||||
img = doc_inst.createElement(u8"img");
|
||||
img.setAttribute(u8"src", u8"file:///" + QDir::current().filePath(u8"volumes_group.svg"));
|
||||
img = doc_inst.createElement("img");
|
||||
img.setAttribute("src", "file:///" + QDir::current().filePath("volumes_group.svg"));
|
||||
dom_relate.appendChild(img);
|
||||
|
||||
QTextStream tout(&tfile);
|
||||
|
@ -693,21 +705,21 @@ void printer::tools_printer::plain_html_output(const std::shared_ptr<const ast_g
|
|||
}
|
||||
|
||||
auto current_stamp = QTime::currentTime();
|
||||
qDebug().noquote() << QString(u8"%html构建消耗时间:%1 ms。").arg(time_stamp.msecsTo(current_stamp));
|
||||
qDebug().noquote() << u8"%编译成功:" << destination_dir.absoluteFilePath(u8"index.html");
|
||||
qDebug().noquote() << QString("%html构建消耗时间:%1 ms。").arg(time_stamp.msecsTo(current_stamp));
|
||||
qDebug().noquote() << "%编译成功:" << destination_dir.absoluteFilePath("index.html");
|
||||
}
|
||||
|
||||
void printer::AstGenerate::append_tokens(QDomElement _elm, std::shared_ptr<const ast_gen::SyntaxElement> inst) {
|
||||
auto dom_tokens = doc.createElement(u8"tokens");
|
||||
auto dom_tokens = doc.createElement("tokens");
|
||||
_elm.appendChild(dom_tokens);
|
||||
|
||||
for (auto& token : inst->selfTokens()) {
|
||||
auto dom_token = doc.createElement(u8"token");
|
||||
auto dom_token = doc.createElement("token");
|
||||
dom_tokens.appendChild(dom_token);
|
||||
|
||||
dom_token.setAttribute(u8"text", token->token()->content());
|
||||
dom_token.setAttribute(u8"row", token->token()->row());
|
||||
dom_token.setAttribute(u8"col", token->token()->column());
|
||||
dom_token.setAttribute("text", token->token()->content());
|
||||
dom_token.setAttribute("row", token->token()->row());
|
||||
dom_token.setAttribute("col", token->token()->column());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -717,8 +729,7 @@ printer::AstGenerate::AstGenerate(const QDir &src_rt)
|
|||
doc.appendChild(procs);
|
||||
}
|
||||
|
||||
QString printer::AstGenerate::content() const
|
||||
{
|
||||
QString printer::AstGenerate::content() const {
|
||||
return doc.toString(2);
|
||||
}
|
||||
|
||||
|
@ -729,119 +740,147 @@ VisitMode printer::AstGenerate::mode() const {
|
|||
#include <QDateTime>
|
||||
bool printer::AstGenerate::visit(std::shared_ptr<const ast_gen::ElementAccess> syntax_element) {
|
||||
switch ((NovelNode) syntax_element->element()->typeMark()) {
|
||||
case NovelNode::GlobalElement:{
|
||||
auto body = doc.createElement(u8"ast");
|
||||
case NovelNode::GlobalElement:
|
||||
{
|
||||
auto body = doc.createElement("ast");
|
||||
doc.appendChild(body);
|
||||
body.setAttribute(u8"time", QDateTime::currentDateTime().toString(u8"yyyyMMdd_hhmmss"));
|
||||
body.setAttribute(u8"dir_src", src_root.absolutePath());
|
||||
body.setAttribute("time", QDateTime::currentDateTime().toString("yyyyMMdd_hhmmss"));
|
||||
body.setAttribute("dir_src", src_root.absolutePath());
|
||||
element_stack.append(body);
|
||||
}break;
|
||||
case NovelNode::Document: break;
|
||||
case NovelNode::StoryDefine:{
|
||||
while (element_stack.last().tagName() != u8"ast") {
|
||||
case NovelNode::StoryDefine:
|
||||
{
|
||||
while (element_stack.last().tagName() != "ast") {
|
||||
element_stack.takeLast();
|
||||
}
|
||||
|
||||
auto current_ast = element_stack.last();
|
||||
auto story_node = std::dynamic_pointer_cast<const example_novel::StoryDefine>(syntax_element->element());
|
||||
auto dom_story = doc.createElement(u8"story");
|
||||
auto dom_story = doc.createElement("story");
|
||||
current_ast.appendChild(dom_story);
|
||||
element_stack.append(dom_story);
|
||||
|
||||
dom_story.setAttribute(u8"name", story_node->name());
|
||||
dom_story.setAttribute(u8"address", (qulonglong)story_node.get());
|
||||
dom_story.setAttribute(u8"file-path", src_root.relativeFilePath(story_node->filePath()));
|
||||
dom_story.setAttribute(u8"sort", story_node->sort());
|
||||
dom_story.setAttribute("name", story_node->name());
|
||||
dom_story.setAttribute("address", (qulonglong) story_node.get());
|
||||
dom_story.setAttribute("file-path", src_root.relativeFilePath(story_node->filePath()));
|
||||
dom_story.setAttribute("sort", story_node->sort());
|
||||
|
||||
append_tokens(dom_story, story_node);
|
||||
}break;
|
||||
case NovelNode::PointDefines: {
|
||||
while (element_stack.last().tagName() != u8"story") {
|
||||
case NovelNode::FragmentSlice:
|
||||
{
|
||||
while (element_stack.last().tagName() != "story") {
|
||||
element_stack.takeLast();
|
||||
}
|
||||
|
||||
auto current_story = element_stack.last();
|
||||
auto fragment_node = std::dynamic_pointer_cast<const example_novel::PointDefines>(syntax_element->element());
|
||||
auto dom_fragment = doc.createElement(u8"fragment");
|
||||
current_story.appendChild(dom_fragment);
|
||||
element_stack.append(dom_fragment);
|
||||
auto slice_node = std::dynamic_pointer_cast<const example_novel::FragmentSlice>(syntax_element->element());
|
||||
auto dom_slice = doc.createElement("slice");
|
||||
current_story.appendChild(dom_slice);
|
||||
element_stack.append(dom_slice);
|
||||
|
||||
dom_fragment.setAttribute(u8"name", fragment_node->name());
|
||||
dom_fragment.setAttribute(u8"address", (qulonglong)fragment_node.get());
|
||||
dom_fragment.setAttribute(u8"file-path", src_root.relativeFilePath(fragment_node->filePath()));
|
||||
|
||||
append_tokens(dom_fragment, fragment_node);
|
||||
dom_slice.setAttribute("name", slice_node->name());
|
||||
dom_slice.setAttribute("address", (qulonglong) slice_node.get());
|
||||
}break;
|
||||
case NovelNode::TextSection:{
|
||||
auto current_text = element_stack.last();
|
||||
auto text_node = std::dynamic_pointer_cast<const example_novel::TextSection>(syntax_element->element());
|
||||
auto dom_text = doc.createElement(u8"text-section");
|
||||
current_text.appendChild(dom_text);
|
||||
case NovelNode::PointDefines:
|
||||
{
|
||||
while (element_stack.last().tagName() != "slice") {
|
||||
element_stack.takeLast();
|
||||
}
|
||||
|
||||
dom_text.setAttribute(u8"text", text_node->content());
|
||||
dom_text.setAttribute(u8"file-path", src_root.relativeFilePath(text_node->filePath()));
|
||||
auto current_slice = element_stack.last();
|
||||
auto point_node = std::dynamic_pointer_cast<const example_novel::PointDefines>(syntax_element->element());
|
||||
auto dom_point = doc.createElement("point");
|
||||
current_slice.appendChild(dom_point);
|
||||
element_stack.append(dom_point);
|
||||
|
||||
dom_point.setAttribute("name", point_node->name());
|
||||
dom_point.setAttribute("address", (qulonglong) point_node.get());
|
||||
dom_point.setAttribute("file-path", src_root.relativeFilePath(point_node->filePath()));
|
||||
|
||||
append_tokens(dom_point, point_node);
|
||||
}break;
|
||||
case NovelNode::TextSection:
|
||||
{
|
||||
while (element_stack.last().tagName() == "text") {
|
||||
element_stack.takeLast();
|
||||
}
|
||||
|
||||
auto current_pnode = element_stack.last();
|
||||
auto text_node = std::dynamic_pointer_cast<const example_novel::TextSection>(syntax_element->element());
|
||||
auto dom_text = doc.createElement("text-section");
|
||||
current_pnode.appendChild(dom_text);
|
||||
|
||||
dom_text.setAttribute("text", text_node->content());
|
||||
dom_text.setAttribute("file-path", src_root.relativeFilePath(text_node->filePath()));
|
||||
|
||||
append_tokens(dom_text, text_node);
|
||||
}break;
|
||||
case NovelNode::PointRefers:{
|
||||
while (element_stack.last().tagName() != u8"article" && element_stack.last().tagName() != u8"story") {
|
||||
case NovelNode::PointRefers:
|
||||
{
|
||||
while (element_stack.last().tagName() != "article" && element_stack.last().tagName() != "slice") {
|
||||
element_stack.takeLast();
|
||||
}
|
||||
|
||||
auto current_pnode = element_stack.last();
|
||||
auto refer_node = std::dynamic_pointer_cast<const example_novel::PointRefers>(syntax_element->element());
|
||||
auto dom_refer = doc.createElement(u8"refer");
|
||||
auto dom_refer = doc.createElement("refer");
|
||||
element_stack.append(dom_refer);
|
||||
current_pnode.appendChild(dom_refer);
|
||||
|
||||
dom_refer.setAttribute(u8"story", refer_node->storyRefer());
|
||||
dom_refer.setAttribute(u8"fragment", refer_node->fragmentRefer());
|
||||
dom_refer.setAttribute(u8"file-path", src_root.relativeFilePath(refer_node->filePath()));
|
||||
dom_refer.setAttribute("story", refer_node->storyRefer());
|
||||
dom_refer.setAttribute("slice", refer_node->sliceRefer());
|
||||
dom_refer.setAttribute("point", refer_node->pointRefer());
|
||||
dom_refer.setAttribute("file-path", src_root.relativeFilePath(refer_node->filePath()));
|
||||
|
||||
append_tokens(dom_refer, refer_node);
|
||||
}break;
|
||||
case NovelNode::VolumeDefine:{
|
||||
while (element_stack.last().tagName() != u8"ast") {
|
||||
case NovelNode::VolumeDefine:
|
||||
{
|
||||
while (element_stack.last().tagName() != "ast") {
|
||||
element_stack.takeLast();
|
||||
}
|
||||
|
||||
auto current_ast = element_stack.last();
|
||||
auto volume_node = std::dynamic_pointer_cast<const example_novel::VolumeDefine>(syntax_element->element());
|
||||
auto dom_volume = doc.createElement(u8"volume");
|
||||
auto dom_volume = doc.createElement("volume");
|
||||
current_ast.appendChild(dom_volume);
|
||||
element_stack.append(dom_volume);
|
||||
|
||||
dom_volume.setAttribute(u8"name", volume_node->name());
|
||||
dom_volume.setAttribute(u8"address", (qulonglong)volume_node.get());
|
||||
dom_volume.setAttribute(u8"file-path", src_root.relativeFilePath(volume_node->filePath()));
|
||||
dom_volume.setAttribute("name", volume_node->name());
|
||||
dom_volume.setAttribute("address", (qulonglong) volume_node.get());
|
||||
dom_volume.setAttribute("file-path", src_root.relativeFilePath(volume_node->filePath()));
|
||||
|
||||
append_tokens(dom_volume, volume_node);
|
||||
}break;
|
||||
case NovelNode::ArticleDefine:{
|
||||
while (element_stack.last().tagName() != u8"volume") {
|
||||
case NovelNode::ArticleDefine:
|
||||
{
|
||||
while (element_stack.last().tagName() != "volume") {
|
||||
element_stack.takeLast();
|
||||
}
|
||||
|
||||
auto current_volume = element_stack.last();
|
||||
auto article_node = std::dynamic_pointer_cast<const example_novel::ArticleDefine>(syntax_element->element());
|
||||
auto dom_article = doc.createElement(u8"article");
|
||||
auto dom_article = doc.createElement("article");
|
||||
current_volume.appendChild(dom_article);
|
||||
element_stack.append(dom_article);
|
||||
|
||||
dom_article.setAttribute(u8"name", article_node->name());
|
||||
dom_article.setAttribute(u8"address", (qulonglong)article_node.get());
|
||||
dom_article.setAttribute(u8"file-path", src_root.relativeFilePath(article_node->filePath()));
|
||||
dom_article.setAttribute("name", article_node->name());
|
||||
dom_article.setAttribute("address", (qulonglong) article_node.get());
|
||||
dom_article.setAttribute("file-path", src_root.relativeFilePath(article_node->filePath()));
|
||||
|
||||
append_tokens(dom_article, article_node);
|
||||
}break;
|
||||
case NovelNode::RankDeclaration:{
|
||||
case NovelNode::RankDeclaration:
|
||||
{
|
||||
auto ast_element = element_stack.first();
|
||||
auto rank_node = std::dynamic_pointer_cast<const example_novel::RankDeclare>(syntax_element->element());
|
||||
auto dom_rank = doc.createElement(u8"rank");
|
||||
auto dom_rank = doc.createElement("rank");
|
||||
ast_element.appendChild(dom_rank);
|
||||
|
||||
dom_rank.setAttribute(u8"rank", rank_node->rankNumber());
|
||||
dom_rank.setAttribute(u8"doc-path", src_root.relativeFilePath(rank_node->filePath()));
|
||||
dom_rank.setAttribute("rank", rank_node->rankNumber());
|
||||
dom_rank.setAttribute("doc-path", src_root.relativeFilePath(rank_node->filePath()));
|
||||
|
||||
append_tokens(dom_rank, rank_node);
|
||||
}break;
|
||||
|
|
|
@ -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();
|
||||
NovelParser::NovelParser() {
|
||||
checker_list << std::make_shared<FragmentExistsCheck>();
|
||||
checker_list << std::make_shared<StoryOrderCheck>();
|
||||
checker_list << std::make_shared<FragmentGraphCheck>();
|
||||
checker_list << std::make_shared<PointGraphCheck>();
|
||||
|
||||
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
|
||||
{
|
||||
QString NovelParser::version() const {
|
||||
return "1.0.0";
|
||||
}
|
||||
|
||||
std::shared_ptr<IContext> NovelParser::parserContext() const
|
||||
{
|
||||
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"小说");
|
||||
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 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());
|
||||
|
||||
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);
|
||||
// 文件语法解析
|
||||
ast_gen::SyntaxParser proc(example_novel::NovalSyntax::getSyntaxTree());
|
||||
auto rst = proc.parse(word_head);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
qDebug().noquote() << QString("%词法解析+语法解析消耗时间:%1 ms。").arg(time_stamp.msecsTo(current_stamp));
|
||||
|
||||
return forst_root;
|
||||
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();
|
||||
QList<std::shared_ptr<ast_gen::SyntaxElement>> docs_node;
|
||||
for (auto& it : forst_root) {
|
||||
auto xitem = std::dynamic_pointer_cast<const ast_gen::SyntaxElement>(it);
|
||||
docs_node.append(std::const_pointer_cast<ast_gen::SyntaxElement>(xitem));
|
||||
context->addChild(docs_node.last());
|
||||
}
|
||||
|
||||
auto x_root = NovalSyntax::tidy(context, docs_node);
|
||||
auto novel_accesstree = std::make_shared<ast_gen::ElementAccess>(x_root);
|
||||
auto access_root = std::make_shared<ast_gen::ElementAccess>(ast_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);
|
||||
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>> {
|
||||
|
@ -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,9 +328,15 @@ 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);
|
||||
|
||||
void appendError(const QList<QString>& errors);
|
||||
QList<QString> errors() const;
|
||||
|
||||
// 通过 SyntaxElement 继承
|
||||
std::shared_ptr<const ast_basic::IExprInstance> bindExpression() const override;
|
||||
int typeMark() 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