244 lines
8.5 KiB
C++
244 lines
8.5 KiB
C++
|
#include "ast_novel.h"
|
|||
|
|
|||
|
|
|||
|
using namespace example_novel;
|
|||
|
|
|||
|
TextSection::TextSection(const QString& text, const QString path, std::shared_ptr<const SyntaxElement> parent)
|
|||
|
: content_store(text), file_path(path), pnode_store(parent) {}
|
|||
|
|
|||
|
QString example_novel::TextSection::content() const
|
|||
|
{
|
|||
|
return this->content_store;
|
|||
|
}
|
|||
|
|
|||
|
int TextSection::typeMark() const { return (int)NovelNode::TextSection; }
|
|||
|
|
|||
|
bool example_novel::TextSection::isAnonymous() const
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
QString TextSection::path() const { return file_path; }
|
|||
|
|
|||
|
QString TextSection::signature() const { return u8"::section"; }
|
|||
|
|
|||
|
std::shared_ptr<const ast_gen::SyntaxElement> TextSection::parent() const { return pnode_store; }
|
|||
|
|
|||
|
QList<std::shared_ptr<const ast_gen::TokenAccess> > TextSection::selfTokens() const {
|
|||
|
return TokenSL::selfTokens();
|
|||
|
}
|
|||
|
|
|||
|
FragmentRefers::FragmentRefers(const QString& story, const QString& fragment, const QString& path, std::shared_ptr<const SyntaxElement> parent)
|
|||
|
: story_ref(story), fragm_ref(fragment), path_store(path), pnode_store(parent) {}
|
|||
|
|
|||
|
QString FragmentRefers::storyRefer() const { return story_ref; }
|
|||
|
|
|||
|
QString FragmentRefers::fragmentRefer() const { return fragm_ref; }
|
|||
|
|
|||
|
int FragmentRefers::typeMark() const { return (int)NovelNode::FragmentRefer; }
|
|||
|
|
|||
|
bool example_novel::FragmentRefers::isAnonymous() const
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
QString FragmentRefers::path() const { return path_store; }
|
|||
|
|
|||
|
QString FragmentRefers::signature() const {
|
|||
|
QString signature = u8"@" + storyRefer() + u8"&" + fragmentRefer();
|
|||
|
return parent()->signature() + signature;
|
|||
|
}
|
|||
|
|
|||
|
std::shared_ptr<const ast_gen::SyntaxElement> FragmentRefers::parent() const { return pnode_store; }
|
|||
|
|
|||
|
QList<std::shared_ptr<const ast_gen::TokenAccess> > FragmentRefers::selfTokens() const {
|
|||
|
return TokenSL::selfTokens();
|
|||
|
}
|
|||
|
|
|||
|
FragmentDefine::FragmentDefine(const QString& name, const QString& path, std::shared_ptr<const SyntaxElement> parent)
|
|||
|
: name_store(name), path_store(path), pnode_store(parent) {}
|
|||
|
|
|||
|
QString FragmentDefine::name() const { return name_store; }
|
|||
|
|
|||
|
int FragmentDefine::typeMark() const { return (int)NovelNode::FragmentDefine; }
|
|||
|
|
|||
|
bool example_novel::FragmentDefine::isAnonymous() const
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
QString FragmentDefine::path() const { return path_store; }
|
|||
|
|
|||
|
QString FragmentDefine::signature() const { return parent()->signature() + u8"&" + name(); }
|
|||
|
|
|||
|
std::shared_ptr<const ast_gen::SyntaxElement> FragmentDefine::parent() const { return pnode_store; }
|
|||
|
|
|||
|
QList<std::shared_ptr<const ast_gen::TokenAccess> > FragmentDefine::selfTokens() const {
|
|||
|
return TokenSL::selfTokens();
|
|||
|
}
|
|||
|
|
|||
|
StoryDefine::StoryDefine(const QString name, int sort, const QString path, std::shared_ptr<const SyntaxElement> parent)
|
|||
|
: name_store(name), sort_index(sort), path_store(path), pnode_store(parent) {}
|
|||
|
|
|||
|
QString StoryDefine::name() const { return name_store; }
|
|||
|
|
|||
|
int StoryDefine::sort() const { return sort_index; }
|
|||
|
|
|||
|
int StoryDefine::typeMark() const { return (int)NovelNode::StoryDefine; }
|
|||
|
|
|||
|
bool example_novel::StoryDefine::isAnonymous() const
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
QString StoryDefine::path() const { return path_store; }
|
|||
|
|
|||
|
QString StoryDefine::signature() const { return name_store; }
|
|||
|
|
|||
|
std::shared_ptr<const ast_gen::SyntaxElement> StoryDefine::parent() const { return pnode_store; }
|
|||
|
|
|||
|
QList<std::shared_ptr<const ast_gen::TokenAccess> > StoryDefine::selfTokens() const {
|
|||
|
return TokenSL::selfTokens();
|
|||
|
}
|
|||
|
|
|||
|
#include "syntax_novel.h"
|
|||
|
std::shared_ptr<const ast_gen::SyntaxElement> NovelExprsVisitor::visit(std::shared_ptr<const ast_basic::ExprNode> expr, std::shared_ptr<const ast_gen::SyntaxElement> pnode) const
|
|||
|
{
|
|||
|
auto tidy_tokens = [&](std::shared_ptr<const ast_basic::ExprNode> expr) {
|
|||
|
auto vtokens = expr->tokens();
|
|||
|
for (auto& cld : expr->exprNodes()) {
|
|||
|
auto remove_tokens = cld->tokens();
|
|||
|
for (auto& rit : remove_tokens)
|
|||
|
vtokens.removeAll(rit);
|
|||
|
}
|
|||
|
return vtokens;
|
|||
|
};
|
|||
|
|
|||
|
switch (expr->defined()->typeMark()) {
|
|||
|
case example_novel::NovelExprs::DOC_DEFINES:
|
|||
|
return std::make_shared<Document>(expr->filePath(), pnode);
|
|||
|
case example_novel::NovelExprs::STORY_DEFINES: {
|
|||
|
auto name = expr->tokens().at(3)->content();
|
|||
|
auto sort = expr->tokens().at(2)->content().toInt();
|
|||
|
|
|||
|
auto rinst = std::make_shared<StoryDefine>(name, sort, expr->filePath(), pnode);
|
|||
|
rinst->appendDefinedTokens(rinst, tidy_tokens(expr));
|
|||
|
return rinst;
|
|||
|
}
|
|||
|
case example_novel::NovelExprs::FRAG_DEFINES: {
|
|||
|
auto name = expr->tokens().at(2)->content();
|
|||
|
auto inst = std::make_shared<FragmentDefine>(name, expr->filePath(), pnode);
|
|||
|
inst->appendDefinedTokens(inst, tidy_tokens(expr));
|
|||
|
return inst;
|
|||
|
}
|
|||
|
case example_novel::NovelExprs::FRAG_REFERS: {
|
|||
|
auto fragm_ref = expr->tokens().at(3)->content();
|
|||
|
auto story_ref = expr->tokens().at(5)->content();
|
|||
|
auto inst = std::make_shared<FragmentRefers>(story_ref, fragm_ref, expr->filePath(), pnode);
|
|||
|
inst->appendDefinedTokens(inst, tidy_tokens(expr));
|
|||
|
return inst;
|
|||
|
}
|
|||
|
case example_novel::NovelExprs::DESC_SECTION:
|
|||
|
{
|
|||
|
QString content = u8"";
|
|||
|
for (auto& t : expr->tokens())
|
|||
|
content += t->content();
|
|||
|
auto inst = std::make_shared<TextSection>(content, expr->filePath(), pnode);
|
|||
|
inst->appendDefinedTokens(inst, tidy_tokens(expr));
|
|||
|
return inst;
|
|||
|
}
|
|||
|
case example_novel::NovelExprs::ARTICLE_DEFINE:
|
|||
|
{
|
|||
|
auto name = expr->tokens().at(2)->content();
|
|||
|
auto inst = std::make_shared<ArticleDefine>(name, expr->filePath(), pnode);
|
|||
|
inst->appendDefinedTokens(inst, tidy_tokens(expr));
|
|||
|
return inst;
|
|||
|
}
|
|||
|
case example_novel::NovelExprs::VOLUME_DEFINE:
|
|||
|
{
|
|||
|
auto name = expr->tokens().at(2)->content();
|
|||
|
auto inst = std::make_shared<VolumeDefine>(name, expr->filePath(), pnode);
|
|||
|
inst->appendDefinedTokens(inst, tidy_tokens(expr));
|
|||
|
return inst;
|
|||
|
}
|
|||
|
default:
|
|||
|
throw new lib_syntax::SyntaxException(u8"InternalError[0x0003]<5D><><EFBFBD><EFBFBD>ƥ<EFBFBD><C6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
Document::Document(const QString& path, std::shared_ptr<const SyntaxElement> pnode)
|
|||
|
: path_store(path), pnode_store(pnode) {}
|
|||
|
|
|||
|
int Document::typeMark() const { return (int)NovelNode::Document; }
|
|||
|
|
|||
|
bool example_novel::Document::isAnonymous() const
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
QString Document::path() const { return path_store; }
|
|||
|
|
|||
|
QString Document::signature() const { return QString(u8"::document<%1>").arg(path()); }
|
|||
|
|
|||
|
std::shared_ptr<const ast_gen::SyntaxElement> Document::parent() const { return pnode_store; }
|
|||
|
|
|||
|
QList<std::shared_ptr<const ast_gen::TokenAccess> > Document::selfTokens() const
|
|||
|
{
|
|||
|
return QList<std::shared_ptr<const ast_gen::TokenAccess>>();
|
|||
|
}
|
|||
|
|
|||
|
void TokenSL::appendDefinedTokens(std::shared_ptr<const ast_gen::SyntaxElement> elm, QList<std::shared_ptr<const lib_token::Token>> tokens) {
|
|||
|
QList<std::shared_ptr<const ast_gen::TokenAccess>> access;
|
|||
|
for (auto& t : tokens)
|
|||
|
this->tokens_store << std::make_shared<ast_gen::TokenAccess>(elm, t);
|
|||
|
}
|
|||
|
|
|||
|
QList<std::shared_ptr<const ast_gen::TokenAccess> > TokenSL::selfTokens() const {
|
|||
|
return tokens_store;
|
|||
|
}
|
|||
|
|
|||
|
VolumeDefine::VolumeDefine(const QString& name, const QString& path, std::shared_ptr<const SyntaxElement> parent)
|
|||
|
: name_store(name), path_store(path), pnode_store(parent) {}
|
|||
|
|
|||
|
QString VolumeDefine::name() const { return name_store; }
|
|||
|
|
|||
|
int VolumeDefine::typeMark() const { return (int)NovelNode::VolumeDefine; }
|
|||
|
|
|||
|
bool example_novel::VolumeDefine::isAnonymous() const
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
QString VolumeDefine::path() const { return path_store; }
|
|||
|
|
|||
|
QString VolumeDefine::signature() const { return name(); }
|
|||
|
|
|||
|
std::shared_ptr<const ast_gen::SyntaxElement> VolumeDefine::parent() const { return pnode_store; }
|
|||
|
|
|||
|
QList<std::shared_ptr<const ast_gen::TokenAccess> > VolumeDefine::selfTokens() const {
|
|||
|
return TokenSL::selfTokens();
|
|||
|
}
|
|||
|
|
|||
|
ArticleDefine::ArticleDefine(const QString& name, const QString& path, std::shared_ptr<const SyntaxElement> parent)
|
|||
|
: name_store(name), path_store(path), pnode_store(parent) {}
|
|||
|
|
|||
|
QString ArticleDefine::name() const { return name_store; }
|
|||
|
|
|||
|
int ArticleDefine::typeMark() const { return (int)NovelNode::ArticleDefine; }
|
|||
|
|
|||
|
bool example_novel::ArticleDefine::isAnonymous() const
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
QString ArticleDefine::path() const { return path_store; }
|
|||
|
|
|||
|
QString ArticleDefine::signature() const { return parent()->signature() + u8"&" + name(); }
|
|||
|
|
|||
|
std::shared_ptr<const ast_gen::SyntaxElement> ArticleDefine::parent() const { return pnode_store; }
|
|||
|
|
|||
|
QList<std::shared_ptr<const ast_gen::TokenAccess> > ArticleDefine::selfTokens() const {
|
|||
|
return TokenSL::selfTokens();
|
|||
|
}
|
|||
|
|