From f58a034df276d0a58bff13ddde2ba19205832dec Mon Sep 17 00:00:00 2001 From: codeboss <2422523675@qq.com> Date: Fri, 19 Jul 2024 22:01:55 +0800 Subject: [PATCH] slash --- WsNovelParser/novelparser.cpp | 4 +++- libSyntax/ast_basic.cpp | 2 +- libSyntax/ast_basic.h | 2 +- libSyntax/ast_novel.h | 5 +++-- libSyntax/libsyntax.cpp | 17 +++++++++-------- libSyntax/libsyntax.h | 2 +- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/WsNovelParser/novelparser.cpp b/WsNovelParser/novelparser.cpp index f994df3..f3521c2 100644 --- a/WsNovelParser/novelparser.cpp +++ b/WsNovelParser/novelparser.cpp @@ -42,7 +42,9 @@ QList> NovelParser::parse(const QFil for (auto& file : source_list) { context->setCurrentFile(file.canonicalFilePath()); auto words = word_reader->wordsFrom(file.canonicalFilePath()); - this->syntax_defines->parse(context, words); + + lib_syntax::IBasicRule::ErrOccurs modify = lib_syntax::IBasicRule::ErrOccurs::None; + this->syntax_defines->parse(context, words, modify); } QList> forst_root = context->getDocInsts(); diff --git a/libSyntax/ast_basic.cpp b/libSyntax/ast_basic.cpp index 7865c2b..c5431d2 100644 --- a/libSyntax/ast_basic.cpp +++ b/libSyntax/ast_basic.cpp @@ -76,7 +76,7 @@ std::shared_ptr ExpressionContext::popExprRule() return rule_stack.takeLast(); } -void ExpressionContext::appendParseErrors(const QString& file_path, int start, const QString& e) { +void ExpressionContext::appendParseError(const QString& file_path, int start, const QString& e) { this->errors_storage.append(std::make_tuple(file_path, start, e)); } diff --git a/libSyntax/ast_basic.h b/libSyntax/ast_basic.h index 238eb76..ae90544 100644 --- a/libSyntax/ast_basic.h +++ b/libSyntax/ast_basic.h @@ -104,7 +104,7 @@ namespace ast_basic { virtual void appendDocInst(std::shared_ptr inst) override; virtual QList> getDocInsts() const override; - void appendParseErrors(const QString& file_path, int start, const QString& error_msg) override; + void appendParseError(const QString& file_path, int start, const QString& error_msg) override; QStringList errors() const override; void clearErrors(const QString& file_path, int start) override; }; diff --git a/libSyntax/ast_novel.h b/libSyntax/ast_novel.h index baafad9..fabcb84 100644 --- a/libSyntax/ast_novel.h +++ b/libSyntax/ast_novel.h @@ -184,14 +184,15 @@ namespace lib_syntax { } virtual std::tuple> - parse(std::shared_ptr rt_inst, std::shared_ptr head) const override { + parse(std::shared_ptr rt_inst, std::shared_ptr head, IBasicRule::ErrOccurs &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); - auto rstg = child_store->parse(rt_inst, head); + IBasicRule::ErrOccurs fixed = IBasicRule::ErrOccurs::None; + auto rstg = child_store->parse(rt_inst, head, fixed); auto tokens_decl = elm_ast->tokens(); switch (std::get<0>(rstg)) { diff --git a/libSyntax/libsyntax.cpp b/libSyntax/libsyntax.cpp index 27d2faf..e523e26 100644 --- a/libSyntax/libsyntax.cpp +++ b/libSyntax/libsyntax.cpp @@ -243,7 +243,8 @@ QList> ExprRule::children() const { 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 }; + IBasicRule::ErrOccurs::None, IBasicRule::ErrOccurs::Surplus, IBasicRule::ErrOccurs::Absence, IBasicRule::ErrOccurs::Replace + }; auto opt_current_itor = opts_list.cbegin(); tuple> ret_tuple; @@ -256,14 +257,7 @@ ExprRule::parse(shared_ptr rt_inst, shared_ptr head, rt_inst->pushExprInst(elm_ast); ret_tuple = child_store->parse(rt_inst, head, opt_val); - auto tokens_decl = elm_ast->tokens(); - switch (get<0>(ret_tuple)) { - case IBasicRule::MatchResult::Fail: - case IBasicRule::MatchResult::Part: - rt_inst->popExprInst(); - rt_inst->popExprRule(); - break; case IBasicRule::MatchResult::Success: { if (!dynamic_pointer_cast(elm_ast) && opt_val == IBasicRule::ErrOccurs::None) { auto start_pos = head->position(); @@ -279,6 +273,13 @@ ExprRule::parse(shared_ptr rt_inst, shared_ptr head, 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; diff --git a/libSyntax/libsyntax.h b/libSyntax/libsyntax.h index 1e6d4dd..1e67043 100644 --- a/libSyntax/libsyntax.h +++ b/libSyntax/libsyntax.h @@ -38,7 +38,7 @@ namespace lib_syntax { virtual void setCurrentFile(const QString &path) = 0; virtual QString currentFile() const = 0; - virtual void appendParseErrors(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;