WsParser_VS/libSyntax/ast_novel.cpp

226 lines
5.1 KiB
C++
Raw Permalink Normal View History

2024-03-17 07:58:28 +00:00
#include "ast_novel.h"
2025-02-08 01:06:39 +00:00
#include <QtCore/QString>
2024-03-17 07:58:28 +00:00
using namespace example_novel;
using namespace lib_syntax;
2025-02-07 15:26:20 +00:00
using namespace ast_basic;
using namespace ast_gen;
2024-03-17 07:58:28 +00:00
TextSection::TextSection(std::shared_ptr<const ExprRule> rule_bind)
2025-02-07 15:26:20 +00:00
: AbstractImpl(rule_bind) { }
2024-03-17 07:58:28 +00:00
2025-02-07 15:26:20 +00:00
QString TextSection::content() const {
2024-07-28 08:37:31 +00:00
QString text;
for (auto& t : selfTokens()) {
text += t->token()->content() + " ";
}
return text;
2024-03-17 07:58:28 +00:00
}
2025-02-07 15:26:20 +00:00
QString TextSection::signature() const {
2025-02-17 05:59:25 +00:00
return parent().lock()->signature() + "&::section";
2024-03-17 07:58:28 +00:00
}
2025-03-29 09:53:28 +00:00
FragmentRefers::FragmentRefers(std::shared_ptr<const ExprRule> rule_bind)
2025-02-07 15:26:20 +00:00
: AbstractImpl(rule_bind) { }
2024-03-17 07:58:28 +00:00
2025-03-29 09:53:28 +00:00
QString FragmentRefers::storyRefer() const {
2025-02-07 15:26:20 +00:00
return story_refs;
}
2024-03-17 07:58:28 +00:00
2025-03-29 09:53:28 +00:00
void FragmentRefers::setStoryRefer(const QString& refer) {
2024-07-28 08:37:31 +00:00
this->story_refs = refer;
}
2025-03-29 09:53:28 +00:00
QString FragmentRefers::sliceRefer() const {
2025-02-15 15:47:42 +00:00
return slice_ref;
2025-02-07 15:26:20 +00:00
}
2024-03-17 07:58:28 +00:00
2025-03-29 09:53:28 +00:00
void FragmentRefers::setSliceRefer(const QString& refer) {
2025-02-15 15:47:42 +00:00
slice_ref = refer;
}
2024-07-28 08:37:31 +00:00
2025-03-29 09:53:28 +00:00
QString FragmentRefers::referSignature() const {
return storyRefer() + "&" + sliceRefer();
2024-03-31 05:59:17 +00:00
}
2025-03-29 09:53:28 +00:00
QString FragmentRefers::signature() const {
2025-02-11 14:32:10 +00:00
QString signature = "@" + referSignature();
return parent().lock()->signature() + "&" + signature;
2024-03-17 07:58:28 +00:00
}
StoryDefine::StoryDefine(std::shared_ptr<const ExprRule> rule_bind)
2025-02-07 15:26:20 +00:00
: AbstractImpl(rule_bind), sort_index(0) { }
2024-03-17 07:58:28 +00:00
2025-02-07 15:26:20 +00:00
QString StoryDefine::name() const {
return name_store;
}
2024-03-17 07:58:28 +00:00
2025-02-07 15:26:20 +00:00
void StoryDefine::setName(const QString& nm) {
2024-07-28 08:37:31 +00:00
this->name_store = nm;
}
2025-02-07 15:26:20 +00:00
void StoryDefine::setSort(int value) {
sort_index = value;
}
2025-02-07 15:26:20 +00:00
int StoryDefine::sort() const {
return sort_index;
2024-03-17 07:58:28 +00:00
}
2025-02-07 15:26:20 +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 ExprRule> rule_bind)
2025-02-07 15:26:20 +00:00
: AbstractImpl(rule_bind) { }
2024-03-17 07:58:28 +00:00
2025-02-07 15:26:20 +00:00
QString Document::signature() const {
2025-02-11 14:32:10 +00:00
return QString("::document<%1>").arg(path());
2024-07-28 08:37:31 +00:00
}
2025-02-07 15:26:20 +00:00
VolumeDefine::VolumeDefine(std::shared_ptr<const ExprRule> rule_bind)
: AbstractImpl(rule_bind) { }
2024-03-17 07:58:28 +00:00
2025-02-07 15:26:20 +00:00
QString VolumeDefine::name() const {
return name_store;
}
2025-02-07 15:26:20 +00:00
void VolumeDefine::setName(const QString& nm) {
this->name_store = nm;
2024-03-17 07:58:28 +00:00
}
2025-02-07 15:26:20 +00:00
QString VolumeDefine::signature() const {
return name();
2024-03-17 07:58:28 +00:00
}
2025-02-07 15:26:20 +00:00
ArticleDefine::ArticleDefine(std::shared_ptr<const ExprRule> rule_bind)
: AbstractImpl(rule_bind) { }
2025-02-07 15:26:20 +00:00
QString ArticleDefine::name() const {
return name_store;
2024-03-17 07:58:28 +00:00
}
2025-02-07 15:26:20 +00:00
void ArticleDefine::setName(const QString& nm) {
2024-07-28 08:37:31 +00:00
this->name_store = nm;
}
2024-03-17 07:58:28 +00:00
2025-02-07 15:26:20 +00:00
QString ArticleDefine::signature() const {
2025-02-11 14:32:10 +00:00
return parent().lock()->signature() + "&" + name();
2024-03-17 07:58:28 +00:00
}
2025-02-07 15:26:20 +00:00
RankDeclare::RankDeclare(std::shared_ptr<const ExprRule> rule)
: AbstractImpl(rule) { }
2024-03-17 07:58:28 +00:00
2025-02-07 15:26:20 +00:00
int RankDeclare::rankNumber() const {
return page_rank;
}
2025-02-07 15:26:20 +00:00
void RankDeclare::setRank(int nums) {
this->page_rank = nums;
}
2024-03-17 07:58:28 +00:00
2025-02-07 15:26:20 +00:00
QString RankDeclare::signature() const {
2025-02-11 14:32:10 +00:00
return "::rank";
2025-02-07 15:26:20 +00:00
}
2024-03-17 07:58:28 +00:00
2025-02-07 15:26:20 +00:00
FragmentSlice::FragmentSlice(std::shared_ptr<const ExprRule> rule)
:AbstractImpl(rule) {
2025-02-11 14:32:10 +00:00
_slice_name = QString("名称未定义_%1").arg((uint64_t)this);
2024-03-17 07:58:28 +00:00
}
2025-02-07 15:26:20 +00:00
QString FragmentSlice::name() const {
return _slice_name;
}
2025-02-07 15:26:20 +00:00
void FragmentSlice::setName(const QString& nm) {
this->_slice_name = nm;
}
2025-02-07 15:26:20 +00:00
QString FragmentSlice::signature() const {
2025-02-11 14:32:10 +00:00
return parent().lock()->signature() + "&" + name();
}
2025-02-07 15:26:20 +00:00
std::shared_ptr<const IExprInstance> NGlobalElement::bindExpression() const {
return shared_from_this();
2024-07-28 08:37:31 +00:00
}
2025-02-07 15:26:20 +00:00
int NGlobalElement::typeMark() const {
return (int)NovelNode::GlobalElement;
}
2025-02-07 15:26:20 +00:00
bool NGlobalElement::isAnonymous() const {
return true;
}
2025-02-07 15:26:20 +00:00
QString NGlobalElement::path() const {
return ExprProgram::filePath();
}
2025-02-04 14:26:34 +00:00
2025-02-07 15:26:20 +00:00
QString NGlobalElement::signature() const {
2025-02-11 14:32:10 +00:00
return "::program";
2025-02-04 14:26:34 +00:00
}
2025-03-01 13:15:15 +00:00
int example_novel::NGlobalElement::depth() const {
return 1;
}
2025-02-07 15:26:20 +00:00
std::weak_ptr<const SyntaxElement> NGlobalElement::parent() const {
return std::weak_ptr<const SyntaxElement>();
2025-02-04 14:26:34 +00:00
}
2025-02-07 15:26:20 +00:00
QList<std::shared_ptr<const TokenAccess>> NGlobalElement::selfTokens() const {
return QList<std::shared_ptr<const TokenAccess>>();
2025-02-04 14:26:34 +00:00
}
2025-02-07 15:26:20 +00:00
NGlobalElement::NGlobalElement(const QString& root): ExprProgram(root) { }
2025-02-08 01:06:39 +00:00
2025-02-15 15:47:42 +00:00
void example_novel::NGlobalElement::appendError(const QList<QString>& errors) {
_errors_store.append(errors);
}
QList<QString> example_novel::NGlobalElement::errors() const {
return _errors_store;
}
2025-02-08 01:06:39 +00:00
using namespace ast_gen;
using namespace ast_basic;
ElementAccess::ElementAccess(std::shared_ptr<const SyntaxElement> point) {
peers = point;
}
std::shared_ptr<const SyntaxElement> ElementAccess::element() const {
return peers;
}
QList<std::shared_ptr<const ElementAccess>> ElementAccess::children() const {
auto expression_inst = element()->bindExpression();
auto children = expression_inst->children();
QList<std::shared_ptr<const ElementAccess>> retvalues;
for (auto item : children) {
auto elem_inst = std::dynamic_pointer_cast<const SyntaxElement>(item);
retvalues.append(std::make_shared<ElementAccess>(elem_inst));
}
return retvalues;
}
QList<std::shared_ptr<const TokenAccess>> ElementAccess::tokens() const {
return element()->selfTokens();
}
TokenAccess::TokenAccess(std::shared_ptr<const SyntaxElement> elm_inst, std::shared_ptr<const lib_token::IToken> token_inst)
: element_bind(elm_inst), token_store(token_inst) { }
std::shared_ptr<const SyntaxElement> TokenAccess::bind() const {
return element_bind;
}
std::shared_ptr<const lib_token::IToken> TokenAccess::token() const {
return token_store;
}