WsParser_VS/libSyntax/ast_novel.cpp

190 lines
5.0 KiB
C++
Raw Normal View History

2024-03-17 07:58:28 +00:00
#include "ast_novel.h"
using namespace example_novel;
TextSection::TextSection(std::shared_ptr<const lib_syntax::ExpressionRule> rule_bind)
: AbstractImpl(rule_bind) {}
2024-03-17 07:58:28 +00:00
QString example_novel::TextSection::content() const
{
return context_store;
2024-03-17 07:58:28 +00:00
}
int TextSection::typeMark() const { return (int)NovelNode::TextSection; }
bool example_novel::TextSection::isAnonymous() const
{
return true;
2024-03-17 07:58:28 +00:00
}
QString TextSection::signature() const { return u8"::section"; }
void example_novel::TextSection::cacheLoad()
{
QString text;
for (auto& t : selfTokens()) {
text += t->token()->content() + " ";
}
context_store = text;
}
FragmentRefers::FragmentRefers(std::shared_ptr<const lib_syntax::ExpressionRule> rule_bind)
: AbstractImpl(rule_bind) {}
2024-03-17 07:58:28 +00:00
QString FragmentRefers::storyRefer() const { return story_refs; }
2024-03-17 07:58:28 +00:00
QString FragmentRefers::fragmentRefer() const { return fragment_ref; }
2024-03-17 07:58:28 +00:00
void example_novel::FragmentRefers::cacheLoad()
{
this->story_refs = selfTokens()[5]->token()->content();
this->fragment_ref = selfTokens()[3]->token()->content();
}
2024-03-31 05:59:17 +00:00
QString FragmentRefers::referSignature() const {
return storyRefer() + u8"&" + fragmentRefer();
2024-03-31 05:59:17 +00:00
}
2024-03-17 07:58:28 +00:00
int FragmentRefers::typeMark() const { return (int)NovelNode::FragmentRefer; }
bool example_novel::FragmentRefers::isAnonymous() const
{
return true;
2024-03-17 07:58:28 +00:00
}
QString FragmentRefers::signature() const {
QString signature = u8"@" + storyRefer() + u8"&" + fragmentRefer();
return parent()->signature() + signature;
2024-03-17 07:58:28 +00:00
}
FragmentDefine::FragmentDefine(std::shared_ptr<const lib_syntax::ExpressionRule> rule_bind)
: AbstractImpl(rule_bind) {}
2024-03-17 07:58:28 +00:00
QString FragmentDefine::name() const { return name_store; }
2024-03-17 07:58:28 +00:00
void example_novel::FragmentDefine::cacheLoad()
{
name_store = selfTokens()[2]->token()->content();
}
2024-03-17 07:58:28 +00:00
int FragmentDefine::typeMark() const { return (int)NovelNode::FragmentDefine; }
bool example_novel::FragmentDefine::isAnonymous() const
{
return false;
2024-03-17 07:58:28 +00:00
}
QString FragmentDefine::signature() const { return parent()->signature() + u8"&" + name(); }
StoryDefine::StoryDefine(std::shared_ptr<const lib_syntax::ExpressionRule> rule_bind)
: AbstractImpl(rule_bind) {}
2024-03-17 07:58:28 +00:00
QString StoryDefine::name() const { return name_store; }
2024-03-17 07:58:28 +00:00
int StoryDefine::sort() const { return sort_index; }
void example_novel::StoryDefine::cacheLoad()
{
name_store = selfTokens()[3]->token()->content();
sort_index = selfTokens()[2]->token()->content().toInt();
}
2024-03-17 07:58:28 +00:00
int StoryDefine::typeMark() const { return (int)NovelNode::StoryDefine; }
bool example_novel::StoryDefine::isAnonymous() const
{
return false;
2024-03-17 07:58:28 +00:00
}
QString StoryDefine::signature() const { return name(); }
2024-03-17 07:58:28 +00:00
#include "syntax_novel.h"
Document::Document(std::shared_ptr<const lib_syntax::ExpressionRule> rule_bind)
: AbstractImpl(rule_bind) {}
2024-03-17 07:58:28 +00:00
int Document::typeMark() const { return (int)NovelNode::Document; }
bool example_novel::Document::isAnonymous() const
{
return true;
2024-03-17 07:58:28 +00:00
}
QString Document::signature() const { return QString(u8"::document<%1>").arg(path()); }
void example_novel::Document::cacheLoad()
{
}
example_novel::AbstractImpl::AbstractImpl(std::shared_ptr<const lib_syntax::ExpressionRule> rule_bind)
2024-06-18 11:55:36 +00:00
: 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));
}
2024-03-17 07:58:28 +00:00
return values;
}
std::shared_ptr<const ast_gen::SyntaxElement> example_novel::AbstractImpl::parent() const
2024-03-17 07:58:28 +00:00
{
2024-06-18 11:55:36 +00:00
return this->parent_store.lock();
2024-03-17 07:58:28 +00:00
}
void example_novel::AbstractImpl::setParent(std::shared_ptr<const ast_gen::SyntaxElement> inst)
{
this->parent_store = inst;
2024-03-17 07:58:28 +00:00
}
// ͨ<><CDA8> SyntaxElement <20>̳<EFBFBD>
std::shared_ptr<const ast_basic::Expression> example_novel::AbstractImpl::bindExpression() const {
return shared_from_this();
}
QString example_novel::AbstractImpl::path() const
{
return ast_basic::ExpressionElement::filePath();
2024-03-17 07:58:28 +00:00
}
VolumeDefine::VolumeDefine(std::shared_ptr<const lib_syntax::ExpressionRule> rule_bind)
: AbstractImpl(rule_bind) {}
2024-03-17 07:58:28 +00:00
QString VolumeDefine::name() const { return name_store; }
void example_novel::VolumeDefine::cacheLoad()
{
name_store = selfTokens()[2]->token()->content();
}
2024-03-17 07:58:28 +00:00
int VolumeDefine::typeMark() const { return (int)NovelNode::VolumeDefine; }
bool example_novel::VolumeDefine::isAnonymous() const
{
return false;
2024-03-17 07:58:28 +00:00
}
QString VolumeDefine::signature() const { return name(); }
ArticleDefine::ArticleDefine(std::shared_ptr<const lib_syntax::ExpressionRule> rule_bind)
: AbstractImpl(rule_bind) {}
2024-03-17 07:58:28 +00:00
QString ArticleDefine::name() const { return name_store; }
void example_novel::ArticleDefine::cacheLoad()
{
name_store = selfTokens()[2]->token()->content();
}
2024-03-17 07:58:28 +00:00
int ArticleDefine::typeMark() const { return (int)NovelNode::ArticleDefine; }
bool example_novel::ArticleDefine::isAnonymous() const
{
return false;
2024-03-17 07:58:28 +00:00
}
QString ArticleDefine::signature() const { return parent()->signature() + u8"&" + name(); }