226 lines
5.1 KiB
C++
226 lines
5.1 KiB
C++
#include "ast_novel.h"
|
|
#include <QtCore/QString>
|
|
|
|
using namespace example_novel;
|
|
using namespace lib_syntax;
|
|
using namespace ast_basic;
|
|
using namespace ast_gen;
|
|
|
|
|
|
TextSection::TextSection(std::shared_ptr<const ExprRule> rule_bind)
|
|
: AbstractImpl(rule_bind) { }
|
|
|
|
QString TextSection::content() const {
|
|
QString text;
|
|
for (auto& t : selfTokens()) {
|
|
text += t->token()->content() + " ";
|
|
}
|
|
return text;
|
|
}
|
|
|
|
QString TextSection::signature() const {
|
|
return parent().lock()->signature() + "&::section";
|
|
}
|
|
|
|
FragmentRefers::FragmentRefers(std::shared_ptr<const ExprRule> rule_bind)
|
|
: AbstractImpl(rule_bind) { }
|
|
|
|
QString FragmentRefers::storyRefer() const {
|
|
return story_refs;
|
|
}
|
|
|
|
void FragmentRefers::setStoryRefer(const QString& refer) {
|
|
this->story_refs = refer;
|
|
}
|
|
|
|
QString FragmentRefers::sliceRefer() const {
|
|
return slice_ref;
|
|
}
|
|
|
|
void FragmentRefers::setSliceRefer(const QString& refer) {
|
|
slice_ref = refer;
|
|
}
|
|
|
|
QString FragmentRefers::referSignature() const {
|
|
return storyRefer() + "&" + sliceRefer();
|
|
}
|
|
|
|
QString FragmentRefers::signature() const {
|
|
QString signature = "@" + referSignature();
|
|
return parent().lock()->signature() + "&" + signature;
|
|
}
|
|
|
|
StoryDefine::StoryDefine(std::shared_ptr<const ExprRule> rule_bind)
|
|
: AbstractImpl(rule_bind), sort_index(0) { }
|
|
|
|
QString StoryDefine::name() const {
|
|
return name_store;
|
|
}
|
|
|
|
void StoryDefine::setName(const QString& nm) {
|
|
this->name_store = nm;
|
|
}
|
|
|
|
void StoryDefine::setSort(int value) {
|
|
sort_index = value;
|
|
}
|
|
|
|
int StoryDefine::sort() const {
|
|
return sort_index;
|
|
}
|
|
|
|
QString StoryDefine::signature() const {
|
|
return name();
|
|
}
|
|
|
|
#include "syntax_novel.h"
|
|
Document::Document(std::shared_ptr<const ExprRule> rule_bind)
|
|
: AbstractImpl(rule_bind) { }
|
|
|
|
QString Document::signature() const {
|
|
return QString("::document<%1>").arg(path());
|
|
}
|
|
|
|
VolumeDefine::VolumeDefine(std::shared_ptr<const ExprRule> rule_bind)
|
|
: AbstractImpl(rule_bind) { }
|
|
|
|
QString VolumeDefine::name() const {
|
|
return name_store;
|
|
}
|
|
|
|
void VolumeDefine::setName(const QString& nm) {
|
|
this->name_store = nm;
|
|
}
|
|
|
|
QString VolumeDefine::signature() const {
|
|
return name();
|
|
}
|
|
|
|
ArticleDefine::ArticleDefine(std::shared_ptr<const ExprRule> rule_bind)
|
|
: AbstractImpl(rule_bind) { }
|
|
|
|
QString ArticleDefine::name() const {
|
|
return name_store;
|
|
}
|
|
|
|
void ArticleDefine::setName(const QString& nm) {
|
|
this->name_store = nm;
|
|
}
|
|
|
|
QString ArticleDefine::signature() const {
|
|
return parent().lock()->signature() + "&" + name();
|
|
}
|
|
|
|
RankDeclare::RankDeclare(std::shared_ptr<const ExprRule> rule)
|
|
: AbstractImpl(rule) { }
|
|
|
|
int RankDeclare::rankNumber() const {
|
|
return page_rank;
|
|
}
|
|
|
|
void RankDeclare::setRank(int nums) {
|
|
this->page_rank = nums;
|
|
}
|
|
|
|
QString RankDeclare::signature() const {
|
|
return "::rank";
|
|
}
|
|
|
|
FragmentSlice::FragmentSlice(std::shared_ptr<const ExprRule> rule)
|
|
:AbstractImpl(rule) {
|
|
_slice_name = QString("名称未定义_%1").arg((uint64_t)this);
|
|
}
|
|
|
|
QString FragmentSlice::name() const {
|
|
return _slice_name;
|
|
}
|
|
|
|
void FragmentSlice::setName(const QString& nm) {
|
|
this->_slice_name = nm;
|
|
}
|
|
|
|
QString FragmentSlice::signature() const {
|
|
return parent().lock()->signature() + "&" + name();
|
|
}
|
|
|
|
std::shared_ptr<const IExprInstance> NGlobalElement::bindExpression() const {
|
|
return shared_from_this();
|
|
}
|
|
|
|
int NGlobalElement::typeMark() const {
|
|
return (int)NovelNode::GlobalElement;
|
|
}
|
|
|
|
bool NGlobalElement::isAnonymous() const {
|
|
return true;
|
|
}
|
|
|
|
QString NGlobalElement::path() const {
|
|
return ExprProgram::filePath();
|
|
}
|
|
|
|
QString NGlobalElement::signature() const {
|
|
return "::program";
|
|
}
|
|
|
|
int example_novel::NGlobalElement::depth() const {
|
|
return 1;
|
|
}
|
|
|
|
std::weak_ptr<const SyntaxElement> NGlobalElement::parent() const {
|
|
return std::weak_ptr<const SyntaxElement>();
|
|
}
|
|
|
|
QList<std::shared_ptr<const TokenAccess>> NGlobalElement::selfTokens() const {
|
|
return QList<std::shared_ptr<const TokenAccess>>();
|
|
}
|
|
|
|
NGlobalElement::NGlobalElement(const QString& root): ExprProgram(root) { }
|
|
|
|
void example_novel::NGlobalElement::appendError(const QList<QString>& errors) {
|
|
_errors_store.append(errors);
|
|
}
|
|
|
|
QList<QString> example_novel::NGlobalElement::errors() const {
|
|
return _errors_store;
|
|
}
|
|
|
|
|
|
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;
|
|
}
|