#include "syntax_novel.h" #include #include "ast_novel.h" using namespace lib_syntax; using namespace example_novel; using namespace lib_token; using namespace ast_basic; // token-avaliable ========================================================================== 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(); // 排序 auto story_key = std::make_shared(); // 故事 auto numbers = std::make_shared(); // [0-9]+ auto slice_key = std::make_shared(); // 剧情 auto point_key = std::make_shared(); // 节点 auto volume_key = std::make_shared(); // 分卷 auto article_key = std::make_shared(); // 章节 auto vtext = std::make_shared(); // ^([^\\{\\}@&]+) auto name_text = std::make_shared(); // ^([^\\{\\}@&]+) // rule-parts =============================================================================== #include "syntax_templets.h" // MakeRule #define MK(type) std::make_shared() // MatchRule #define MER(E, XProc, t) std::make_shared>(t) #define MR(E, t) MER(E, lib_composit::apntk, t) // Buffer #define Rules QList> // Option #define OptMulT(token) std::make_shared(MR(token), 0, INT_MAX) #define OptMulR(rule) std::make_shared(rule, 0, INT_MAX) // multi+ #define MultiR(rule) std::make_shared(rule, 1, INT_MAX) // opt? #define OptR(rule) std::make_shared(rule, 0, 1) using namespace lib_composit; void point_nmset(std::shared_ptr inst, std::shared_ptr token) { inst->addToken(token); inst->setName(token->content()); } void ref_story_set(std::shared_ptr inst, std::shared_ptr token) { inst->addToken(token); inst->setStoryRefer(token->content()); } void ref_slice_set(std::shared_ptr inst, std::shared_ptr token) { inst->addToken(token); inst->setSliceRefer(token->content()); } void ref_point_set(std::shared_ptr inst, std::shared_ptr token) { inst->addToken(token); inst->setPointRefer(token->content()); } void slice_nm_set(std::shared_ptr inst, std::shared_ptr token) { inst->addToken(token); inst->setName(token->content()); } void story_nmset(std::shared_ptr inst, std::shared_ptr token) { inst->addToken(token); inst->setName(token->content()); } void article_nset(std::shared_ptrinst, std::shared_ptr token) { inst->addToken(token); inst->setName(token->content()); } void volume_nset(std::shared_ptr inst, std::shared_ptr token) { inst->addToken(token); inst->setName(token->content()); } void rank_set(std::shared_ptr inst, std::shared_ptr token) { inst->addToken(token); inst->setRank(token->content().toInt()); } using TextDeclsSyntaxDef = lib_composit::Multi, TokenRn, TokenRn, TokenRn>>; class DeclExpr : public ElementRule { public: DeclExpr() : ElementRule( "decl_section", std::make_shared()) { } // 通过 ElementRule 继承 QList> expr_rule_parse(std::shared_ptr cursor) const override { return _children_store->parse(cursor); } }; using PointSyntaxDef = lib_composit::SeqsR< TokenRn, TokenRn, TokenR, Opt, TokenRn>; class PointSyntax : public ElementRule { public: PointSyntax() : ElementRule( "point_define", std::make_shared()) { } // 通过 ElementRule 继承 QList> expr_rule_parse(std::shared_ptr cursor) const override { return _children_store->parse(cursor); } }; using ReferSyntaxDef = lib_composit::SeqsR< TokenRn, TokenRn, TokenRn, TokenR, TokenRn, TokenR, TokenRn, TokenR, Opt, TokenRn>; class ReferSyntax : public ElementRule { public: ReferSyntax() : ElementRule < PointRefers, (int) NovelNode::PointRefers>( "point_refer", std::make_shared()) { } // 通过 ElementRule 继承 QList> expr_rule_parse(std::shared_ptr cursor) const override { return _children_store->parse(cursor); } }; using SliceSyntaxDef = lib_composit::SeqsR< TokenRn, TokenRn, TokenR, lib_composit::OptMulti>, TokenRn>; class SliceSyntax : public ElementRule { public: SliceSyntax() : ElementRule( "slice_define", std::make_shared()) { } // 通过 ElementRule 继承 QList> expr_rule_parse(std::shared_ptr cursor) const override { return _children_store->parse(cursor); } }; using StorySyntaxDef = lib_composit::SeqsR< TokenRn, TokenRn, TokenR, lib_composit::OptMulti>, TokenRn>; class StorySyntax : public ElementRule { public: StorySyntax() : ElementRule( "story_define", std::make_shared()) { } // 通过 ElementRule 继承 QList> expr_rule_parse(std::shared_ptr cursor) const override { return _children_store->parse(cursor); } }; using ArticleSyntaxDef = lib_composit::SeqsR< TokenRn, TokenRn, TokenR, lib_composit::OptMulti>, TokenRn>; class ArticleSyntax : public ElementRule { public: ArticleSyntax() : ElementRule( "article_define", std::make_shared()) { } // 通过 ElementRule 继承 QList> expr_rule_parse(std::shared_ptr cursor) const override { return _children_store->parse(cursor); } }; using VolumeSyntaxDef = lib_composit::SeqsR< TokenRn, TokenRn, TokenR, lib_composit::OptMulti>, TokenRn>; class VolumeSyntax : public ElementRule { public: VolumeSyntax() : ElementRule( "volume_define", std::make_shared()) { } // 通过 ElementRule 继承 QList> expr_rule_parse(std::shared_ptr cursor) const override { return _children_store->parse(cursor); } }; using RankSyntaxDef = lib_composit::SeqsR< TokenRn, TokenRn, TokenR>; class RankSyntax : public ElementRule { public: RankSyntax() : ElementRule( "rank_define", std::make_shared()) { } // 通过 ElementRule 继承 QList> expr_rule_parse(std::shared_ptr cursor) const override { return _children_store->parse(cursor); } }; using DocSyntaxDef = lib_composit::SeqsR, lib_composit::OptMulti>>; class DocumentSyntax : public ElementRule { public: DocumentSyntax() : ElementRule( "decls-doc", std::make_shared()) { } // 通过 ElementRule 继承 QList> expr_rule_parse(std::shared_ptr cursor) const override { return _children_store->parse(cursor); } }; //std::shared_ptr NovalSyntax::tidy(std::shared_ptr root, QList> children) //{ // build_objecttree(root, children); // node_register(root, children); // return root; //} //void NovalSyntax::build_objecttree(std::shared_ptr root, QList> children) //{ // for (auto& cinst : children) { // cinst->setParent(root); // // QList> child_items; // for (auto& it : cinst->bindExpression()->children()) { // auto const_it = std::dynamic_pointer_cast(it); // child_items.append(std::const_pointer_cast(const_it)); // } // // build_objecttree(cinst, child_items); // } //} //void NovalSyntax::node_register(std::shared_ptr root, QList> children) //{ // for (auto& child : children) { // if (!child->isAnonymous()) { // auto check_result = ast_gen::GlobalElement::UniquePtr->appendToCache(child); // if (check_result) // throw new SyntaxException(QString("SyntaxError[0x0004]系统中包含同类型重名命名节点:%1(%3,%4)") // .arg(child->signature()).arg(child->typeMark()).arg(child->path()).arg(check_result->path())); // } // // QList> next_child_items; // for (auto& it : child->bindExpression()->children()) { // auto const_it = std::dynamic_pointer_cast(it); // next_child_items.append(std::const_pointer_cast(const_it)); // } // // node_register(child, next_child_items); // } //} #include "syntax_templets.h" void rules() { AnyR, TokenRn, TokenRn, TokenRn> mmm; ReptR decl; }