精简分卷语法规则

This commit is contained in:
codeboss 2024-04-18 01:56:44 +08:00
parent 6b20f42416
commit 35214ca78f
11 changed files with 101 additions and 16 deletions

View File

@ -107,6 +107,9 @@
<ItemGroup>
<Text Include="..\x64\test_file\description.txt" />
</ItemGroup>
<ItemGroup>
<None Include="..\x64\test_file\description - 副本.story" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')">
<Import Project="$(QtMsBuild)\qt.targets" />

View File

@ -44,4 +44,7 @@
<ItemGroup>
<Text Include="..\x64\test_file\description.txt" />
</ItemGroup>
<ItemGroup>
<None Include="..\x64\test_file\description - 副本.story" />
</ItemGroup>
</Project>

View File

@ -6,9 +6,9 @@
<LocalDebuggerCommandArguments>-path D:\Projects\Cpp\WsNovelParser\x64\test_file</LocalDebuggerCommandArguments>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<QtLastBackgroundBuild>2024-04-16T15:45:16.4474871Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2024-04-17T14:40:52.6884025Z</QtLastBackgroundBuild>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<QtLastBackgroundBuild>2024-04-16T15:45:16.7053041Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2024-04-17T14:40:53.5267874Z</QtLastBackgroundBuild>
</PropertyGroup>
</Project>

View File

@ -422,11 +422,11 @@ void tools_printer::volumes_anchors_define(const QList<std::shared_ptr<StoryVolu
}
}
QString printer::tools_printer::storylines_paint(const QList<std::shared_ptr<StoryLine>> lines) {
auto get_node_name = [](const std::shared_ptr<Access> item){
return u8"node_" + QString::number((qulonglong)item->accessPeers()->element().get());
};
QString printer::tools_printer::storylines_paint(const QList<std::shared_ptr<StoryLine>> &lines) {
QHash<QString, std::shared_ptr<Access>> node_records;
QString nodes_description;
for (auto& story : lines) {
@ -434,7 +434,7 @@ QString printer::tools_printer::storylines_paint(const QList<std::shared_ptr<Sto
node_records[story_elem->signature()] = story;
nodes_description += get_node_name(story) + QString(u8"[label=\"%1\",shape=\"cds\"]\n").arg(story_elem->name());
for (auto frag : story->elements()) {
for (auto &frag : story->elements()) {
auto fragment_peers = frag->accessPeers()->element();
if (fragment_peers->typeMark() == (int)example_novel::NovelNode::FragmentDefine) {
auto fragment_elem = std::dynamic_pointer_cast<const example_novel::FragmentDefine>(fragment_peers);
@ -465,3 +465,66 @@ QString printer::tools_printer::storylines_paint(const QList<std::shared_ptr<Sto
return QString(u8"digraph{ rankdir = LR \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) {
QHash<QString, std::shared_ptr<Element>> node_records;
QString clusters_description;
for (auto& story : lines) {
QString nodes_description;
for (auto &frag : story->elements()) {
auto fragment_peers = frag->accessPeers()->element();
if (fragment_peers->typeMark() == (int)example_novel::NovelNode::FragmentDefine) {
auto fragment_elem = std::dynamic_pointer_cast<const example_novel::FragmentDefine>(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());
}
}
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 }")
.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 {
QString nodes_description;
for (auto& fragment_access : article_access->children()) {
if (fragment_access->element()->typeMark() == (int)example_novel::NovelNode::FragmentRefer) {
auto refer_fragment = std::dynamic_pointer_cast<const example_novel::FragmentRefers>(fragment_access->element());
nodes_description += QString(u8"fragment_%1[label=\"%2\",shape=\"plaintext\"]\n")
.arg((qulonglong)refer_fragment.get()).arg(refer_fragment->fragmentRefer());
auto symbo_refer = node_records[refer_fragment->referSignature()];
arrows_out << QString(u8"fragment_%1 -- %2\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())
.arg(article_define->name()).arg(nodes_description);
};
QString arrows_link;
for (auto &vol : vols) {
QString members_description;
for (auto& eref : vol->accessPeers()->children()) {
QList<QString> arrows_temp;
switch ((example_novel::NovelNode)eref->element()->typeMark()){
case example_novel::NovelNode::ArticleDefine:
members_description += article_cluster(eref, arrows_temp);
break;
default:
break;
}
for (auto& arrow : arrows_temp) {
arrows_link += arrow;
}
}
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 }")
.arg((qulonglong)volume_elem.get()).arg(members_description).arg(volume_elem->name());
}
return QString("graph scale{ %1 \n %2}").arg(clusters_description).arg(arrows_link);
}

View File

@ -154,6 +154,7 @@ namespace printer {
void storylines_anchors_define(const QList<std::shared_ptr<StoryLine>> &list, const QDir &destdir);
void volumes_anchors_define(const QList<std::shared_ptr<StoryVolume>> &list, const QDir &destdir);
QString storylines_paint(const QList<std::shared_ptr<StoryLine>> lines);
QString storylines_paint(const QList<std::shared_ptr<StoryLine>> &lines);
QString volumes_paint(const QList<std::shared_ptr<StoryVolume>> &vols, const QList<std::shared_ptr<StoryLine>> &lines);
};
}

View File

@ -74,6 +74,17 @@ int main(int argc, char* argv[]) {
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"));
if (vols_file.open(QIODevice::WriteOnly | QIODevice::Text)) {
QTextStream txt(&vols_file);
txt.setCodec(u8"UTF-8");
txt << vols_src;
txt.flush();
}
system("fdp -Tsvg volumes_group.dot -o volumes_group.svg");
std::function<void(std::shared_ptr<const ast_gen::ElementAccess>, int)> tnode_print =
[&](std::shared_ptr<const ast_gen::ElementAccess> node, int intend) {
@ -156,6 +167,10 @@ int main(int argc, char* argv[]) {
auto img = doc_inst.createElement(u8"img");
img.setAttribute(u8"src", u8"file:///" + QDir::current().filePath(u8"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"));
dom_relate.appendChild(img);
QTextStream tout(&tfile);
doc_inst.save(tout, 2);
@ -163,7 +178,6 @@ int main(int argc, char* argv[]) {
}
}
system("dot -Tsvg relates.dot -o relates.svg");
tnode_print(novel_accesstree, 0);
}
catch (lib_syntax::SyntaxException* e) {

View File

@ -5,9 +5,9 @@
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<QtLastBackgroundBuild>2024-04-16T15:45:17.3540175Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2024-04-17T14:40:53.7303429Z</QtLastBackgroundBuild>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<QtLastBackgroundBuild>2024-04-16T15:45:17.5173655Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2024-04-17T14:40:53.9873724Z</QtLastBackgroundBuild>
</PropertyGroup>
</Project>

View File

@ -5,9 +5,9 @@
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<QtLastBackgroundBuild>2024-04-16T15:45:16.8232289Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2024-04-17T14:40:54.1672966Z</QtLastBackgroundBuild>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<QtLastBackgroundBuild>2024-04-16T15:45:17.0319953Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2024-04-17T14:40:54.3959724Z</QtLastBackgroundBuild>
</PropertyGroup>
</Project>

View File

@ -114,6 +114,7 @@ std::tuple<BaseRule::MatchResult, uint> Seqs::match(const QList<std::shared_ptr<
auto token_offset = 0;
QString token_seqs = this->token_present();
for (auto& r : mbrs_store) {
auto v_token_seqs = r->token_present();
auto result = r->match(stream.mid(token_offset));
token_offset += std::get<1>(result);

View File

@ -85,7 +85,7 @@ ExprRule(u8"volume_define", (int)NovelExprs::VOLUME_DEFINE)
.reloadRule(remove_nl,
std::make_shared<const Seqs>(Buff << OptMulT(newl)
<< MR(leftb) << OptMulT(newl) << MR(volume) << OptMulT(newl) << MR(ntext) << OptMulT(newl)
<< OptMulR(std::make_shared<const Any>(Buff << fragment_refer << decl_expr << article_decl))
<< OptMulR(std::make_shared<const Any>(Buff << decl_expr << article_decl))
<< MR(rightb) << OptMulT(newl)));
auto document_define =

View File

@ -2,9 +2,9 @@
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<QtLastBackgroundBuild>2024-04-16T15:45:17.1080516Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2024-04-17T14:40:54.5095005Z</QtLastBackgroundBuild>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<QtLastBackgroundBuild>2024-04-16T15:45:17.2738131Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2024-04-17T14:40:54.8818904Z</QtLastBackgroundBuild>
</PropertyGroup>
</Project>