222 lines
5.7 KiB
C++
222 lines
5.7 KiB
C++
#pragma once
|
|
|
|
#include "ast_gen.h"
|
|
|
|
namespace example_novel
|
|
{
|
|
enum class NovelNode {
|
|
GlobalElement = 0,
|
|
TextSection = 1,
|
|
FragmentRefer = 2,
|
|
FragmentDefine = 3,
|
|
StoryDefine = 4,
|
|
Document = 5,
|
|
ArticleDefine = 6,
|
|
VolumeDefine = 7,
|
|
RankDeclaration = 8,
|
|
};
|
|
|
|
class LIBSYNTAX_EXPORT AbstractImpl : public ast_basic::ExpressionElement, public ast_gen::SyntaxElement {
|
|
private:
|
|
std::weak_ptr<const SyntaxElement> parent_store;
|
|
|
|
public:
|
|
explicit AbstractImpl(std::shared_ptr<const lib_syntax::ExprRule> rule_bind);
|
|
|
|
// ͨ¹ý SyntaxElement ¼Ì³Ð
|
|
virtual std::shared_ptr<const ast_basic::IExprInst> bindExpression() const override;
|
|
QString path() const override;
|
|
virtual std::shared_ptr<const ast_gen::SyntaxElement> parent() const override;
|
|
virtual void setParent(std::shared_ptr<const ast_gen::SyntaxElement> inst) override;
|
|
virtual QList<std::shared_ptr<const ast_gen::TokenAccess>> selfTokens() const override;
|
|
};
|
|
|
|
|
|
class LIBSYNTAX_EXPORT TextSection : public AbstractImpl {
|
|
public:
|
|
TextSection(std::shared_ptr<const lib_syntax::ExprRule> rule_bind);
|
|
|
|
QString content() const;
|
|
|
|
// SyntaxElement interface
|
|
public:
|
|
virtual int typeMark() const override;
|
|
virtual bool isAnonymous() const override;
|
|
virtual QString signature() const override;
|
|
virtual void cacheLoad() override;
|
|
|
|
private:
|
|
QString context_store;
|
|
};
|
|
|
|
class LIBSYNTAX_EXPORT FragmentRefers : public AbstractImpl {
|
|
public:
|
|
FragmentRefers(std::shared_ptr<const lib_syntax::ExprRule> rule_bind);
|
|
|
|
QString storyRefer() const;
|
|
QString fragmentRefer() const;
|
|
QString referSignature() const;
|
|
|
|
// SyntaxElement interface
|
|
public:
|
|
virtual int typeMark() const override;
|
|
virtual bool isAnonymous() const override;
|
|
virtual QString signature() const override;
|
|
virtual void cacheLoad() override;
|
|
|
|
private:
|
|
QString story_refs, fragment_ref;
|
|
};
|
|
|
|
class LIBSYNTAX_EXPORT FragmentDefine : public AbstractImpl {
|
|
public:
|
|
FragmentDefine(std::shared_ptr<const lib_syntax::ExprRule> rule_bind);
|
|
|
|
QString name() const;
|
|
|
|
// SyntaxElement interface
|
|
public:
|
|
virtual int typeMark() const override;
|
|
virtual bool isAnonymous() const override;
|
|
virtual QString signature() const override;
|
|
virtual void cacheLoad() override;
|
|
|
|
private:
|
|
QString name_store;
|
|
};
|
|
|
|
class LIBSYNTAX_EXPORT ArticleDefine : public AbstractImpl {
|
|
public:
|
|
ArticleDefine(std::shared_ptr<const lib_syntax::ExprRule> rule_bind);
|
|
|
|
QString name() const;
|
|
|
|
// SyntaxElement interface
|
|
public:
|
|
virtual int typeMark() const override;
|
|
virtual bool isAnonymous() const override;
|
|
virtual QString signature() const override;
|
|
virtual void cacheLoad() override;
|
|
|
|
private:
|
|
QString name_store;
|
|
};
|
|
|
|
class LIBSYNTAX_EXPORT VolumeDefine : public AbstractImpl {
|
|
public:
|
|
VolumeDefine(std::shared_ptr<const lib_syntax::ExprRule> rule_bind);
|
|
|
|
QString name() const;
|
|
|
|
// SyntaxElement interface
|
|
public:
|
|
virtual int typeMark() const override;
|
|
virtual bool isAnonymous() const override;
|
|
virtual QString signature() const override;
|
|
virtual void cacheLoad() override;
|
|
|
|
private:
|
|
QString name_store;
|
|
};
|
|
|
|
class LIBSYNTAX_EXPORT StoryDefine : public AbstractImpl {
|
|
public:
|
|
StoryDefine(std::shared_ptr<const lib_syntax::ExprRule> rule_bind);
|
|
|
|
QString name() const;
|
|
void setSort(int value);
|
|
int sort() const;
|
|
|
|
// SyntaxElement interface
|
|
public:
|
|
virtual int typeMark() const override;
|
|
virtual bool isAnonymous() const override;
|
|
virtual QString signature() const override;
|
|
virtual void cacheLoad() override;
|
|
|
|
private:
|
|
QString name_store;
|
|
int sort_index;
|
|
};
|
|
|
|
class LIBSYNTAX_EXPORT Document : public AbstractImpl {
|
|
public:
|
|
Document(std::shared_ptr<const lib_syntax::ExprRule> rule_bind);
|
|
|
|
// SyntaxElement interface
|
|
public:
|
|
virtual int typeMark() const override;
|
|
virtual bool isAnonymous() const override;
|
|
virtual QString signature() const override;
|
|
virtual void cacheLoad() override;
|
|
};
|
|
|
|
class LIBSYNTAX_EXPORT RankDeclare : public AbstractImpl {
|
|
private:
|
|
int page_rank = 0;
|
|
public:
|
|
RankDeclare(std::shared_ptr<const lib_syntax::ExprRule> rule);
|
|
|
|
int rankNumber() const;
|
|
|
|
// ͨ¹ý AbstractImpl ¼Ì³Ð
|
|
int typeMark() const override;
|
|
bool isAnonymous() const override;
|
|
QString signature() const override;
|
|
void cacheLoad() override;
|
|
};
|
|
}
|
|
|
|
namespace lib_syntax {
|
|
template<> class ElementRule<example_novel::TextSection> : public lib_syntax::ExprRule {
|
|
public:
|
|
ElementRule<example_novel::TextSection>(const QString& rule_name, int expr_mark)
|
|
:ExprRule(rule_name, expr_mark) {}
|
|
|
|
// ͨ¹ý ExprRule ¼Ì³Ð
|
|
virtual std::shared_ptr<ast_basic::IExprInst> newEmptyInstance() const {
|
|
return std::dynamic_pointer_cast<ast_basic::IExprInst>(
|
|
std::make_shared<example_novel::TextSection>(this->shared_from_this()));
|
|
}
|
|
|
|
virtual std::shared_ptr<lib_syntax::ExprRule> makeCopy() const {
|
|
return std::make_shared<ElementRule<example_novel::TextSection>>(name(), typeMark());
|
|
}
|
|
|
|
virtual QList<ParseFork> parse(const ParseFork& context) const override {
|
|
auto text_present = this->token_present();
|
|
|
|
ParseFork estart;
|
|
estart.next = context.next;
|
|
auto result_fork = this->child_store->parse(estart);
|
|
for (auto rst : result_fork) {
|
|
switch (rst.occurs) {
|
|
case ErrDeals::None: {
|
|
auto tokens_decl = result_fork.first().tokens_list;
|
|
|
|
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--);
|
|
}
|
|
}
|
|
rst.mbrs_list << text_paragraph;
|
|
}
|
|
|
|
return QList<ParseFork>{ rst };
|
|
}break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
return result_fork;
|
|
}
|
|
};
|
|
}
|