update
This commit is contained in:
parent
405ef03a28
commit
40c9eef31f
|
@ -4,28 +4,33 @@
|
|||
#include <QFile>
|
||||
#include <libsyntax.h>
|
||||
#include <ast_gen.h>
|
||||
#include <ast_novel.h>
|
||||
#include <syntax_novel.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication a(argc, argv);
|
||||
int main(int argc, char* argv[]) {
|
||||
QCoreApplication a(argc, argv);
|
||||
|
||||
QFile in("D:\\Projects\\Cpp\\WsNovelParser\\CoreTest\\syntax_example.txt");
|
||||
in.open(QIODevice::ReadOnly|QIODevice::Text);
|
||||
QTextStream tt(&in);
|
||||
lib_words::WordReader reader;
|
||||
auto vwords = reader.wordsFrom(tt, "D:\\Projects\\Cpp\\WsNovelParser\\CoreTest\\syntax_example.txt");
|
||||
QFile in("D:\\Projects\\Cpp\\WsNovelParser\\CoreTest\\syntax_example.txt");
|
||||
in.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||
QTextStream tt(&in);
|
||||
lib_words::WordReader reader;
|
||||
auto vwords = reader.wordsFrom(tt, "D:\\Projects\\Cpp\\WsNovelParser\\CoreTest\\syntax_example.txt");
|
||||
|
||||
ast_gen::SyntaxParser parser(example_novel::NovalSyntax::getSyntaxTree());
|
||||
auto rst = parser.parse(vwords);
|
||||
ast_gen::SyntaxParser parser(example_novel::NovalSyntax::getSyntaxTree());
|
||||
auto rst = parser.parse(vwords);
|
||||
|
||||
for(auto x : rst)
|
||||
qDebug() << x->parseSyntax();
|
||||
|
||||
auto prag_root = std::make_shared< ast_basic::ExprProgram>("HelloWorld!");
|
||||
auto structx = parser.getAst(rst.first(), prag_root);
|
||||
parser.astPresent(structx);
|
||||
|
||||
qDebug() << "===========finished==========================";
|
||||
return a.exec();
|
||||
if (rst.first()->totalErrorCount()) {
|
||||
auto pos_mark = rst.first()->token()->position();
|
||||
for (auto item : rst)
|
||||
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);
|
||||
parser.astPresent(structx);
|
||||
}
|
||||
qDebug() << "===========finished==========================";
|
||||
return a.exec();
|
||||
}
|
||||
|
|
|
@ -12,4 +12,118 @@
|
|||
|
||||
{¹<><C2B9><EFBFBD> ¹<><C2B9><EFBFBD><EFBFBD><EFBFBD>³<EFBFBD>4
|
||||
¹<><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
|
||||
{章节 章节名称 昂来看申领发
|
||||
{@节点 故事&剧情&节点 爱;莱肯爱;冷
|
||||
森铃但凡拉动垦局}
|
||||
}
|
||||
}
|
|
@ -61,7 +61,7 @@
|
|||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<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>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
|
@ -70,7 +70,7 @@
|
|||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Link>
|
||||
<AdditionalDependencies>libToken.lib;libSyntax.lib;%(AdditionalDependencies);$(Qt_LIBS_)</AdditionalDependencies>
|
||||
<AdditionalDependencies>libWords.lib;libSyntax.lib;%(AdditionalDependencies);$(Qt_LIBS_)</AdditionalDependencies>
|
||||
</Link>
|
||||
<ClCompile>
|
||||
<LanguageStandard>Default</LanguageStandard>
|
||||
|
|
|
@ -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) {
|
||||
auto msg = QString(depth * 4, ' ');
|
||||
if (node->definedRule())
|
||||
qDebug() << msg + node->definedRule()->name();
|
||||
else
|
||||
qDebug() << msg + "Program";
|
||||
if (node->definedRule()) {
|
||||
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
|
||||
qDebug().noquote() << msg + "Program";
|
||||
|
||||
for (auto it : node->children())
|
||||
astPresent(it, depth + 1);
|
||||
|
|
|
@ -206,7 +206,7 @@ namespace lib_syntax {
|
|||
// 只有在表达式的起始点遇到nullptr,才是正常结束。
|
||||
if (current->token()->tokenType() != lib_token::IActionToken::Type::ElementBegin) {
|
||||
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();
|
||||
return QList<std::shared_ptr<const MatchCursor>>() << ncurs;
|
||||
}
|
||||
|
@ -238,14 +238,14 @@ namespace lib_syntax {
|
|||
QList<std::shared_ptr<const MatchCursor>> retvals;
|
||||
// 少一个
|
||||
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(w_this->row()).arg(w_this->column()).arg(w_this->file()));
|
||||
retvals << short_one;
|
||||
|
||||
// 错一个
|
||||
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()));
|
||||
auto tkins = std::make_shared<lib_token::TokenContent>(
|
||||
w_this->row(), w_this->column(), w_this->position(),
|
||||
|
@ -267,7 +267,7 @@ namespace lib_syntax {
|
|||
}
|
||||
|
||||
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()));
|
||||
clone_ins->setCurrent(chain, remains);
|
||||
retvals << clone_ins;
|
||||
|
|
|
@ -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>,
|
||||
Match<RBracket>>;
|
||||
class ReferSyntax : public ElementRule<PointRefers, (int) NovelNode::PointRefers, ReferSyntaxDef> {
|
||||
|
|
Loading…
Reference in New Issue