224 lines
5.1 KiB
C++
224 lines
5.1 KiB
C++
#include "ast_novel.h"
|
||
|
||
|
||
using namespace example_novel;
|
||
using namespace lib_syntax;
|
||
|
||
TextSection::TextSection(std::shared_ptr<const ExpressionRule> rule_bind)
|
||
: AbstractImpl(rule_bind) {}
|
||
|
||
QString TextSection::content() const
|
||
{
|
||
return context_store;
|
||
}
|
||
|
||
int TextSection::typeMark() const { return (int)NovelNode::TextSection; }
|
||
|
||
bool TextSection::isAnonymous() const
|
||
{
|
||
return true;
|
||
}
|
||
|
||
QString TextSection::signature() const { return u8"::section"; }
|
||
|
||
void TextSection::cacheLoad()
|
||
{
|
||
QString text;
|
||
for (auto& t : selfTokens()) {
|
||
text += t->token()->content() + " ";
|
||
}
|
||
context_store = text;
|
||
}
|
||
|
||
FragmentRefers::FragmentRefers(std::shared_ptr<const ExpressionRule> rule_bind)
|
||
: AbstractImpl(rule_bind) {}
|
||
|
||
QString FragmentRefers::storyRefer() const { return story_refs; }
|
||
|
||
QString FragmentRefers::fragmentRefer() const { return fragment_ref; }
|
||
|
||
void FragmentRefers::cacheLoad()
|
||
{
|
||
this->story_refs = selfTokens()[5]->token()->content();
|
||
this->fragment_ref = selfTokens()[3]->token()->content();
|
||
}
|
||
QString FragmentRefers::referSignature() const {
|
||
return storyRefer() + u8"&" + fragmentRefer();
|
||
}
|
||
|
||
int FragmentRefers::typeMark() const { return (int)NovelNode::FragmentRefer; }
|
||
|
||
bool FragmentRefers::isAnonymous() const
|
||
{
|
||
return true;
|
||
}
|
||
|
||
QString FragmentRefers::signature() const {
|
||
QString signature = u8"@" + storyRefer() + u8"&" + fragmentRefer();
|
||
return parent()->signature() + signature;
|
||
}
|
||
|
||
|
||
FragmentDefine::FragmentDefine(std::shared_ptr<const ExpressionRule> rule_bind)
|
||
: AbstractImpl(rule_bind) {}
|
||
|
||
QString FragmentDefine::name() const { return name_store; }
|
||
|
||
void FragmentDefine::cacheLoad()
|
||
{
|
||
name_store = selfTokens()[2]->token()->content();
|
||
}
|
||
int FragmentDefine::typeMark() const { return (int)NovelNode::FragmentDefine; }
|
||
|
||
bool FragmentDefine::isAnonymous() const
|
||
{
|
||
return false;
|
||
}
|
||
|
||
QString FragmentDefine::signature() const { return parent()->signature() + u8"&" + name(); }
|
||
|
||
|
||
StoryDefine::StoryDefine(std::shared_ptr<const ExpressionRule> rule_bind)
|
||
: AbstractImpl(rule_bind), sort_index(0) {}
|
||
|
||
QString StoryDefine::name() const { return name_store; }
|
||
|
||
void example_novel::StoryDefine::setSort(int value){
|
||
sort_index = value;
|
||
}
|
||
|
||
int StoryDefine::sort() const { return sort_index; }
|
||
|
||
void StoryDefine::cacheLoad()
|
||
{
|
||
name_store = selfTokens()[2]->token()->content();
|
||
}
|
||
|
||
int StoryDefine::typeMark() const { return (int)NovelNode::StoryDefine; }
|
||
|
||
bool StoryDefine::isAnonymous() const
|
||
{
|
||
return false;
|
||
}
|
||
|
||
QString StoryDefine::signature() const { return name(); }
|
||
|
||
#include "syntax_novel.h"
|
||
Document::Document(std::shared_ptr<const ExpressionRule> rule_bind)
|
||
: AbstractImpl(rule_bind) {}
|
||
|
||
int Document::typeMark() const { return (int)NovelNode::Document; }
|
||
|
||
bool Document::isAnonymous() const
|
||
{
|
||
return true;
|
||
}
|
||
|
||
QString Document::signature() const { return QString(u8"::document<%1>").arg(path()); }
|
||
|
||
void Document::cacheLoad()
|
||
{
|
||
}
|
||
|
||
AbstractImpl::AbstractImpl(std::shared_ptr<const ExpressionRule> rule_bind)
|
||
: ExpressionElement(rule_bind) { parent_store.reset(); }
|
||
|
||
QList<std::shared_ptr<const ast_gen::TokenAccess> > AbstractImpl::selfTokens() const {
|
||
auto tokensx = ast_basic::ExpressionElement::tokens();
|
||
QList<std::shared_ptr<const ast_gen::TokenAccess>> values;
|
||
for (auto xit : tokensx) {
|
||
values.append(std::make_shared<ast_gen::TokenAccess>(std::dynamic_pointer_cast<const ast_gen::SyntaxElement>(shared_from_this()), xit));
|
||
}
|
||
|
||
return values;
|
||
}
|
||
|
||
std::shared_ptr<const ast_gen::SyntaxElement> AbstractImpl::parent() const
|
||
{
|
||
return this->parent_store.lock();
|
||
}
|
||
|
||
void AbstractImpl::setParent(std::shared_ptr<const ast_gen::SyntaxElement> inst)
|
||
{
|
||
this->parent_store = inst;
|
||
}
|
||
|
||
|
||
// ͨ<><CDA8> SyntaxElement <20>̳<EFBFBD>
|
||
std::shared_ptr<const ast_basic::Expression> AbstractImpl::bindExpression() const {
|
||
return shared_from_this();
|
||
}
|
||
|
||
QString AbstractImpl::path() const
|
||
{
|
||
return ast_basic::ExpressionElement::filePath();
|
||
}
|
||
|
||
VolumeDefine::VolumeDefine(std::shared_ptr<const ExpressionRule> rule_bind)
|
||
: AbstractImpl(rule_bind) {}
|
||
|
||
QString VolumeDefine::name() const { return name_store; }
|
||
|
||
void VolumeDefine::cacheLoad()
|
||
{
|
||
name_store = selfTokens()[2]->token()->content();
|
||
}
|
||
|
||
int VolumeDefine::typeMark() const { return (int)NovelNode::VolumeDefine; }
|
||
|
||
bool VolumeDefine::isAnonymous() const
|
||
{
|
||
return false;
|
||
}
|
||
|
||
QString VolumeDefine::signature() const { return name(); }
|
||
|
||
ArticleDefine::ArticleDefine(std::shared_ptr<const ExpressionRule> rule_bind)
|
||
: AbstractImpl(rule_bind) {}
|
||
|
||
QString ArticleDefine::name() const { return name_store; }
|
||
|
||
void ArticleDefine::cacheLoad()
|
||
{
|
||
name_store = selfTokens()[2]->token()->content();
|
||
}
|
||
|
||
int ArticleDefine::typeMark() const { return (int)NovelNode::ArticleDefine; }
|
||
|
||
bool ArticleDefine::isAnonymous() const
|
||
{
|
||
return false;
|
||
}
|
||
|
||
QString ArticleDefine::signature() const { return parent()->signature() + u8"&" + name(); }
|
||
|
||
RankDeclare::RankDeclare(std::shared_ptr<const ExpressionRule> rule)
|
||
: AbstractImpl(rule)
|
||
{
|
||
}
|
||
|
||
int example_novel::RankDeclare::rankNumber() const
|
||
{
|
||
return page_rank;
|
||
}
|
||
|
||
int RankDeclare::typeMark() const
|
||
{
|
||
return (int)NovelNode::RankDeclaration;
|
||
}
|
||
|
||
bool RankDeclare::isAnonymous() const
|
||
{
|
||
return true;
|
||
}
|
||
|
||
QString RankDeclare::signature() const
|
||
{
|
||
return u8"::rank";
|
||
}
|
||
|
||
void RankDeclare::cacheLoad()
|
||
{
|
||
page_rank = selfTokens()[2]->token()->content().toInt();
|
||
}
|