update
This commit is contained in:
parent
ea2db22b37
commit
351c061479
|
@ -272,12 +272,12 @@ namespace lib_syntax {
|
||||||
/**
|
/**
|
||||||
* @brief 基础模板化语法元素解析规则.
|
* @brief 基础模板化语法元素解析规则.
|
||||||
*/
|
*/
|
||||||
template<class ExprType, int mark>
|
template<class ExprType, int mark, typename R>
|
||||||
requires std::derived_from<ExprType, ast_basic::IExprInstance>
|
requires std::derived_from<ExprType, ast_basic::IExprInstance>&& std::derived_from<R, lib_syntax::IBasicRule>
|
||||||
class ElementRule : public ExprRule {
|
class ElementRule : public ExprRule {
|
||||||
public:
|
public:
|
||||||
ElementRule(const QString& rule_name, std::shared_ptr<const IBasicRule> children)
|
ElementRule(const QString& rule_name)
|
||||||
:ExprRule(rule_name, mark), _children_store(children) { }
|
:ExprRule(rule_name, mark), _children_store(std::make_shared<R>()) { }
|
||||||
|
|
||||||
virtual QList<std::shared_ptr<const IBasicRule>> children() const {
|
virtual QList<std::shared_ptr<const IBasicRule>> children() const {
|
||||||
return QList<std::shared_ptr<const IBasicRule>>() << this->_children_store;
|
return QList<std::shared_ptr<const IBasicRule>>() << this->_children_store;
|
||||||
|
|
|
@ -6,43 +6,10 @@ using namespace lib_syntax;
|
||||||
using namespace example_novel;
|
using namespace example_novel;
|
||||||
using namespace lib_token;
|
using namespace lib_token;
|
||||||
using namespace ast_basic;
|
using namespace ast_basic;
|
||||||
|
using namespace std;
|
||||||
// token-avaliable ==========================================================================
|
|
||||||
auto leftb = std::make_shared<LBracket>(); // {
|
|
||||||
auto rightb = std::make_shared<RBracket>(); // }
|
|
||||||
auto refers = std::make_shared<ReferMk>(); // @
|
|
||||||
auto declare = std::make_shared<DeclareSymbo>(); // #
|
|
||||||
auto split_mark = std::make_shared<SplitMk>(); // &
|
|
||||||
|
|
||||||
auto rank_key = std::make_shared<RankWord>(); // 排序
|
|
||||||
auto story_key = std::make_shared<StoryWord>(); // 故事
|
|
||||||
auto numbers = std::make_shared<Numbers>(); // [0-9]+
|
|
||||||
auto slice_key = std::make_shared<SliceWord>(); // 剧情
|
|
||||||
auto point_key = std::make_shared<PointWord>(); // 节点
|
|
||||||
auto volume_key = std::make_shared<VolumeWord>(); // 分卷
|
|
||||||
auto article_key = std::make_shared<ArticleWord>(); // 章节
|
|
||||||
auto vtext = std::make_shared<NormalText>(); // ^([^\\{\\}@&]+)
|
|
||||||
auto name_text = std::make_shared<NameSection>(); // ^([^\\{\\}@&]+)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// rule-parts ===============================================================================
|
// rule-parts ===============================================================================
|
||||||
#include "syntax_templets.h"
|
#include "syntax_templets.h"
|
||||||
// MakeRule
|
|
||||||
#define MK(type) std::make_shared<const type>()
|
|
||||||
// MatchRule
|
|
||||||
#define MER(E, XProc, t) std::make_shared<const TokenMatch<E, XProc>>(t)
|
|
||||||
#define MR(E, t) MER(E, lib_composit::apntk<E>, t)
|
|
||||||
// Buffer
|
|
||||||
#define Rules QList<std::shared_ptr<const IBasicRule>>
|
|
||||||
// Option
|
|
||||||
#define OptMulT(token) std::make_shared<const Rept>(MR(token), 0, INT_MAX)
|
|
||||||
#define OptMulR(rule) std::make_shared<const Rept>(rule, 0, INT_MAX)
|
|
||||||
// multi+
|
|
||||||
#define MultiR(rule) std::make_shared<const Rept>(rule, 1, INT_MAX)
|
|
||||||
// opt?
|
|
||||||
#define OptR(rule) std::make_shared<const Rept>(rule, 0, 1)
|
|
||||||
|
|
||||||
using namespace lib_composit;
|
using namespace lib_composit;
|
||||||
|
|
||||||
void point_nmset(std::shared_ptr<PointDefines> inst, std::shared_ptr<const lib_token::IToken> token) {
|
void point_nmset(std::shared_ptr<PointDefines> inst, std::shared_ptr<const lib_token::IToken> token) {
|
||||||
|
@ -83,10 +50,9 @@ void rank_set(std::shared_ptr<RankDeclare> inst, std::shared_ptr<const lib_token
|
||||||
}
|
}
|
||||||
|
|
||||||
using TextDeclsSyntaxDef = lib_composit::Multi<AnyR<TokenRn<TextSection, Numbers>, TokenRn<TextSection, NormalText>, TokenRn<TextSection, ReferMk>, TokenRn<TextSection, SplitMk>>>;
|
using TextDeclsSyntaxDef = lib_composit::Multi<AnyR<TokenRn<TextSection, Numbers>, TokenRn<TextSection, NormalText>, TokenRn<TextSection, ReferMk>, TokenRn<TextSection, SplitMk>>>;
|
||||||
class DeclExpr : public ElementRule<TextSection, (int) NovelNode::TextSection> {
|
class DeclSyntax : public ElementRule<TextSection, (int) NovelNode::TextSection, TextDeclsSyntaxDef> {
|
||||||
public:
|
public:
|
||||||
DeclExpr() : ElementRule<TextSection, (int) NovelNode::TextSection>(
|
DeclSyntax() : ElementRule<TextSection, (int) NovelNode::TextSection, TextDeclsSyntaxDef>("decl_section") { }
|
||||||
"decl_section", std::make_shared<TextDeclsSyntaxDef>()) { }
|
|
||||||
|
|
||||||
// 通过 ElementRule 继承
|
// 通过 ElementRule 继承
|
||||||
QList<std::shared_ptr<const MatchCursor>> expr_rule_parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
QList<std::shared_ptr<const MatchCursor>> expr_rule_parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
||||||
|
@ -95,14 +61,13 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
using PointSyntaxDef = lib_composit::SeqsR<
|
|
||||||
TokenRn<PointDefines, LBracket>, TokenRn<PointDefines, PointWord>, TokenR<PointDefines, NameSection, point_nmset>,
|
using PointSyntaxDef = lib_composit::SeqsR<TokenRn<PointDefines, LBracket>, TokenRn<PointDefines, PointWord>, TokenR<PointDefines, NameSection, point_nmset>,
|
||||||
Opt<DeclExpr>,
|
Opt<DeclSyntax>,
|
||||||
TokenRn<PointDefines, RBracket>>;
|
TokenRn<PointDefines, RBracket>>;
|
||||||
class PointSyntax : public ElementRule<PointDefines, (int) NovelNode::PointDefines> {
|
class PointSyntax : public ElementRule<PointDefines, (int) NovelNode::PointDefines, PointSyntaxDef> {
|
||||||
public:
|
public:
|
||||||
PointSyntax() : ElementRule<PointDefines, (int) NovelNode::PointDefines>(
|
PointSyntax() : ElementRule<PointDefines, (int) NovelNode::PointDefines, PointSyntaxDef>("point_define") { }
|
||||||
"point_define", std::make_shared<PointSyntaxDef>()) { }
|
|
||||||
|
|
||||||
// 通过 ElementRule 继承
|
// 通过 ElementRule 继承
|
||||||
QList<std::shared_ptr<const MatchCursor>> expr_rule_parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
QList<std::shared_ptr<const MatchCursor>> expr_rule_parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
||||||
|
@ -111,14 +76,13 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
using ReferSyntaxDef = lib_composit::SeqsR<
|
|
||||||
TokenRn<PointRefers, LBracket>, TokenRn<PointRefers, ReferMk>, TokenRn<PointRefers, PointWord>, TokenR<PointRefers, NameSection, ref_story_set>, TokenRn<PointRefers, ReferMk>, TokenR<PointRefers, NameSection, ref_slice_set>, TokenRn<PointRefers, ReferMk>, TokenR<PointRefers, NameSection, ref_point_set>,
|
using ReferSyntaxDef = lib_composit::SeqsR<TokenRn<PointRefers, LBracket>, TokenRn<PointRefers, ReferMk>, TokenRn<PointRefers, PointWord>, TokenR<PointRefers, NameSection, ref_story_set>, TokenRn<PointRefers, ReferMk>, TokenR<PointRefers, NameSection, ref_slice_set>, TokenRn<PointRefers, ReferMk>, TokenR<PointRefers, NameSection, ref_point_set>,
|
||||||
Opt<DeclExpr>,
|
Opt<DeclSyntax>,
|
||||||
TokenRn<PointDefines, RBracket>>;
|
TokenRn<PointDefines, RBracket>>;
|
||||||
class ReferSyntax : public ElementRule<PointRefers, (int) NovelNode::PointRefers> {
|
class ReferSyntax : public ElementRule<PointRefers, (int) NovelNode::PointRefers, ReferSyntaxDef> {
|
||||||
public:
|
public:
|
||||||
ReferSyntax() : ElementRule < PointRefers, (int) NovelNode::PointRefers>(
|
ReferSyntax() : ElementRule < PointRefers, (int) NovelNode::PointRefers, ReferSyntaxDef>("point_refer") { }
|
||||||
"point_refer", std::make_shared<ReferSyntaxDef>()) { }
|
|
||||||
|
|
||||||
// 通过 ElementRule 继承
|
// 通过 ElementRule 继承
|
||||||
QList<std::shared_ptr<const MatchCursor>> expr_rule_parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
QList<std::shared_ptr<const MatchCursor>> expr_rule_parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
||||||
|
@ -127,14 +91,13 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
using SliceSyntaxDef = lib_composit::SeqsR<
|
|
||||||
TokenRn<FragmentSlice, LBracket>, TokenRn<FragmentSlice, SliceWord>, TokenR<FragmentSlice, NameSection, slice_nm_set>,
|
using SliceSyntaxDef = lib_composit::SeqsR<TokenRn<FragmentSlice, LBracket>, TokenRn<FragmentSlice, SliceWord>, TokenR<FragmentSlice, NameSection, slice_nm_set>,
|
||||||
lib_composit::OptMulti<AnyR<PointSyntax, ReferSyntax, DeclExpr>>,
|
lib_composit::OptMulti<AnyR<PointSyntax, ReferSyntax, DeclSyntax>>,
|
||||||
TokenRn<FragmentSlice, RBracket>>;
|
TokenRn<FragmentSlice, RBracket>>;
|
||||||
class SliceSyntax : public ElementRule<FragmentSlice, (int) NovelNode::FragmentSlice> {
|
class SliceSyntax : public ElementRule<FragmentSlice, (int) NovelNode::FragmentSlice, SliceSyntaxDef> {
|
||||||
public:
|
public:
|
||||||
SliceSyntax() : ElementRule<FragmentSlice, (int) NovelNode::FragmentSlice>(
|
SliceSyntax() : ElementRule<FragmentSlice, (int) NovelNode::FragmentSlice, SliceSyntaxDef>("slice_define") { }
|
||||||
"slice_define", std::make_shared<SliceSyntaxDef>()) { }
|
|
||||||
|
|
||||||
// 通过 ElementRule 继承
|
// 通过 ElementRule 继承
|
||||||
QList<std::shared_ptr<const MatchCursor>> expr_rule_parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
QList<std::shared_ptr<const MatchCursor>> expr_rule_parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
||||||
|
@ -143,14 +106,13 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
using StorySyntaxDef = lib_composit::SeqsR<
|
|
||||||
TokenRn<StoryDefine, LBracket>, TokenRn<StoryDefine, StoryWord>, TokenR<StoryDefine, NameSection, story_nmset>,
|
using StorySyntaxDef = lib_composit::SeqsR<TokenRn<StoryDefine, LBracket>, TokenRn<StoryDefine, StoryWord>, TokenR<StoryDefine, NameSection, story_nmset>,
|
||||||
lib_composit::OptMulti<AnyR<SliceSyntax, DeclExpr>>,
|
lib_composit::OptMulti<AnyR<SliceSyntax, DeclSyntax>>,
|
||||||
TokenRn<StoryDefine, RBracket>>;
|
TokenRn<StoryDefine, RBracket>>;
|
||||||
class StorySyntax : public ElementRule<StoryDefine, (int) NovelNode::StoryDefine> {
|
class StorySyntax : public ElementRule<StoryDefine, (int) NovelNode::StoryDefine, StorySyntaxDef> {
|
||||||
public:
|
public:
|
||||||
StorySyntax() : ElementRule<StoryDefine, (int) NovelNode::StoryDefine>(
|
StorySyntax() : ElementRule<StoryDefine, (int) NovelNode::StoryDefine, StorySyntaxDef>("story_define") { }
|
||||||
"story_define", std::make_shared<StorySyntaxDef>()) { }
|
|
||||||
|
|
||||||
// 通过 ElementRule 继承
|
// 通过 ElementRule 继承
|
||||||
QList<std::shared_ptr<const MatchCursor>> expr_rule_parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
QList<std::shared_ptr<const MatchCursor>> expr_rule_parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
||||||
|
@ -160,14 +122,12 @@ public:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
using ArticleSyntaxDef = lib_composit::SeqsR<
|
using ArticleSyntaxDef = lib_composit::SeqsR<TokenRn<ArticleDefine, LBracket>, TokenRn<ArticleDefine, ArticleWord>, TokenR<ArticleDefine, NameSection, article_nset>,
|
||||||
TokenRn<ArticleDefine, LBracket>, TokenRn<ArticleDefine, ArticleWord>, TokenR<ArticleDefine, NameSection, article_nset>,
|
lib_composit::OptMulti<AnyR<ReferSyntax, DeclSyntax>>,
|
||||||
lib_composit::OptMulti<AnyR<ReferSyntax, DeclExpr>>,
|
|
||||||
TokenRn<ArticleDefine, RBracket>>;
|
TokenRn<ArticleDefine, RBracket>>;
|
||||||
class ArticleSyntax : public ElementRule<ArticleDefine, (int) NovelNode::ArticleDefine> {
|
class ArticleSyntax : public ElementRule<ArticleDefine, (int) NovelNode::ArticleDefine, ArticleSyntaxDef> {
|
||||||
public:
|
public:
|
||||||
ArticleSyntax() : ElementRule<ArticleDefine, (int) NovelNode::ArticleDefine>(
|
ArticleSyntax() : ElementRule<ArticleDefine, (int) NovelNode::ArticleDefine, ArticleSyntaxDef>("article_define") { }
|
||||||
"article_define", std::make_shared<ArticleSyntaxDef>()) { }
|
|
||||||
|
|
||||||
// 通过 ElementRule 继承
|
// 通过 ElementRule 继承
|
||||||
QList<std::shared_ptr<const MatchCursor>> expr_rule_parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
QList<std::shared_ptr<const MatchCursor>> expr_rule_parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
||||||
|
@ -176,14 +136,13 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
using VolumeSyntaxDef = lib_composit::SeqsR<
|
|
||||||
TokenRn<VolumeDefine, LBracket>, TokenRn<VolumeDefine, VolumeWord>, TokenR<VolumeDefine, NameSection, volume_nset>,
|
using VolumeSyntaxDef = lib_composit::SeqsR<TokenRn<VolumeDefine, LBracket>, TokenRn<VolumeDefine, VolumeWord>, TokenR<VolumeDefine, NameSection, volume_nset>,
|
||||||
lib_composit::OptMulti<AnyR<ArticleSyntax, DeclExpr>>,
|
lib_composit::OptMulti<AnyR<ArticleSyntax, DeclSyntax>>,
|
||||||
TokenRn<VolumeDefine, RBracket>>;
|
TokenRn<VolumeDefine, RBracket>>;
|
||||||
class VolumeSyntax : public ElementRule<VolumeDefine, (int) NovelNode::VolumeDefine> {
|
class VolumeSyntax : public ElementRule<VolumeDefine, (int) NovelNode::VolumeDefine, VolumeSyntaxDef> {
|
||||||
public:
|
public:
|
||||||
VolumeSyntax() : ElementRule<VolumeDefine, (int) NovelNode::VolumeDefine>(
|
VolumeSyntax() : ElementRule<VolumeDefine, (int) NovelNode::VolumeDefine, VolumeSyntaxDef>("volume_define") { }
|
||||||
"volume_define", std::make_shared<VolumeSyntaxDef>()) { }
|
|
||||||
|
|
||||||
// 通过 ElementRule 继承
|
// 通过 ElementRule 继承
|
||||||
QList<std::shared_ptr<const MatchCursor>> expr_rule_parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
QList<std::shared_ptr<const MatchCursor>> expr_rule_parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
||||||
|
@ -193,12 +152,10 @@ public:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
using RankSyntaxDef = lib_composit::SeqsR<
|
using RankSyntaxDef = lib_composit::SeqsR<TokenRn<RankDeclare, DeclareSymbo>, TokenRn<RankDeclare, RankWord>, TokenR<RankDeclare, Numbers, rank_set>>;
|
||||||
TokenRn<RankDeclare, DeclareSymbo>, TokenRn<RankDeclare, RankWord>, TokenR<RankDeclare, Numbers, rank_set>>;
|
class RankSyntax : public ElementRule<RankDeclare, (int) NovelNode::RankDeclaration, RankSyntaxDef> {
|
||||||
class RankSyntax : public ElementRule<RankDeclare, (int) NovelNode::RankDeclaration> {
|
|
||||||
public:
|
public:
|
||||||
RankSyntax() : ElementRule<RankDeclare, (int) NovelNode::RankDeclaration>(
|
RankSyntax() : ElementRule<RankDeclare, (int) NovelNode::RankDeclaration, RankSyntaxDef>("rank_define") { }
|
||||||
"rank_define", std::make_shared<RankSyntaxDef>()) { }
|
|
||||||
|
|
||||||
// 通过 ElementRule 继承
|
// 通过 ElementRule 继承
|
||||||
QList<std::shared_ptr<const MatchCursor>> expr_rule_parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
QList<std::shared_ptr<const MatchCursor>> expr_rule_parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
||||||
|
@ -208,11 +165,10 @@ public:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
using DocSyntaxDef = lib_composit::SeqsR<Opt<RankSyntaxDef>, lib_composit::OptMulti<AnyR<StorySyntax, VolumeSyntax>>>;
|
using DocSyntaxDef = lib_composit::SeqsR<Opt<RankSyntax>, lib_composit::OptMulti<AnyR<StorySyntax, VolumeSyntax>>>;
|
||||||
class DocumentSyntax : public ElementRule<Document, (int) NovelNode::Document> {
|
class DocumentSyntax : public ElementRule<Document, (int) NovelNode::Document, DocSyntaxDef> {
|
||||||
public:
|
public:
|
||||||
DocumentSyntax() : ElementRule<Document, (int) NovelNode::Document>(
|
DocumentSyntax() : ElementRule<Document, (int) NovelNode::Document, DocSyntaxDef>("decls-doc") { }
|
||||||
"decls-doc", std::make_shared<DocSyntaxDef>()) { }
|
|
||||||
|
|
||||||
// 通过 ElementRule 继承
|
// 通过 ElementRule 继承
|
||||||
QList<std::shared_ptr<const MatchCursor>> expr_rule_parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
QList<std::shared_ptr<const MatchCursor>> expr_rule_parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
||||||
|
@ -262,15 +218,3 @@ public:
|
||||||
// node_register(child, next_child_items);
|
// node_register(child, next_child_items);
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "syntax_templets.h"
|
|
||||||
|
|
||||||
|
|
||||||
void rules() {
|
|
||||||
|
|
||||||
|
|
||||||
AnyR<TokenRn<TextSection, Numbers>, TokenRn<TextSection, NormalText>, TokenRn<TextSection, ReferMk>, TokenRn<TextSection, SplitMk>> mmm;
|
|
||||||
ReptR<decltype(mmm), 1, INT_MAX> decl;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue