#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; using namespace std; // rule-parts =============================================================================== #include "syntax_templets.h" using namespace lib_composit; void point_nm_set(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_nm_set(std::shared_ptr inst, std::shared_ptr token) { inst->addToken(token); inst->setName(token->content()); } void article_nm_set(std::shared_ptrinst, std::shared_ptr token) { inst->addToken(token); inst->setName(token->content()); } void volume_nm_set(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()); } auto content_extract = [](std::shared_ptr token) { QString content; while (token) { if (token->defines()) content.prepend(token->content() + " "); token = token->prevToken(); } return content; }; using TextDeclsSyntaxDef = Any, Match, Match, Match>; class DeclSyntax : public ElementRule { public: DeclSyntax() : ElementRule("decl_section") { } // 通过 ElementRule 继承 QList> expr_rule_parse(std::shared_ptr cursor) const override { auto syntax_text = this->present(); auto current_rst = content_extract(cursor->currentToken()); auto rst = _children_store->parse(cursor); return rst; } }; using PointSyntaxDef = lib_composit::Seqs, Match, Action, OptMulti, Match>; class PointSyntax : public ElementRule { public: PointSyntax() : ElementRule("point_define") { } // 通过 ElementRule 继承 QList> expr_rule_parse(std::shared_ptr cursor) const override { return _children_store->parse(cursor); } }; using ReferSyntaxDef = lib_composit::Seqs, Match, Match, Action, Match, Action, Match, Action, OptMulti, Match>; class ReferSyntax : public ElementRule { public: ReferSyntax() : ElementRule < PointRefers, (int) NovelNode::PointRefers, ReferSyntaxDef>("point_refer") { } // 通过 ElementRule 继承 QList> expr_rule_parse(std::shared_ptr cursor) const override { return _children_store->parse(cursor); } }; using SliceSyntaxDef = lib_composit::Seqs, Match, Action, lib_composit::OptMulti>, Match>; class SliceSyntax : public ElementRule { public: SliceSyntax() : ElementRule("slice_define") { } // 通过 ElementRule 继承 QList> expr_rule_parse(std::shared_ptr cursor) const override { return _children_store->parse(cursor); } }; using StorySyntaxDef = lib_composit::Seqs, Match, Action, lib_composit::OptMulti>, Match>; class StorySyntax : public ElementRule { public: StorySyntax() : ElementRule("story_define") { } // 通过 ElementRule 继承 QList> expr_rule_parse(std::shared_ptr cursor) const override { return _children_store->parse(cursor); } }; using ArticleSyntaxDef = lib_composit::Seqs, Match, Action, lib_composit::OptMulti>, Match>; class ArticleSyntax : public ElementRule { public: ArticleSyntax() : ElementRule("article_define") { } // 通过 ElementRule 继承 QList> expr_rule_parse(std::shared_ptr cursor) const override { return _children_store->parse(cursor); } }; using VolumeSyntaxDef = lib_composit::Seqs, Match, Action, lib_composit::OptMulti>, Match>; class VolumeSyntax : public ElementRule { public: VolumeSyntax() : ElementRule("volume_define") { } // 通过 ElementRule 继承 QList> expr_rule_parse(std::shared_ptr cursor) const override { return _children_store->parse(cursor); } }; using RankSyntaxDef = lib_composit::Seqs, Match, Action>; class RankSyntax : public ElementRule { public: RankSyntax() : ElementRule("rank_define") { } // 通过 ElementRule 继承 QList> expr_rule_parse(std::shared_ptr cursor) const override { return _children_store->parse(cursor); } }; using DocSyntaxDef = lib_composit::Seqs, lib_composit::OptMulti>>; class DocumentSyntax : public ElementRule { public: DocumentSyntax() : ElementRule("decls-doc") { } // 通过 ElementRule 继承 QList> expr_rule_parse(std::shared_ptr cursor) const override { auto text = _children_store->present(); return _children_store->parse(cursor); } }; std::shared_ptr example_novel::NovalSyntax::getSyntaxTree() { return std::make_shared(); } //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); // } //}