diff --git a/WsNovelParser/main.cpp b/WsNovelParser/main.cpp index 81e5929..e4b6ff4 100644 --- a/WsNovelParser/main.cpp +++ b/WsNovelParser/main.cpp @@ -119,6 +119,7 @@ int main(int argc, char* argv[]) { std::cout << "nsc(WsNovelStoryCompiler:故事线编译器)" << std::endl; std::cout << "版本:V1.0.0" << std::endl; std::cout << "nsc --path path-to-dir --dest path-to-output [--html]" << std::endl; + std::cout << "nsc --help" << std::endl; }break; } //return a.exec(); diff --git a/libSyntax/ast_novel.h b/libSyntax/ast_novel.h index 6e55bbb..baafad9 100644 --- a/libSyntax/ast_novel.h +++ b/libSyntax/ast_novel.h @@ -114,7 +114,7 @@ namespace example_novel virtual bool isAnonymous() const override; virtual QString signature() const override; virtual void cacheLoad() override; - + private: QString name_store; }; @@ -166,3 +166,76 @@ namespace example_novel void cacheLoad() override; }; } + +namespace lib_syntax { + template<> class ElementRule : public ExprRule { + public: + ElementRule(const QString& rule_name, int expr_mark) + :ExprRule(rule_name, expr_mark) {} + + // 通过 ExprRule 继承 + virtual std::shared_ptr newEmptyInstance() const { + return std::dynamic_pointer_cast( + std::make_shared(this->shared_from_this())); + } + + virtual std::shared_ptr makeCopy() const { + return std::make_shared>(name(), typeMark()); + } + + virtual std::tuple> + parse(std::shared_ptr rt_inst, std::shared_ptr head) 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); + auto tokens_decl = elm_ast->tokens(); + + switch (std::get<0>(rstg)) { + case IBasicRule::MatchResult::Fail: + case IBasicRule::MatchResult::Part: + rt_inst->popExprInst(); + rt_inst->popExprRule(); + break; + case IBasicRule::MatchResult::Success: { + if (!std::dynamic_pointer_cast(elm_ast)) { + auto start_pos = tokens_decl.first()->position(); + rt_inst->clearErrors(rt_inst->currentFile(), start_pos); + } + + rt_inst->popExprInst(); + rt_inst->popExprRule(); + while (tokens_decl.size()) { + auto text_paragraph = this->newEmptyInstance(); + int row_n = tokens_decl.first()->row(); + + for (int idx = 0; idx < tokens_decl.size(); ++idx) { + auto target_token = tokens_decl.at(idx); + if (target_token->row() == row_n) { + text_paragraph->addToken(target_token); + tokens_decl.removeAt(idx--); + } + } + + if (rt_inst->currentExprInst()) { + rt_inst->currentExprInst()->addChild(text_paragraph); + } + else { + rt_inst->appendDocInst(text_paragraph); + } + } + + }break; + default: + break; + } + + return rstg; + } + + + }; +} diff --git a/libSyntax/libsyntax.h b/libSyntax/libsyntax.h index 1517942..efff551 100644 --- a/libSyntax/libsyntax.h +++ b/libSyntax/libsyntax.h @@ -197,8 +197,10 @@ namespace lib_syntax { parse(std::shared_ptr rt_inst, std::shared_ptr head) const override; virtual QString token_present() const override; - private: + protected: std::shared_ptr child_store; + + private: QString name_store; int mark_store; };