update
This commit is contained in:
parent
eb20475b26
commit
88bc1de7a4
|
@ -1,98 +0,0 @@
|
||||||
#include "ast_access.h"
|
|
||||||
|
|
||||||
using namespace ast_gen;
|
|
||||||
using namespace ast_basic;
|
|
||||||
|
|
||||||
|
|
||||||
GlobalElement* GlobalElement::UniquePtr = nullptr;
|
|
||||||
|
|
||||||
GlobalElement::GlobalElement(const QString& name) :names_store(name) {
|
|
||||||
UniquePtr = this;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlobalElement::clearCache() {
|
|
||||||
node_cache.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<const SyntaxElement> GlobalElement::appendToCache(std::shared_ptr<const SyntaxElement> named_node) {
|
|
||||||
auto mixed_key = QString(u8"%1<%2>").arg(named_node->signature()).arg(named_node->typeMark());
|
|
||||||
if (node_cache.contains(mixed_key))
|
|
||||||
return node_cache[mixed_key];
|
|
||||||
node_cache[mixed_key] = named_node;
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<const SyntaxElement> GlobalElement::getNamedNodeBy(int paramType, const QString& signature) const {
|
|
||||||
auto mixed_key = QString(u8"%1<%2>").arg(signature).arg(paramType);
|
|
||||||
if (!node_cache.contains(mixed_key))
|
|
||||||
return nullptr;
|
|
||||||
return node_cache[mixed_key];
|
|
||||||
}
|
|
||||||
|
|
||||||
int GlobalElement::typeMark() const {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GlobalElement::isAnonymous() const {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString GlobalElement::signature() const {
|
|
||||||
return u8"::global";
|
|
||||||
}
|
|
||||||
|
|
||||||
QString GlobalElement::path() const {
|
|
||||||
return u8"";
|
|
||||||
}
|
|
||||||
|
|
||||||
std::weak_ptr<const SyntaxElement> GlobalElement::parent() const {
|
|
||||||
return std::weak_ptr<const SyntaxElement>();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlobalElement::setParent(std::shared_ptr<const SyntaxElement> inst) { }
|
|
||||||
|
|
||||||
QList<std::shared_ptr<const TokenAccess>> GlobalElement::selfTokens() const {
|
|
||||||
return QList<std::shared_ptr<const TokenAccess>>();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<const IExprInstance> GlobalElement::bindExpression() const {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlobalElement::addChild(std::shared_ptr<SyntaxElement> citem) {
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
|
@ -1,136 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QString>
|
|
||||||
#include <QList>
|
|
||||||
#include <QHash>
|
|
||||||
#include "ast_basic.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace ast_gen {
|
|
||||||
class TokenAccess;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 解析上下文
|
|
||||||
*/
|
|
||||||
class SyntaxElement {
|
|
||||||
public:
|
|
||||||
virtual ~SyntaxElement() = default;
|
|
||||||
/**
|
|
||||||
* 绑定表达式实体.
|
|
||||||
*
|
|
||||||
* \return 表达式实例
|
|
||||||
*/
|
|
||||||
virtual std::shared_ptr<const ast_basic::IExprInstance> bindExpression() const = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 类型标记
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
virtual int typeMark() const = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否属于匿名节点.
|
|
||||||
*
|
|
||||||
* \return 匿名标志
|
|
||||||
*/
|
|
||||||
virtual bool isAnonymous() const = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 文件路径
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
virtual QString path() const = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 元素签名,如果是匿名元素返回空字符串
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
virtual QString signature() const = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 获取父元素
|
|
||||||
* @return 未设置parent,返回nullptr
|
|
||||||
*/
|
|
||||||
virtual std::weak_ptr<const SyntaxElement> parent() const = 0;
|
|
||||||
/**
|
|
||||||
* @brief 重置父指针.
|
|
||||||
*
|
|
||||||
* \param inst
|
|
||||||
*/
|
|
||||||
virtual void setParent(std::shared_ptr<const SyntaxElement> inst) = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 定义元素自身的Token集合
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
virtual QList<std::shared_ptr<const TokenAccess>> selfTokens() const = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 语法元素整理访问接口
|
|
||||||
*/
|
|
||||||
class LIBSYNTAX_EXPORT ElementAccess {
|
|
||||||
private:
|
|
||||||
std::shared_ptr<const SyntaxElement> peers;
|
|
||||||
|
|
||||||
public:
|
|
||||||
ElementAccess(std::shared_ptr<const SyntaxElement> point);
|
|
||||||
|
|
||||||
std::shared_ptr<const SyntaxElement> element() const;
|
|
||||||
QList<std::shared_ptr<const ElementAccess>> children() const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 获取该元素下所有Token定义
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
virtual QList<std::shared_ptr<const TokenAccess>> tokens() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
class LIBSYNTAX_EXPORT TokenAccess {
|
|
||||||
private:
|
|
||||||
std::shared_ptr<const ast_gen::SyntaxElement> element_bind;
|
|
||||||
std::shared_ptr<const lib_token::IToken> token_store;
|
|
||||||
|
|
||||||
public:
|
|
||||||
TokenAccess(std::shared_ptr<const ast_gen::SyntaxElement> elm_inst, std::shared_ptr<const lib_token::IToken> token_inst);
|
|
||||||
virtual std::shared_ptr<const ast_gen::SyntaxElement> bind() const;
|
|
||||||
virtual std::shared_ptr<const lib_token::IToken> token() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 根元素定义
|
|
||||||
*/
|
|
||||||
class LIBSYNTAX_EXPORT GlobalElement : public SyntaxElement {
|
|
||||||
private:
|
|
||||||
QString names_store;
|
|
||||||
QHash<QString, std::shared_ptr<const SyntaxElement>> node_cache;
|
|
||||||
|
|
||||||
public:
|
|
||||||
static GlobalElement* UniquePtr;
|
|
||||||
GlobalElement(const QString& name);
|
|
||||||
|
|
||||||
virtual void clearCache();
|
|
||||||
virtual std::shared_ptr<const ast_gen::SyntaxElement> appendToCache(std::shared_ptr<const ast_gen::SyntaxElement> named_node);
|
|
||||||
/**
|
|
||||||
* @brief 通过节点签名获取定义节点
|
|
||||||
* @param signature 完全签名
|
|
||||||
* @return
|
|
||||||
* @throws 没有指定节点抛出异常
|
|
||||||
*/
|
|
||||||
virtual std::shared_ptr<const ast_gen::SyntaxElement> getNamedNodeBy(int paramType, const QString& signature) const;
|
|
||||||
virtual void addChild(std::shared_ptr<ast_gen::SyntaxElement> citem);
|
|
||||||
|
|
||||||
// ParseElement interface
|
|
||||||
public:
|
|
||||||
virtual int typeMark() const override;
|
|
||||||
virtual bool isAnonymous() const override;
|
|
||||||
virtual QString signature() const override;
|
|
||||||
virtual QString path() const override;
|
|
||||||
virtual std::weak_ptr<const SyntaxElement> parent() const override;
|
|
||||||
virtual void setParent(std::shared_ptr<const SyntaxElement> inst) override;
|
|
||||||
virtual QList<std::shared_ptr<const TokenAccess>> selfTokens() const override;
|
|
||||||
|
|
||||||
// 通过 SyntaxElement 继承
|
|
||||||
virtual std::shared_ptr<const ast_basic::IExprInstance> bindExpression() const override;
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,5 +1,4 @@
|
||||||
#include "ast_gen.h"
|
#include "ast_gen.h"
|
||||||
#include "ast_access.h"
|
|
||||||
|
|
||||||
using namespace ast_gen;
|
using namespace ast_gen;
|
||||||
using namespace ast_basic;
|
using namespace ast_basic;
|
||||||
|
@ -27,10 +26,17 @@ QList<std::shared_ptr<const MatchCursor>> SyntaxParser::parse(std::shared_ptr<IP
|
||||||
std::shared_ptr<IExprInstance> ast_gen::SyntaxParser::getAst(
|
std::shared_ptr<IExprInstance> ast_gen::SyntaxParser::getAst(
|
||||||
std::shared_ptr<const lib_syntax::MatchCursor> cursor, std::shared_ptr<IExprInstance> root) {
|
std::shared_ptr<const lib_syntax::MatchCursor> cursor, std::shared_ptr<IExprInstance> root) {
|
||||||
|
|
||||||
|
QList<std::shared_ptr<const IActionToken>> token_seqs;
|
||||||
std::shared_ptr<const IActionToken> action_token = cursor->currentToken();
|
std::shared_ptr<const IActionToken> action_token = cursor->currentToken();
|
||||||
while (action_token->prevToken()) {
|
while (action_token) {
|
||||||
|
token_seqs.prepend(action_token);
|
||||||
action_token = action_token->prevToken();
|
action_token = action_token->prevToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::const_pointer_cast<IActionToken>(action_token)->makeSure(root);
|
auto expr_inst = root;
|
||||||
|
for (auto ins_t : token_seqs) {
|
||||||
|
expr_inst = std::const_pointer_cast<IActionToken>(ins_t)->makeSure(expr_inst);
|
||||||
|
}
|
||||||
|
|
||||||
|
return expr_inst;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ namespace ast_gen {
|
||||||
/**
|
/**
|
||||||
* @brief 语法解析器
|
* @brief 语法解析器
|
||||||
*/
|
*/
|
||||||
class SyntaxParser {
|
class LIBSYNTAX_EXPORT SyntaxParser {
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<lib_syntax::IBasicRule> _rule_bind = nullptr;
|
std::shared_ptr<lib_syntax::IBasicRule> _rule_bind = nullptr;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include "ast_novel.h"
|
#include "ast_novel.h"
|
||||||
|
#include <QtCore/QString>
|
||||||
|
|
||||||
using namespace example_novel;
|
using namespace example_novel;
|
||||||
using namespace lib_syntax;
|
using namespace lib_syntax;
|
||||||
|
@ -199,3 +199,101 @@ QList<std::shared_ptr<const TokenAccess>> NGlobalElement::selfTokens() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
NGlobalElement::NGlobalElement(const QString& root): ExprProgram(root) { }
|
NGlobalElement::NGlobalElement(const QString& root): ExprProgram(root) { }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
using namespace ast_gen;
|
||||||
|
using namespace ast_basic;
|
||||||
|
|
||||||
|
|
||||||
|
GlobalElement* GlobalElement::UniquePtr = nullptr;
|
||||||
|
|
||||||
|
GlobalElement::GlobalElement(const QString& name) :names_store(name) {
|
||||||
|
UniquePtr = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobalElement::clearCache() {
|
||||||
|
node_cache.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<const SyntaxElement> GlobalElement::appendToCache(std::shared_ptr<const SyntaxElement> named_node) {
|
||||||
|
auto mixed_key = QString(u8"%1<%2>").arg(named_node->signature()).arg(named_node->typeMark());
|
||||||
|
if (node_cache.contains(mixed_key))
|
||||||
|
return node_cache[mixed_key];
|
||||||
|
node_cache[mixed_key] = named_node;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<const SyntaxElement> GlobalElement::getNamedNodeBy(int paramType, const QString& signature) const {
|
||||||
|
auto mixed_key = QString(u8"%1<%2>").arg(signature).arg(paramType);
|
||||||
|
if (!node_cache.contains(mixed_key))
|
||||||
|
return nullptr;
|
||||||
|
return node_cache[mixed_key];
|
||||||
|
}
|
||||||
|
|
||||||
|
int GlobalElement::typeMark() const {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GlobalElement::isAnonymous() const {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString GlobalElement::signature() const {
|
||||||
|
return u8"::global";
|
||||||
|
}
|
||||||
|
|
||||||
|
QString GlobalElement::path() const {
|
||||||
|
return u8"";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::weak_ptr<const SyntaxElement> GlobalElement::parent() const {
|
||||||
|
return std::weak_ptr<const SyntaxElement>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobalElement::setParent(std::shared_ptr<const SyntaxElement> inst) { }
|
||||||
|
|
||||||
|
QList<std::shared_ptr<const TokenAccess>> GlobalElement::selfTokens() const {
|
||||||
|
return QList<std::shared_ptr<const TokenAccess>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<const IExprInstance> GlobalElement::bindExpression() const {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobalElement::addChild(std::shared_ptr<SyntaxElement> citem) { }
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -1,8 +1,141 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ast_access.h"
|
|
||||||
#include "ast_basic.h"
|
#include "ast_basic.h"
|
||||||
#include "libsyntax.h"
|
#include "libsyntax.h"
|
||||||
|
#include <QtCore/QHash>
|
||||||
|
#include <QtCore/QString>
|
||||||
|
|
||||||
|
namespace ast_gen {
|
||||||
|
class TokenAccess;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 解析上下文
|
||||||
|
*/
|
||||||
|
class SyntaxElement {
|
||||||
|
public:
|
||||||
|
virtual ~SyntaxElement() = default;
|
||||||
|
/**
|
||||||
|
* 绑定表达式实体.
|
||||||
|
*
|
||||||
|
* \return 表达式实例
|
||||||
|
*/
|
||||||
|
virtual std::shared_ptr<const ast_basic::IExprInstance> bindExpression() const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 类型标记
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
virtual int typeMark() const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否属于匿名节点.
|
||||||
|
*
|
||||||
|
* \return 匿名标志
|
||||||
|
*/
|
||||||
|
virtual bool isAnonymous() const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 文件路径
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
virtual QString path() const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 元素签名,如果是匿名元素返回空字符串
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
virtual QString signature() const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 获取父元素
|
||||||
|
* @return 未设置parent,返回nullptr
|
||||||
|
*/
|
||||||
|
virtual std::weak_ptr<const SyntaxElement> parent() const = 0;
|
||||||
|
/**
|
||||||
|
* @brief 重置父指针.
|
||||||
|
*
|
||||||
|
* \param inst
|
||||||
|
*/
|
||||||
|
virtual void setParent(std::shared_ptr<const SyntaxElement> inst) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 定义元素自身的Token集合
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
virtual QList<std::shared_ptr<const TokenAccess>> selfTokens() const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 语法元素整理访问接口
|
||||||
|
*/
|
||||||
|
class LIBSYNTAX_EXPORT ElementAccess {
|
||||||
|
private:
|
||||||
|
std::shared_ptr<const SyntaxElement> peers;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ElementAccess(std::shared_ptr<const SyntaxElement> point);
|
||||||
|
|
||||||
|
std::shared_ptr<const SyntaxElement> element() const;
|
||||||
|
QList<std::shared_ptr<const ElementAccess>> children() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 获取该元素下所有Token定义
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
virtual QList<std::shared_ptr<const TokenAccess>> tokens() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Token元素访问接口
|
||||||
|
*/
|
||||||
|
class LIBSYNTAX_EXPORT TokenAccess {
|
||||||
|
private:
|
||||||
|
std::shared_ptr<const ast_gen::SyntaxElement> element_bind;
|
||||||
|
std::shared_ptr<const lib_token::IToken> token_store;
|
||||||
|
|
||||||
|
public:
|
||||||
|
TokenAccess(std::shared_ptr<const ast_gen::SyntaxElement> elm_inst, std::shared_ptr<const lib_token::IToken> token_inst);
|
||||||
|
virtual std::shared_ptr<const ast_gen::SyntaxElement> bind() const;
|
||||||
|
virtual std::shared_ptr<const lib_token::IToken> token() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 根元素定义
|
||||||
|
*/
|
||||||
|
class LIBSYNTAX_EXPORT GlobalElement : public SyntaxElement {
|
||||||
|
private:
|
||||||
|
QString names_store;
|
||||||
|
QHash<QString, std::shared_ptr<const SyntaxElement>> node_cache;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static GlobalElement* UniquePtr;
|
||||||
|
GlobalElement(const QString& name);
|
||||||
|
|
||||||
|
virtual void clearCache();
|
||||||
|
virtual std::shared_ptr<const ast_gen::SyntaxElement> appendToCache(std::shared_ptr<const ast_gen::SyntaxElement> named_node);
|
||||||
|
/**
|
||||||
|
* @brief 通过节点签名获取定义节点
|
||||||
|
* @param signature 完全签名
|
||||||
|
* @return
|
||||||
|
* @throws 没有指定节点抛出异常
|
||||||
|
*/
|
||||||
|
virtual std::shared_ptr<const ast_gen::SyntaxElement> getNamedNodeBy(int paramType, const QString& signature) const;
|
||||||
|
virtual void addChild(std::shared_ptr<ast_gen::SyntaxElement> citem);
|
||||||
|
|
||||||
|
// ParseElement interface
|
||||||
|
public:
|
||||||
|
virtual int typeMark() const override;
|
||||||
|
virtual bool isAnonymous() const override;
|
||||||
|
virtual QString signature() const override;
|
||||||
|
virtual QString path() const override;
|
||||||
|
virtual std::weak_ptr<const SyntaxElement> parent() const override;
|
||||||
|
virtual void setParent(std::shared_ptr<const SyntaxElement> inst) override;
|
||||||
|
virtual QList<std::shared_ptr<const TokenAccess>> selfTokens() const override;
|
||||||
|
|
||||||
|
// 通过 SyntaxElement 继承
|
||||||
|
virtual std::shared_ptr<const ast_basic::IExprInstance> bindExpression() const override;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
namespace example_novel {
|
namespace example_novel {
|
||||||
enum class NovelNode {
|
enum class NovelNode {
|
||||||
|
@ -236,6 +369,9 @@ namespace example_novel {
|
||||||
virtual QString signature() const override;
|
virtual QString signature() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 全局根元素
|
||||||
|
*/
|
||||||
class LIBSYNTAX_EXPORT NGlobalElement : public ast_basic::ExprProgram, public ast_gen::SyntaxElement {
|
class LIBSYNTAX_EXPORT NGlobalElement : public ast_basic::ExprProgram, public ast_gen::SyntaxElement {
|
||||||
public:
|
public:
|
||||||
NGlobalElement(const QString &root);
|
NGlobalElement(const QString &root);
|
||||||
|
|
|
@ -108,11 +108,9 @@
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="ast_access.cpp" />
|
|
||||||
<ClCompile Include="libtokens.cpp" />
|
<ClCompile Include="libtokens.cpp" />
|
||||||
<ClCompile Include="syntax_novel.cpp" />
|
<ClCompile Include="syntax_novel.cpp" />
|
||||||
<ClCompile Include="tokens_novel.cpp" />
|
<ClCompile Include="tokens_novel.cpp" />
|
||||||
<ClInclude Include="ast_access.h" />
|
|
||||||
<ClInclude Include="ast_basic.h" />
|
<ClInclude Include="ast_basic.h" />
|
||||||
<ClInclude Include="ast_gen.h" />
|
<ClInclude Include="ast_gen.h" />
|
||||||
<ClInclude Include="ast_novel.h" />
|
<ClInclude Include="ast_novel.h" />
|
||||||
|
|
|
@ -53,9 +53,6 @@
|
||||||
<ClInclude Include="tokens_impl.h">
|
<ClInclude Include="tokens_impl.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="ast_access.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="ast_basic.cpp">
|
<ClCompile Include="ast_basic.cpp">
|
||||||
|
@ -76,8 +73,5 @@
|
||||||
<ClCompile Include="tokens_novel.cpp">
|
<ClCompile Include="tokens_novel.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="ast_access.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -148,8 +148,8 @@ auto document_define = ElementRule<Document>(u8"decls-doc", (int) NovelNode::Doc
|
||||||
MultiR(std::make_shared<const Any>(Rules{story_define, volume_decl}))
|
MultiR(std::make_shared<const Any>(Rules{story_define, volume_decl}))
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
//
|
|
||||||
//std::shared_ptr<const ExprRule> NovalSyntax::getParseTree() { return document_define; }
|
std::shared_ptr<const ExprRule> NovalSyntax::getSyntaxTree() { return document_define; }
|
||||||
//std::shared_ptr<const ast_gen::SyntaxElement> NovalSyntax::tidy(std::shared_ptr<ast_gen::SyntaxElement> root, QList<std::shared_ptr<ast_gen::SyntaxElement>> children)
|
//std::shared_ptr<const ast_gen::SyntaxElement> NovalSyntax::tidy(std::shared_ptr<ast_gen::SyntaxElement> root, QList<std::shared_ptr<ast_gen::SyntaxElement>> children)
|
||||||
//{
|
//{
|
||||||
// build_objecttree(root, children);
|
// build_objecttree(root, children);
|
||||||
|
|
|
@ -7,19 +7,19 @@
|
||||||
#include <tokens_novel.h>
|
#include <tokens_novel.h>
|
||||||
|
|
||||||
namespace example_novel {
|
namespace example_novel {
|
||||||
//class LIBSYNTAX_EXPORT NovalSyntax {
|
class LIBSYNTAX_EXPORT NovalSyntax {
|
||||||
//public:
|
public:
|
||||||
// /**
|
/**
|
||||||
// * @brief 获取novel语法解析树
|
* @brief 获取novel语法解析树
|
||||||
// * @return
|
* @return
|
||||||
// */
|
*/
|
||||||
// static std::shared_ptr<const ExprRule> getParseTree();
|
static std::shared_ptr<const lib_syntax::ExprRule> getSyntaxTree();
|
||||||
|
|
||||||
// static std::shared_ptr<const ast_gen::SyntaxElement> tidy(std::shared_ptr<ast_gen::SyntaxElement> root, QList<std::shared_ptr<ast_gen::SyntaxElement>> docs);
|
// static std::shared_ptr<const ast_gen::SyntaxElement> tidy(std::shared_ptr<ast_gen::SyntaxElement> root, QList<std::shared_ptr<ast_gen::SyntaxElement>> docs);
|
||||||
|
|
||||||
//private:
|
//private:
|
||||||
// static void build_objecttree(std::shared_ptr<ast_gen::SyntaxElement> root, QList<std::shared_ptr<ast_gen::SyntaxElement>> docs);
|
// static void build_objecttree(std::shared_ptr<ast_gen::SyntaxElement> root, QList<std::shared_ptr<ast_gen::SyntaxElement>> docs);
|
||||||
// static void node_register(std::shared_ptr<const ast_gen::SyntaxElement> root, QList<std::shared_ptr<ast_gen::SyntaxElement>> docs);
|
// static void node_register(std::shared_ptr<const ast_gen::SyntaxElement> root, QList<std::shared_ptr<ast_gen::SyntaxElement>> docs);
|
||||||
//};
|
};
|
||||||
|
|
||||||
} // namespace example_novel
|
} // namespace example_novel
|
Loading…
Reference in New Issue