From 367140bef2f97111112b83bae6a54c198d0b05b2 Mon Sep 17 00:00:00 2001 From: codeboss <2422523675@qq.com> Date: Sun, 21 Jul 2024 10:40:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WsNovelParser/novelparser.cpp | 2 +- libSyntax/ast_novel.h | 6 +- libSyntax/libsyntax.cpp | 300 ++++++++++++++++++---------------- libSyntax/libsyntax.h | 71 ++++---- libSyntax/syntax_novel.cpp | 16 +- libToken/tokens_novel.cpp | 4 +- 6 files changed, 209 insertions(+), 190 deletions(-) diff --git a/WsNovelParser/novelparser.cpp b/WsNovelParser/novelparser.cpp index f3521c2..a54987d 100644 --- a/WsNovelParser/novelparser.cpp +++ b/WsNovelParser/novelparser.cpp @@ -43,7 +43,7 @@ QList> NovelParser::parse(const QFil context->setCurrentFile(file.canonicalFilePath()); auto words = word_reader->wordsFrom(file.canonicalFilePath()); - lib_syntax::IBasicRule::ErrOccurs modify = lib_syntax::IBasicRule::ErrOccurs::None; + lib_syntax::IBasicRule::ErrDeals modify = lib_syntax::IBasicRule::ErrDeals::None; this->syntax_defines->parse(context, words, modify); } diff --git a/libSyntax/ast_novel.h b/libSyntax/ast_novel.h index fabcb84..c425c84 100644 --- a/libSyntax/ast_novel.h +++ b/libSyntax/ast_novel.h @@ -184,14 +184,14 @@ namespace lib_syntax { } virtual std::tuple> - parse(std::shared_ptr rt_inst, std::shared_ptr head, IBasicRule::ErrOccurs &fx_type) const override { + parse(std::shared_ptr rt_inst, std::shared_ptr head, IBasicRule::ErrDeals &fx_type) const override { std::shared_ptr elm_ast = this->newEmptyInstance(); auto text_present = this->token_present(); rt_inst->pushExprRule(this->shared_from_this()); rt_inst->pushExprInst(elm_ast); - IBasicRule::ErrOccurs fixed = IBasicRule::ErrOccurs::None; + IBasicRule::ErrDeals fixed = IBasicRule::ErrDeals::None; auto rstg = child_store->parse(rt_inst, head, fixed); auto tokens_decl = elm_ast->tokens(); @@ -203,7 +203,7 @@ namespace lib_syntax { break; case IBasicRule::MatchResult::Success: { if (!std::dynamic_pointer_cast(elm_ast)) { - auto start_pos = tokens_decl.first()->position(); + auto start_pos = head->position(); rt_inst->clearErrors(rt_inst->currentFile(), start_pos); } diff --git a/libSyntax/libsyntax.cpp b/libSyntax/libsyntax.cpp index e523e26..19a0846 100644 --- a/libSyntax/libsyntax.cpp +++ b/libSyntax/libsyntax.cpp @@ -11,92 +11,100 @@ TokenMatch::TokenMatch(shared_ptr define) : define_peer(defi QList> TokenMatch::children() const { return QList>(); } -tuple> -TokenMatch::parse(shared_ptr rt_inst, shared_ptr head, ErrOccurs& fx_type) const +ParseResult TokenMatch::parse(shared_ptr rt_inst, shared_ptr head, ErrDeals& fx_type) const { if (!head) { rt_inst->appendParseError(rt_inst->currentFile(), -1, QString(u8"Syntax[0x0000]token流(%1)提前终止").arg(rt_inst->currentFile())); - return make_tuple(IBasicRule::MatchResult::Fail, head); + return ParseResult(); } + ParseResult result_ret; auto match_result = define_peer->analysis(head); if (get<0>(match_result)) { rt_inst->currentExprInst()->addToken(get<0>(match_result)); + decltype(result_ret.result_repair) v_result; if (get<1>(match_result)) { - return make_tuple(IBasicRule::MatchResult::Success, make_shared(get<1>(match_result), head->nextWord())); + v_result = make_tuple(MatchResult::Success, make_shared(get<1>(match_result), head->nextWord())); } else { - return make_tuple(IBasicRule::MatchResult::Success, head->nextWord()); + v_result = make_tuple(MatchResult::Success, head->nextWord()); } + + if (fx_type == ErrDeals::None) + result_ret.result_straight = v_result; + else + result_ret.result_repair = v_result; } else { switch (fx_type) { - case lib_syntax::IBasicRule::ErrOccurs::None: - return make_tuple(IBasicRule::MatchResult::Part, head); - case lib_syntax::IBasicRule::ErrOccurs::Replace: - fx_type = IBasicRule::ErrOccurs::None; - rt_inst->appendParseError(rt_inst->currentFile(), head->position(), - QString(u8"Syntax[0x00001]语法匹配错误,不能识别token:\"%1\"(应该为:%4)") - .arg(head->content()).arg(head->row()).arg(head->column()).arg(this->define_peer->reviseWords())); - return make_tuple(IBasicRule::MatchResult::Success, head->nextWord()); - case lib_syntax::IBasicRule::ErrOccurs::Absence: - fx_type = IBasicRule::ErrOccurs::None; - rt_inst->appendParseError(rt_inst->currentFile(), head->position(), - QString(u8"Syntax[0x00001]语法匹配错误,缺少token:\"%1\"") - .arg(this->define_peer->reviseWords()).arg(head->row()).arg(head->column())); - return make_tuple(IBasicRule::MatchResult::Success, head); - case lib_syntax::IBasicRule::ErrOccurs::Surplus: - fx_type = IBasicRule::ErrOccurs::None; + case lib_syntax::ErrDeals::Replace: + fx_type = ErrDeals::None; + result_ret.result_repair = make_tuple(MatchResult::Success, head->nextWord()); + break; + + case lib_syntax::ErrDeals::Absence: + fx_type = ErrDeals::None; + result_ret.result_repair = make_tuple(MatchResult::Success, head); + break; + + case lib_syntax::ErrDeals::Surplus: + fx_type = ErrDeals::None; { auto temp_head = head->nextWord(); auto match_result = define_peer->analysis(temp_head); if (get<0>(match_result)) { - rt_inst->appendParseError(rt_inst->currentFile(), head->position(), - QString(u8"Syntax[0x00001]语法匹配错误,多余token:\"%1\"") - .arg(head->content()).arg(head->row()).arg(head->column())); - rt_inst->currentExprInst()->addToken(get<0>(match_result)); - if (get<1>(match_result)) { - return make_tuple(IBasicRule::MatchResult::Success, make_shared(get<1>(match_result), temp_head->nextWord())); - } - else { - return make_tuple(IBasicRule::MatchResult::Success, temp_head->nextWord()); - } + if (get<1>(match_result)) + result_ret.result_repair = make_tuple(MatchResult::Success, make_shared(get<1>(match_result), temp_head->nextWord())); + else + result_ret.result_repair = make_tuple(MatchResult::Success, temp_head->nextWord()); } else { - return make_tuple(IBasicRule::MatchResult::Part, head); + result_ret.result_repair = make_tuple(MatchResult::Part, head); } } break; + default: + result_ret.result_straight = make_tuple(MatchResult::Part, head); break; } } + + return result_ret; } QString TokenMatch::token_present() const { - return QString(u8"<%1>").arg(this->define_peer->reviseWords()); + return QString(u8"%1 ").arg(this->define_peer->reviseWords()); } Rept::Rept(shared_ptr rule, int min, int max) : rule_peer(rule), min_match(min), max_match(max) {} QList> Rept::children() const { return QList>() << rule_peer; } -tuple> -Rept::parse(shared_ptr rt_inst, shared_ptr head, IBasicRule::ErrOccurs& fx_type) const { - auto temp_head = head; +ParseResult Rept::parse(shared_ptr rt_inst, shared_ptr head, ErrDeals& fx_type) const { + ParseResult result_final; + bool straight_mark = fx_type == ErrDeals::None; + auto temp_head = head; // min-match for (auto idx = 0; idx < min_match; ++idx) { auto result_gen = rule_peer->parse(rt_inst, temp_head, fx_type); - switch (get<0>(result_gen)) { - case IBasicRule::MatchResult::Fail: - return make_tuple(IBasicRule::MatchResult::Part, temp_head); - case IBasicRule::MatchResult::Part: - return make_tuple(IBasicRule::MatchResult::Part, get<1>(result_gen)); + auto v_result = result_gen.result_straight; + if (std::get<0>(v_result) == MatchResult::None) + v_result = result_gen.result_repair; + + switch (std::get<0>(v_result)) { + case MatchResult::Part: + if (straight_mark) + result_final.result_straight = make_tuple(MatchResult::Part, std::get<1>(v_result)); + else + result_final.result_repair = make_tuple(MatchResult::Part, std::get<1>(v_result)); + return result_final; + default: - temp_head = get<1>(result_gen); + temp_head = std::get<1>(v_result); break; } } @@ -107,48 +115,74 @@ Rept::parse(shared_ptr rt_inst, shared_ptr head, IBas break; auto result_gen = rule_peer->parse(rt_inst, temp_head, fx_type); - switch (get<0>(result_gen)) { - case IBasicRule::MatchResult::Fail: - case IBasicRule::MatchResult::Part: - return make_tuple(IBasicRule::MatchResult::Success, temp_head); + auto v_result = result_gen.result_straight; + if (std::get<0>(v_result) == MatchResult::None) + v_result = result_gen.result_repair; + + switch (get<0>(v_result)) { + case MatchResult::Part: + if(straight_mark) + result_final.result_straight = make_tuple(MatchResult::Success, temp_head); + else + result_final.result_repair = make_tuple(MatchResult::Success, temp_head); + return result_final; + default: - temp_head = get<1>(result_gen); + temp_head = get<1>(v_result); break; } } - return make_tuple(IBasicRule::MatchResult::Success, temp_head); + if(straight_mark) + result_final.result_straight = make_tuple(MatchResult::Success, temp_head); + else + result_final.result_repair = make_tuple(MatchResult::Success, temp_head); + return result_final; } QString Rept::token_present() const { - return u8"(" + this->rule_peer->token_present() + QString(u8"{%1, %2}").arg(min_match).arg(max_match) + u8")"; + return u8"(" + this->rule_peer->token_present() + QString(u8"){%1, %2}").arg(min_match).arg(max_match); } Seqs::Seqs(const QList> mbrs) : mbrs_store(mbrs) {} QList> Seqs::children() const { return mbrs_store; } -tuple> -Seqs::parse(shared_ptr rt_inst, shared_ptr head, IBasicRule::ErrOccurs& fx_type) const { - auto temp_head = head; +ParseResult Seqs::parse(shared_ptr rt_inst, shared_ptr head, ErrDeals& fx_type) const { + ParseResult result_final; + auto temp_head = head; + bool straight_mark = fx_type == ErrDeals::None; for (auto& r : mbrs_store) { + auto rule_present = r->token_present(); auto rst_gene = r->parse(rt_inst, temp_head, fx_type); - switch (get<0>(rst_gene)) { - case IBasicRule::MatchResult::Fail: - return make_tuple(IBasicRule::MatchResult::Part, temp_head); - case IBasicRule::MatchResult::Part: - return rst_gene; - case IBasicRule::MatchResult::Success: - temp_head = get<1>(rst_gene); + + auto v_result = rst_gene.result_straight; + if(std::get<0>(v_result) == MatchResult::None) + v_result = rst_gene.result_repair; + + switch (get<0>(v_result)) { + case MatchResult::Part: + if(straight_mark) + result_final.result_straight = v_result; + else + result_final.result_repair = v_result; + return result_final; + + case MatchResult::Success: + temp_head = get<1>(v_result); break; default: break; } } - return make_tuple(IBasicRule::MatchResult::Success, temp_head); + if (straight_mark) + result_final.result_straight = make_tuple(MatchResult::Success, temp_head); + else + result_final.result_repair = make_tuple(MatchResult::Success, temp_head); + return result_final; } QString Seqs::token_present() const @@ -156,55 +190,49 @@ QString Seqs::token_present() const QString content; for (auto& it : children()) content += it->token_present(); - return QString(u8"(%1)").arg(content); + return content; } -//tuple, shared_ptr> +//tuple, shared_ptr> Any::Any(const QList> mbrs) : mbrs_store(mbrs) {} QList> Any::children() const { return mbrs_store; } -class words_span { -public: - int row_span, column_span; - words_span(int rspan, int cspan) :row_span(rspan), column_span(cspan) {} - bool operator>(const words_span& other) { - if (row_span > other.row_span) - return true; - if (row_span == other.row_span) - return column_span > other.column_span; - return false; - } -}; -tuple> -Any::parse(shared_ptr rt_inst, shared_ptr head, IBasicRule::ErrOccurs& fx_type) const { - tuple, uint64_t> temp_result = make_tuple(nullptr, 0); +ParseResult Any::parse(shared_ptr rt_inst, shared_ptr head, ErrDeals& fx_type) const { auto rule_present = this->token_present(); - for (auto& fork : mbrs_store) { - auto gen = fork->parse(rt_inst, head, fx_type); - switch (get<0>(gen)) { - // 遇到成功的直接返回解析结果 - case IBasicRule::MatchResult::Success: - return gen; - case IBasicRule::MatchResult::Fail: { - if (!get<0>(temp_result)) - temp_result = make_tuple(fork, 0); - }break; - case IBasicRule::MatchResult::Part: { - auto span = get<1>(gen)->position() - head->position(); - if (span >= get<1>(temp_result)) - temp_result = make_tuple(fork, span); - } - default: - break; + ParseResult result_final; + bool straight_mark = fx_type == ErrDeals::None; + + switch (fx_type) { + case ErrDeals::None: { + for (auto& fork : mbrs_store) { + auto gen = fork->parse(rt_inst, head, fx_type); + + switch (get<0>(gen.result_straight)) { + // 遇到成功的直接返回解析结果 + case MatchResult::Success: + return gen; + + case MatchResult::Part: { + auto span = get<1>(gen)->position() - head->position(); + if (span >= get<1>(temp_result)) + temp_result = make_tuple(fork, span); + } + default: + break; + } } + // 分析最匹配的分支 + rt_inst->clearErrors(rt_inst->currentFile(), head->position()); + auto temp = get<0>(temp_result)->parse(rt_inst, head, fx_type); + return make_tuple(MatchResult::Part, get<1>(temp)); + } + + default: + break; } - // 分析最匹配的分支 - rt_inst->clearErrors(rt_inst->currentFile(), head->position()); - auto temp = get<0>(temp_result)->parse(rt_inst, head, fx_type); - return make_tuple(IBasicRule::MatchResult::Part, get<1>(temp)); } QString Any::token_present() const @@ -213,7 +241,7 @@ QString Any::token_present() const for (auto& it : children()) { members_content += it->token_present() + u8"|"; } - return u8"(" + members_content.mid(0, members_content.size() - 1) + u8")"; + return members_content.mid(0, members_content.size() - 1); } @@ -240,53 +268,41 @@ QList> ExprRule::children() const { } #include -tuple> -ExprRule::parse(shared_ptr rt_inst, shared_ptr head, IBasicRule::ErrOccurs& fx_type) const { - QList opts_list = { - IBasicRule::ErrOccurs::None, IBasicRule::ErrOccurs::Surplus, IBasicRule::ErrOccurs::Absence, IBasicRule::ErrOccurs::Replace - }; +tuple> +ExprRule::parse(shared_ptr rt_inst, shared_ptr head, ErrDeals& fx_type) const { + auto text_present = this->token_present(); + shared_ptr elm_ast = this->newEmptyInstance(); - auto opt_current_itor = opts_list.cbegin(); - tuple> ret_tuple; - do { - auto opt_val = *opt_current_itor; - shared_ptr elm_ast = this->newEmptyInstance(); - auto text_present = this->token_present(); + rt_inst->pushExprRule(this->shared_from_this()); + rt_inst->pushExprInst(elm_ast); - rt_inst->pushExprRule(this->shared_from_this()); - rt_inst->pushExprInst(elm_ast); - - ret_tuple = child_store->parse(rt_inst, head, opt_val); - switch (get<0>(ret_tuple)) { - case IBasicRule::MatchResult::Success: { - if (!dynamic_pointer_cast(elm_ast) && opt_val == IBasicRule::ErrOccurs::None) { - auto start_pos = head->position(); - rt_inst->clearErrors(rt_inst->currentFile(), start_pos); - } - - rt_inst->popExprInst(); - rt_inst->popExprRule(); - - if (rt_inst->currentExprInst()) { - rt_inst->currentExprInst()->addChild(elm_ast); - } - else { - rt_inst->appendDocInst(elm_ast); - } - }return ret_tuple; - case IBasicRule::MatchResult::Part: - if (!dynamic_pointer_cast(elm_ast)) - rt_inst->clearErrors(rt_inst->currentFile(), head->position()); - case IBasicRule::MatchResult::Fail: { - rt_inst->popExprInst(); - rt_inst->popExprRule(); - }break; - default: - break; + auto ret_tuple = child_store->parse(rt_inst, head, fx_type); + switch (get<0>(ret_tuple)) { + case MatchResult::Success: + if (!dynamic_pointer_cast(elm_ast) && fx_type == ErrDeals::None) { + rt_inst->clearErrors(rt_inst->currentFile(), head->position()); } - opt_current_itor++; - } while (fx_type != IBasicRule::ErrOccurs::None && opt_current_itor != opts_list.cend()); + rt_inst->popExprInst(); + rt_inst->popExprRule(); + + if (rt_inst->currentExprInst()) { + rt_inst->currentExprInst()->addChild(elm_ast); + } + else { + rt_inst->appendDocInst(elm_ast); + } + break; + + case MatchResult::Part: + case MatchResult::Fail: + rt_inst->popExprInst(); + rt_inst->popExprRule(); + break; + + default: + break; + } return ret_tuple; } diff --git a/libSyntax/libsyntax.h b/libSyntax/libsyntax.h index 1e67043..9c17f7c 100644 --- a/libSyntax/libsyntax.h +++ b/libSyntax/libsyntax.h @@ -35,12 +35,12 @@ namespace lib_syntax { public: virtual ~IContext() = default; - virtual void setCurrentFile(const QString &path) = 0; + virtual void setCurrentFile(const QString& path) = 0; virtual QString currentFile() const = 0; - virtual void appendParseError(const QString & file_path, int start, const QString &error_msg) = 0; + virtual void appendParseError(const QString& file_path, int start, const QString& error_msg) = 0; virtual QStringList errors() const = 0; - virtual void clearErrors(const QString &file_path, int start) = 0; + virtual void clearErrors(const QString& file_path, int start) = 0; virtual void appendDocInst(std::shared_ptr inst) = 0; virtual QList> getDocInsts() const = 0; @@ -60,6 +60,33 @@ namespace lib_syntax { virtual QList> currentExprRuleStack() const = 0; }; + /** + * @brief 匹配结果 + */ + enum class MatchResult { + None, // 不适用 + Success, // 符合匹配条件 + Part, // 部分匹配 + }; + + /** + * @brief 修正类型 + */ + enum class ErrDeals { + None, // 不修复 + Surplus, // 多一个词 + Absence, // 少一个词 + Replace, // 错一个词 + }; + + /** + * 匹配结果,返回直接匹配结果和修复匹配结果. + */ + struct ParseResult { + std::tuple> result_straight = std::make_tuple(MatchResult::None, nullptr); + std::tuple> result_repair = std::make_tuple(MatchResult::None, nullptr); + }; + /** * @brief 基础语法匹配规则接口 */ @@ -72,24 +99,6 @@ namespace lib_syntax { */ virtual QList> children() const = 0; - /** - * @brief 匹配结果 - */ - enum class MatchResult { - Success, // 符合匹配条件 - Part, // 部分匹配 - Fail // 从第一个词起完全不匹配 - }; - - /** - * @brief 修正类型 - */ - enum class ErrOccurs { - None, // 无 - Replace, // 错一个词 - Absence, // 少一个词 - Surplus // 多一个词 - }; /** * @brief 解析 @@ -98,8 +107,7 @@ namespace lib_syntax { * @param fx_type 修正措施 * @return 返回结果<匹配完成新列表头,匹配长度> */ - virtual std::tuple> - parse(std::shared_ptr rt_inst, std::shared_ptr head, ErrOccurs &fx_type) const = 0; + virtual ParseResult parse(std::shared_ptr rt_inst, std::shared_ptr head, ErrDeals& fx_type) const = 0; /** * 返回匹配语法规则的词法序列表达 @@ -123,8 +131,7 @@ namespace lib_syntax { // IBasicRule interface public: virtual QList> children() const override; - virtual std::tuple> - parse(std::shared_ptr rt_inst, std::shared_ptr head, ErrOccurs &fx_type) const override; + virtual ParseResult parse(std::shared_ptr rt_inst, std::shared_ptr head, ErrDeals& fx_type) const override; virtual QString token_present() const override; }; @@ -143,8 +150,7 @@ namespace lib_syntax { // IBasicRule interface public: virtual QList> children() const override; - virtual std::tuple> - parse(std::shared_ptr rt_inst, std::shared_ptr head, ErrOccurs &fx_type) const override; + virtual ParseResult parse(std::shared_ptr rt_inst, std::shared_ptr head, ErrDeals& fx_type) const override; virtual QString token_present() const override; }; @@ -161,8 +167,7 @@ namespace lib_syntax { // IBasicRule interface public: virtual QList> children() const override; - virtual std::tuple> - parse(std::shared_ptr rt_inst, std::shared_ptr head, ErrOccurs &fx_type) const override; + virtual ParseResult parse(std::shared_ptr rt_inst, std::shared_ptr head, ErrDeals& fx_type) const override; virtual QString token_present() const override; }; @@ -180,8 +185,7 @@ namespace lib_syntax { // IBasicRule interface public: virtual QList> children() const override; - virtual std::tuple> - parse(std::shared_ptr rt_inst, std::shared_ptr head, ErrOccurs &fixed_type) const override; + virtual ParseResult parse(std::shared_ptr rt_inst, std::shared_ptr head, ErrDeals& fx_type) const override; virtual QString token_present() const override; }; @@ -204,8 +208,7 @@ namespace lib_syntax { // IBasicRule interface public: virtual QList> children() const override; - virtual std::tuple> - parse(std::shared_ptr rt_inst, std::shared_ptr head, ErrOccurs &fx_type) const override; + virtual ParseResult parse(std::shared_ptr rt_inst, std::shared_ptr head, ErrDeals& fx_type) const override; virtual QString token_present() const override; protected: @@ -223,7 +226,7 @@ namespace lib_syntax { class ElementRule : public ExprRule { public: ElementRule(const QString& rule_name, int expr_mark) - :ExprRule(rule_name, expr_mark){} + :ExprRule(rule_name, expr_mark) {} virtual std::shared_ptr newEmptyInstance() const { return std::dynamic_pointer_cast( diff --git a/libSyntax/syntax_novel.cpp b/libSyntax/syntax_novel.cpp index 2748a4c..9d23167 100644 --- a/libSyntax/syntax_novel.cpp +++ b/libSyntax/syntax_novel.cpp @@ -12,6 +12,7 @@ auto leftb = std::make_shared(); // { auto rightb = std::make_shared(); // } auto refers = std::make_shared(); // @ auto declare = std::make_shared(); // # +auto split_mark = std::make_shared(); // & auto rank_key = std::make_shared(u8"排序", 0xAEu); // 排序 auto story_key = std::make_shared(u8"故事", 0xAAu); // 故事 @@ -19,9 +20,8 @@ auto numbers = std::make_shared(); // [0-9 auto frag_key = std::make_shared(u8"情节", 0xABu); // 情节 auto volume_key = std::make_shared(u8"分卷", 0xACu); // 分卷 auto article_key = std::make_shared(u8"章节", 0xADu); // 章节 -auto split_mark = std::make_shared(); // & -auto vtext = std::make_shared(); // ^([^\\{\\}\\n@&]+) -auto name_text = std::make_shared(); // ^([^:\\{\\}\\n@&][^\\{\\}\\n@&]*) +auto vtext = std::make_shared(); // ^([^\\{\\}@&]+) +auto name_text = std::make_shared(); // ^([^\\{\\}@&]+) @@ -38,21 +38,21 @@ auto name_text = std::make_shared(); // ^ -auto decl_comp = std::make_shared(Rules{ MR(numbers), MR(vtext), MR(name_text), MR(split_mark) }); +auto decl_comp = std::make_shared(Rules{ MR(refers), MR(vtext), MR(split_mark) }); auto decl_expr = ElementRule(u8"decl_section", (int)NovelExprs::DESC_SECTION).reloadRule( - MultiR(decl_comp)); + OptMulR(decl_comp)); auto fragment_decl = ElementRule(u8"fragment_define", (int)NovelExprs::FRAG_DEFINES).reloadRule( std::make_shared( Rules{ MR(leftb), MR(frag_key), MR(name_text) } << - OptMulR(decl_expr) << + decl_expr << MR(rightb) )); auto fragment_refer = ElementRule(u8"fragment_refer", (int)NovelExprs::FRAG_REFERS).reloadRule( std::make_shared( Rules{ MR(leftb), MR(refers), MR(frag_key), MR(name_text), MR(split_mark), MR(name_text) } << - OptMulR(decl_expr) << + decl_expr << MR(rightb) )); @@ -87,7 +87,7 @@ auto document_define = ElementRule(u8"decls-doc", (int)NovelExprs::DOC std::make_shared( Rules{ std::make_shared(rank_define, 0, 1), - MultiR(std::make_shared(Rules{story_define, volume_decl})) + OptMulR(std::make_shared(Rules{story_define, volume_decl})) } )); diff --git a/libToken/tokens_novel.cpp b/libToken/tokens_novel.cpp index 9a6999e..20c7a31 100644 --- a/libToken/tokens_novel.cpp +++ b/libToken/tokens_novel.cpp @@ -121,7 +121,7 @@ int VTextSection::typeMark() const return 0x09000000; } -QString VTextSection::regex() const { return u8"^([^\\{\\}\\n@&]+)"; } +QString VTextSection::regex() const { return u8"^([^\\{\\}@&]+)"; } std::tuple, std::shared_ptr> VTextSection::analysis(std::shared_ptr content) const { @@ -160,7 +160,7 @@ int NameSection::typeMark() const return 0x08000000; } -QString NameSection::regex() const { return u8"^([^:\\{\\}\\n@&][^\\{\\}\\n@&]*)"; } +QString NameSection::regex() const { return u8"^([^\\{\\}@&]+)"; } std::tuple, std::shared_ptr > NameSection::analysis(std::shared_ptr content) const {