This commit is contained in:
codeboss 2025-02-15 15:55:35 +08:00
parent 405ef03a28
commit 40c9eef31f
6 changed files with 157 additions and 31 deletions

View File

@ -4,10 +4,10 @@
#include <QFile> #include <QFile>
#include <libsyntax.h> #include <libsyntax.h>
#include <ast_gen.h> #include <ast_gen.h>
#include <ast_novel.h>
#include <syntax_novel.h> #include <syntax_novel.h>
int main(int argc, char *argv[]) int main(int argc, char* argv[]) {
{
QCoreApplication a(argc, argv); QCoreApplication a(argc, argv);
QFile in("D:\\Projects\\Cpp\\WsNovelParser\\CoreTest\\syntax_example.txt"); QFile in("D:\\Projects\\Cpp\\WsNovelParser\\CoreTest\\syntax_example.txt");
@ -19,13 +19,18 @@ int main(int argc, char *argv[])
ast_gen::SyntaxParser parser(example_novel::NovalSyntax::getSyntaxTree()); ast_gen::SyntaxParser parser(example_novel::NovalSyntax::getSyntaxTree());
auto rst = parser.parse(vwords); auto rst = parser.parse(vwords);
for(auto x : rst) if (rst.first()->totalErrorCount()) {
qDebug() << x->parseSyntax(); auto pos_mark = rst.first()->token()->position();
for (auto item : rst)
auto prag_root = std::make_shared< ast_basic::ExprProgram>("HelloWorld!"); if (item->token()->position() == pos_mark)
for (auto line : item->totalErrors())
qDebug().noquote() << line;
}
else {
auto prag_root = std::make_shared<example_novel::NGlobalElement>("HelloWorld!");
auto structx = parser.getAst(rst.first(), prag_root); auto structx = parser.getAst(rst.first(), prag_root);
parser.astPresent(structx); parser.astPresent(structx);
}
qDebug() << "===========finished=========================="; qDebug() << "===========finished==========================";
return a.exec(); return a.exec();
} }

View File

@ -13,3 +13,117 @@
<><C2B9><EFBFBD> ¹<><C2B9><EFBFBD><EFBFBD><EFBFBD>³<EFBFBD>4 <><C2B9><EFBFBD> ¹<><C2B9><EFBFBD><EFBFBD><EFBFBD>³<EFBFBD>4
¹<><C2B9><EFBFBD>½י<C2BD><D799><EFBFBD><C2B6>ה aldkfjl flwief ¹<><C2B9><EFBFBD>½י<C2BD><D799><EFBFBD><C2B6>ה aldkfjl flwief
} }
{故事 故事名称4
故事介绍段落 aldkfjl flwief
{剧情 剧情名称}
}
{故事 故事名称4
故事介绍段落 aldkfjl flwief
{剧情 剧情名称 剧情介绍}
}
{故事 故事名称4
故事介绍段落 aldkfjl flwief
{剧情 剧情名称
剧情介绍
}
}
{故事 故事名称4
故事介绍段落 aldkfjl flwief
{剧情 剧情名称
剧情介绍
{节点 节点名称}
}
}
{故事 故事名称4
故事介绍段落 aldkfjl flwief
{剧情 剧情名称
剧情介绍
{节点 节点名称
奥龙订饭;爱领克 非两爱看扥}
}
}
{故事 故事名称4
故事介绍段落 aldkfjl flwief
{剧情 剧情名称
剧情介绍
{节点 节点名称
奥龙订饭;爱领克 非两爱看扥
}
}
}
{故事 故事名称4
故事介绍段落 aldkfjl flwief
{剧情 剧情名称
剧情介绍
{节点 节点名称
奥龙订饭;爱领克 非两爱看扥
}
{@节点 节点面&发来垦局&零件扥}
}
}
{故事 故事名称4
故事介绍段落 aldkfjl flwief
{剧情 剧情名称
剧情介绍
{节点 节点名称
奥龙订饭;爱领克 非两爱看扥
}
{@节点 节点面&发来垦局&零件扥
asldkfj 来看房莱肯}
}
}
{故事 故事名称4
故事介绍段落 aldkfjl flwief
{剧情 剧情名称
剧情介绍
{节点 节点名称
奥龙订饭;爱领克 非两爱看扥
}
{@节点 节点面&发来垦局&零件扥
asldkfj 来看房莱肯
}
}
}
{分卷 卷宗名称}
{分卷 卷宗名称
拉开茯苓领赛季发啦肯}
{分卷 卷宗名称
拉开茯苓领赛季发啦肯 lakdjf;alfj
}
{分卷 卷宗名称
拉开茯苓领赛季发啦肯 lakdjf;alfj
{章节 章节名称}
}
{分卷 卷宗名称
拉开茯苓领赛季发啦肯 lakdjf;alfj
{章节 章节名称 昂来看申领发}
}
{分卷 卷宗名称
拉开茯苓领赛季发啦肯 lakdjf;alfj
{章节 章节名称 昂来看申领发
{@节点 故事&剧情&节点}
}
}
{分卷 卷宗名称
拉开茯苓领赛季发啦肯 lakdjf;alfj
{章节 章节名称 昂来看申领发
{@节点 故事&剧情&节点 爱;莱肯爱;冷
森铃但凡拉动垦局}
}
}

View File

@ -61,7 +61,7 @@
</ImportGroup> </ImportGroup>
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<IncludePath>$(SolutionDir)libToken\;$(SolutionDir)libSyntax\;$(IncludePath)</IncludePath> <IncludePath>$(SolutionDir)libWords\;$(SolutionDir)libSyntax\;$(IncludePath)</IncludePath>
<LibraryPath>$(SolutionDir)$(Platform)\$(Configuration)\;$(LibraryPath)</LibraryPath> <LibraryPath>$(SolutionDir)$(Platform)\$(Configuration)\;$(LibraryPath)</LibraryPath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
@ -70,7 +70,7 @@
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Link> <Link>
<AdditionalDependencies>libToken.lib;libSyntax.lib;%(AdditionalDependencies);$(Qt_LIBS_)</AdditionalDependencies> <AdditionalDependencies>libWords.lib;libSyntax.lib;%(AdditionalDependencies);$(Qt_LIBS_)</AdditionalDependencies>
</Link> </Link>
<ClCompile> <ClCompile>
<LanguageStandard>Default</LanguageStandard> <LanguageStandard>Default</LanguageStandard>

View File

@ -53,10 +53,17 @@ std::shared_ptr<IExprInstance> ast_gen::SyntaxParser::getAst(
void ast_gen::SyntaxParser::astPresent(std::shared_ptr<const ast_basic::IExprInstance> node, int depth) { void ast_gen::SyntaxParser::astPresent(std::shared_ptr<const ast_basic::IExprInstance> node, int depth) {
auto msg = QString(depth * 4, ' '); auto msg = QString(depth * 4, ' ');
if (node->definedRule()) if (node->definedRule()) {
qDebug() << msg + node->definedRule()->name(); auto token_seqs = node->tokens();
QList<QString> _contents;
std::transform(token_seqs.begin(), token_seqs.end(),
std::back_inserter(_contents),
[](std::shared_ptr<const lib_token::IToken> t) { return t->content(); });
qDebug().noquote() << msg + node->definedRule()->name() << _contents;
}
else else
qDebug() << msg + "Program"; qDebug().noquote() << msg + "Program";
for (auto it : node->children()) for (auto it : node->children())
astPresent(it, depth + 1); astPresent(it, depth + 1);

View File

@ -206,7 +206,7 @@ namespace lib_syntax {
// 只有在表达式的起始点遇到nullptr才是正常结束。 // 只有在表达式的起始点遇到nullptr才是正常结束。
if (current->token()->tokenType() != lib_token::IActionToken::Type::ElementBegin) { if (current->token()->tokenType() != lib_token::IActionToken::Type::ElementBegin) {
auto ncurs = std::make_shared<MatchCursor>(current); auto ncurs = std::make_shared<MatchCursor>(current);
ncurs->logExprsError(QString("Syntax[0x00001]输入错误,程序提前结束:%1。").arg(current->filePath())); ncurs->logExprsError(QString("SyntaxError[0x00001]输入错误,程序提前结束:%1。").arg(current->filePath()));
ncurs->setFailure(); ncurs->setFailure();
return QList<std::shared_ptr<const MatchCursor>>() << ncurs; return QList<std::shared_ptr<const MatchCursor>>() << ncurs;
} }
@ -238,14 +238,14 @@ namespace lib_syntax {
QList<std::shared_ptr<const MatchCursor>> retvals; QList<std::shared_ptr<const MatchCursor>> retvals;
// 少一个 // 少一个
auto short_one = std::make_shared<MatchCursor>(current); auto short_one = std::make_shared<MatchCursor>(current);
short_one->logExprsError(QString("Syntax[0x00001]语法匹配错误,缺失\"%1\"<row:%2,col:%3,file<%4>>") short_one->logExprsError(QString("SyntaxError[0x00002]语法匹配错误,缺失\"%1\"<row:%2,col:%3,file<%4>>")
.arg(this->_define_peers->reviseWords()) .arg(this->_define_peers->reviseWords())
.arg(w_this->row()).arg(w_this->column()).arg(w_this->file())); .arg(w_this->row()).arg(w_this->column()).arg(w_this->file()));
retvals << short_one; retvals << short_one;
// 错一个 // 错一个
auto error_one = std::make_shared<MatchCursor>(current); auto error_one = std::make_shared<MatchCursor>(current);
error_one->logExprsError(QString("Syntax[0x00001]语法匹配错误,请修正\"%1\"<row:%2,col:%3,file<%4>>") error_one->logExprsError(QString("SyntaxError[0x00003]语法匹配错误,请修正\"%1\"<row:%2,col:%3,file<%4>>")
.arg(w_this->content()).arg(w_this->row()).arg(w_this->column()).arg(w_this->file())); .arg(w_this->content()).arg(w_this->row()).arg(w_this->column()).arg(w_this->file()));
auto tkins = std::make_shared<lib_token::TokenContent>( auto tkins = std::make_shared<lib_token::TokenContent>(
w_this->row(), w_this->column(), w_this->position(), w_this->row(), w_this->column(), w_this->position(),
@ -267,7 +267,7 @@ namespace lib_syntax {
} }
auto clone_ins = std::make_shared<MatchCursor>(current); auto clone_ins = std::make_shared<MatchCursor>(current);
clone_ins->logExprsError(QString("Syntax[0x00001]语法匹配错误,请删除\"%1\"<row:%2,col:%3,file<%4>>") clone_ins->logExprsError(QString("SyntaxError[0x00004]语法匹配错误,请删除\"%1\"<row:%2,col:%3,file<%4>>")
.arg(w_this->content()).arg(w_this->row()).arg(w_this->column()).arg(w_this->file())); .arg(w_this->content()).arg(w_this->row()).arg(w_this->column()).arg(w_this->file()));
clone_ins->setCurrent(chain, remains); clone_ins->setCurrent(chain, remains);
retvals << clone_ins; retvals << clone_ins;

View File

@ -152,7 +152,7 @@ public:
using ReferSyntaxDef = lib_composit::Seqs<Match<LBracket>, Match<ReferMk>, Match<PointWord>, Action<PointRefers, NameText, ref_story_set>, Match<ReferMk>, Action<PointRefers, NameText, ref_slice_set>, Match<ReferMk>, Action<PointRefers, NameText, ref_point_set>, using ReferSyntaxDef = lib_composit::Seqs<Match<LBracket>, Match<ReferMk>, Match<PointWord>, Action<PointRefers, NameText, ref_story_set>, Match<SplitMk>, Action<PointRefers, NameText, ref_slice_set>, Match<SplitMk>, Action<PointRefers, NameText, ref_point_set>,
OptMulti<DeclSyntax>, OptMulti<DeclSyntax>,
Match<RBracket>>; Match<RBracket>>;
class ReferSyntax : public ElementRule<PointRefers, (int) NovelNode::PointRefers, ReferSyntaxDef> { class ReferSyntax : public ElementRule<PointRefers, (int) NovelNode::PointRefers, ReferSyntaxDef> {