diff --git a/libSyntax/syntax_novel.cpp b/libSyntax/syntax_novel.cpp index c7c7610..2b5ab01 100644 --- a/libSyntax/syntax_novel.cpp +++ b/libSyntax/syntax_novel.cpp @@ -27,16 +27,12 @@ auto name_text = std::make_shared(); // ^([^\ // rule-parts =============================================================================== -template -void apntk(std::shared_ptr expr, std::shared_ptr t) { - expr->addToken(t); -} - +#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, apntk, t) +#define MR(E, t) MER(E, lib_composit::apntk, t) // Buffer #define Rules QList> // Option @@ -47,175 +43,162 @@ void apntk(std::shared_ptr expr, std::shared_ptr // opt? #define OptR(rule) std::make_shared(rule, 0, 1) - - -class DeclExpr : public ElementRule { -public: - DeclExpr() : ElementRule( - "decl_section", - MultiR(std::make_shared(Rules{ - MR(TextSection, numbers), MR(TextSection, vtext), MR(TextSection, refers), MR(TextSection, split_mark) - }))) { } - - // 通过 ElementRule 继承 - QList> expr_rule_parse(std::shared_ptr cursor) const override { - return _children_store->parse(cursor); - } -}; - - +using namespace lib_composit; void point_nmset(std::shared_ptr inst, std::shared_ptr token) { inst->addToken(token); inst->setName(token->content()); } -class PointSyntax : public ElementRule { -public: - PointSyntax() : ElementRule( - "point_define", std::make_shared(Rules{ - MR(PointDefines, leftb), MR(PointDefines, point_key), MER(PointDefines, point_nmset, name_text) } << - OptR(MK(DeclExpr)) << - MR(PointDefines, rightb) - )) { } - - // 通过 ElementRule 继承 - QList> expr_rule_parse(std::shared_ptr cursor) const override { - return _children_store->parse(cursor); - } -}; - - - -void point_ref_story_set(std::shared_ptr inst, std::shared_ptr token) { +void ref_story_set(std::shared_ptr inst, std::shared_ptr token) { inst->addToken(token); inst->setStoryRefer(token->content()); } -void point_ref_slice_set(std::shared_ptr inst, std::shared_ptr token) { +void ref_slice_set(std::shared_ptr inst, std::shared_ptr token) { inst->addToken(token); inst->setSliceRefer(token->content()); } -void point_ref_point_set(std::shared_ptr inst, std::shared_ptr token) { +void ref_point_set(std::shared_ptr inst, std::shared_ptr token) { inst->addToken(token); inst->setPointRefer(token->content()); } -class ReferSyntax : public ElementRule { -public: - ReferSyntax() : ElementRule < PointRefers, (int) NovelNode::PointRefers>( - "point_refer", std::make_shared(Rules{ - MR(PointRefers, leftb), MR(PointRefers, refers), MR(PointRefers, point_key), - MER(PointRefers, point_ref_story_set, name_text), - MR(PointRefers, split_mark), - MER(PointRefers, point_ref_slice_set, name_text), - MR(PointRefers, split_mark), - MER(PointRefers, point_ref_point_set, name_text) } << - OptR(MK(DeclExpr)) << - MR(PointRefers, rightb))) { } - - // 通过 ElementRule 继承 - QList> expr_rule_parse(std::shared_ptr cursor) const override { - return _children_store->parse(cursor); - } -}; - - - void slice_nm_set(std::shared_ptr inst, std::shared_ptr token) { inst->addToken(token); inst->setName(token->content()); } -class SliceSyntax : public ElementRule { -public: - SliceSyntax() : ElementRule( - "slice_define", std::make_shared(Rules{ - MR(FragmentSlice, leftb), MR(FragmentSlice, slice_key), MER(FragmentSlice, slice_nm_set, name_text) } << - OptMulR(std::make_shared(Rules{ MK(PointSyntax), MK(ReferSyntax), MK(DeclExpr) })) << - MR(FragmentSlice, rightb))) { } - - // 通过 ElementRule 继承 - QList> expr_rule_parse(std::shared_ptr cursor) const override { - return _children_store->parse(cursor); - } -}; - - - void story_nmset(std::shared_ptr inst, std::shared_ptr token) { inst->addToken(token); inst->setName(token->content()); } -class StorySyntax : public ElementRule { -public: - StorySyntax() : ElementRule( - "story_define", - std::make_shared(Rules{ - MR(StoryDefine, leftb), MR(StoryDefine, story_key), MER(StoryDefine, story_nmset, name_text) } << - OptMulR(std::make_shared(Rules{ MK(SliceSyntax), MK(DeclExpr) })) << - MR(StoryDefine, rightb) - )) { } - - // 通过 ElementRule 继承 - QList> expr_rule_parse(std::shared_ptr cursor) const override { - return _children_store->parse(cursor); - } -}; - - - - void article_nset(std::shared_ptrinst, std::shared_ptr token) { inst->addToken(token); inst->setName(token->content()); } -class ArticleSyntax : public ElementRule { -public: - ArticleSyntax() : ElementRule( - "article_define", std::make_shared(Rules{ - MR(ArticleDefine, leftb), MR(ArticleDefine, article_key), MER(ArticleDefine, article_nset, name_text) } << - OptMulR(std::make_shared(Rules{ MK(ReferSyntax), MK(DeclExpr) })) << - MR(ArticleDefine, rightb) - )) { } - - // 通过 ElementRule 继承 - QList> expr_rule_parse(std::shared_ptr cursor) const override { - return _children_store->parse(cursor); - } -}; - - - - void volume_nset(std::shared_ptr inst, std::shared_ptr token) { inst->addToken(token); inst->setName(token->content()); } -class VolumeSyntax : public ElementRule { -public: - VolumeSyntax() : ElementRule( - "volume_define", std::make_shared(Rules{ - MR(VolumeDefine, leftb), MR(VolumeDefine, volume_key), MER(VolumeDefine, volume_nset, name_text) } << - OptMulR(std::make_shared(Rules{ MK(DeclExpr), MK(ArticleSyntax) })) << - MR(VolumeDefine, rightb) - )) { } - - // 通过 ElementRule 继承 - QList> expr_rule_parse(std::shared_ptr cursor) const override { - return _children_store->parse(cursor); - } -}; - - - - 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(Rules{ - MR(RankDeclare, declare), MR(RankDeclare, rank_key), MER(RankDeclare, rank_set, numbers) } - )) { } + "rank_define", std::make_shared()) { } // 通过 ElementRule 继承 QList> expr_rule_parse(std::shared_ptr cursor) const override { @@ -225,12 +208,11 @@ public: +using DocSyntaxDef = lib_composit::SeqsR, lib_composit::OptMulti>>; class DocumentSyntax : public ElementRule { public: DocumentSyntax() : ElementRule( - "decls-doc", std::make_shared(Rules{ - OptR(MK(RankSyntax)), MultiR(std::make_shared(Rules{ MK(StorySyntax), MK(VolumeSyntax) })) - })) { } + "decls-doc", std::make_shared()) { } // 通过 ElementRule 继承 QList> expr_rule_parse(std::shared_ptr cursor) const override { @@ -238,25 +220,8 @@ public: } }; -class MM : public lib_syntax::IBasicRule { - // 通过 IBasicRule 继承 - QList> children() const override { - return QList>(); - } - QString present() const override { - return QString(); - } - QList> parse(std::shared_ptr cursor) const override { - return QList>(); - } -}; -#include "syntax_templets.h" -std::shared_ptr NovalSyntax::getSyntaxTree() { - lib_composit::__types_list vv; - return std::make_shared(); -} //std::shared_ptr NovalSyntax::tidy(std::shared_ptr root, QList> children) //{ @@ -302,34 +267,9 @@ std::shared_ptr NovalSyntax::getSyntaxTree() { #include "syntax_templets.h" -/** - * class DeclExpr : public ElementRule { -public: - DeclExpr() : ElementRule( - "decl_section", - MultiR(std::make_shared(Rules{ - MR(TextSection, numbers), MR(TextSection, vtext), MR(TextSection, refers), MR(TextSection, split_mark) - }))) { } - - // 通过 ElementRule 继承 - QList> expr_rule_parse(std::shared_ptr cursor) const override { - return _children_store->parse(cursor); - } -}; - */ - -using namespace lib_composit; - -template class TokenRn : public TokenR { }; -template class MultiRx : public ReptR { }; void rules() { - MultiRx, - TokenRn, - TokenRn, - TokenRn - >> dcc; + AnyR, TokenRn, TokenRn, TokenRn> mmm; ReptR decl; diff --git a/libSyntax/syntax_templets.h b/libSyntax/syntax_templets.h index 81ab416..45f351c 100644 --- a/libSyntax/syntax_templets.h +++ b/libSyntax/syntax_templets.h @@ -14,7 +14,7 @@ namespace lib_composit { }; template - requires std::derived_from + requires std::derived_from class __types_list : public __types_list { public: static QList> getRules() { @@ -27,29 +27,37 @@ namespace lib_composit { template class AnyR : public lib_syntax::Any, public __types_list { public: - AnyR() : Any(__types_list::getRules()){ } + AnyR() : Any(__types_list::getRules()) { } }; template class SeqsR : public lib_syntax::Seqs, public __types_list { public: - SeqsR() : Seqs(__types_list::getRules()){ } + SeqsR() : Seqs(__types_list::getRules()) { } }; template requires std::derived_from class ReptR : public lib_syntax::Rept { public: - ReptR() : Rept(std::make_shared(), min, max){ } + ReptR() : Rept(std::make_shared(), min, max) { } }; - template class OptMulti : public ReptR{ }; - template class Multi : public ReptR{ }; - template class Opt : public ReptR{ }; + template class OptMulti : public ReptR { }; + template class Multi : public ReptR { }; + template class Opt : public ReptR { }; template p = nullptr> - requires std::derived_from && std::derived_from + requires std::derived_from&& std::derived_from class TokenR : public lib_syntax::TokenMatch { - public: - TokenR() : TokenMatch(std::make_shared()){ } + public: + TokenR() : TokenMatch(std::make_shared()) { } }; + + template requires std::derived_from + void apntk(std::shared_ptr expr, std::shared_ptr t) { + expr->addToken(t); + } + template + requires std::derived_from&& std::derived_from + class TokenRn : public TokenR { }; }