精简和改进

This commit is contained in:
codeboss 2024-07-26 16:22:34 +08:00
parent 97763d28e8
commit 4d3d19c6a7
2 changed files with 17 additions and 16 deletions

View File

@ -23,7 +23,7 @@ std::tuple<IBasicRule::MatchResult, std::shared_ptr<const IWordBase>> TokenMatch
}
else {
rt_inst->appendParseErrors(rt_inst->currentFile(), head->position(),
QString(u8"Syntax[0x00001]语法匹配错误,无法识别\"%1\"<row:%2,col:%3>(应该为:%4)\n\t目标语法:'%5'\n")
QString(u8"Syntax[0x00001]语法匹配错误,无法识别\"%1\"<row:%2,col:%3>(应该为:%4)\n\t目标语法:%5。\n")
.arg(head->content()).arg(head->row()).arg(head->column()).arg(this->define_peer->reviseWords())
.arg(rt_inst->currentExprRule()->token_present()));
return std::make_tuple(IBasicRule::MatchResult::Part, head);

View File

@ -12,6 +12,7 @@ auto leftb = std::make_shared<LeftBracket>(); // {
auto rightb = std::make_shared<RightBracket>(); // }
auto refers = std::make_shared<ReferMark>(); // @
auto declare = std::make_shared<DeclareSymbo>(); // #
auto split_mark = std::make_shared<Split>(); // &
auto rank_key = std::make_shared<Keywords>(u8"排序", 0xAEu); // 排序
auto story_key = std::make_shared<Keywords>(u8"故事", 0xAAu); // 故事
@ -19,7 +20,6 @@ auto numbers = std::make_shared<Numbers>(); // [0-9
auto frag_key = std::make_shared<Keywords>(u8"情节", 0xABu); // 情节
auto volume_key = std::make_shared<Keywords>(u8"分卷", 0xACu); // 分卷
auto article_key = std::make_shared<Keywords>(u8"章节", 0xADu); // 章节
auto split_mark = std::make_shared<Split>(); // &
auto vtext = std::make_shared<VTextSection>(); // ^([^\\{\\}\@&]+)
auto name_text = std::make_shared<NameSection>(); // ^([^\\{\\}@&]+)
@ -35,32 +35,33 @@ auto name_text = std::make_shared<NameSection>(); // ^
#define OptMulR(rule) std::make_shared<const Rept>(rule, 0, INT_MAX)
// multi+
#define MultiR(rule) std::make_shared<const Rept>(rule, 1, INT_MAX)
// opt?
#define OptR(rule) std::make_shared<const Rept>(rule, 0, 1)
auto decl_comp = std::make_shared<const Any>(Rules{ MR(numbers), MR(vtext), MR(name_text), MR(split_mark) });
auto decl_expr = ElementRule<TextSection>(u8"decl_section", (int)NovelExprs::DESC_SECTION).reloadRule(
MultiR(decl_comp));
MultiR(std::make_shared<const Any>(Rules{ MR(numbers), MR(vtext), MR(refers), MR(split_mark)}))
);
auto fragment_decl = ElementRule<FragmentDefine>(u8"fragment_define", (int)NovelExprs::FRAG_DEFINES).reloadRule(
std::make_shared<const Seqs>(
Rules{ MR(leftb), MR(frag_key), MR(name_text) } <<
OptMulR(decl_expr) <<
std::make_shared<const Seqs>(Rules{
MR(leftb), MR(frag_key), MR(name_text) } <<
OptR(decl_expr) <<
MR(rightb)
));
auto fragment_refer = ElementRule<FragmentRefers>(u8"fragment_refer", (int)NovelExprs::FRAG_REFERS).reloadRule(
std::make_shared<const Seqs>(
Rules{ MR(leftb), MR(refers), MR(frag_key), MR(name_text), MR(split_mark), MR(name_text) } <<
OptMulR(decl_expr) <<
std::make_shared<const Seqs>(Rules{
MR(leftb), MR(refers), MR(frag_key), MR(name_text), MR(split_mark), MR(name_text) } <<
OptR(decl_expr) <<
MR(rightb)
));
auto fragment_comp = std::make_shared<const Any>(Rules{ fragment_decl, fragment_refer, decl_expr });
auto story_define = ElementRule<StoryDefine>(u8"story_define", (int)NovelExprs::STORY_DEFINES).reloadRule(
std::make_shared<const Seqs>(
Rules{ MR(leftb), MR(story_key), MR(name_text) } <<
OptMulR(fragment_comp) <<
std::make_shared<const Seqs>(Rules{
MR(leftb), MR(story_key), MR(name_text) } <<
OptMulR(std::make_shared<const Any>(Rules{ fragment_decl, fragment_refer, decl_expr })) <<
MR(rightb)
));
// ===================================================================
@ -79,8 +80,8 @@ auto volume_decl = ElementRule<VolumeDefine>(u8"volume_define", (int)NovelExprs:
));
auto rank_define = ElementRule<RankDeclare>(u8"rank_define", (int)NovelNode::RankDeclaration).reloadRule(
std::make_shared<const Seqs>(
Rules{ MR(declare), MR(rank_key), MR(numbers) }
std::make_shared<const Seqs>(Rules{
MR(declare), MR(rank_key), MR(numbers) }
));
auto document_define = ElementRule<Document>(u8"decls-doc", (int)NovelExprs::DOC_DEFINES).reloadRule(