encoding update
This commit is contained in:
parent
22f2d1adf2
commit
735a9fb210
|
|
@ -14,7 +14,7 @@ std::shared_ptr<const ExprRule> ExprInstance::definedRule() const {
|
|||
|
||||
QString ExprInstance::filePath() const {
|
||||
if (!tokens_bind.size())
|
||||
throw new SyntaxException(u8"InternalError[0x0002]一个空的非法无效节点");
|
||||
throw new SyntaxException("InternalError[0x0002]一个空的非法无效节点");
|
||||
|
||||
return tokens_bind.first()->file();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,55 +9,55 @@ namespace lib_syntax {
|
|||
class ExprRule;
|
||||
}
|
||||
|
||||
// 抽象语法树结构 ====================================================================
|
||||
// 抽象语法树结构 ====================================================================
|
||||
namespace ast_basic {
|
||||
/**
|
||||
* @brief 抽象语法树集合节点/表达式节点
|
||||
* @brief 抽象语法树集合节点/表达式节点
|
||||
*/
|
||||
class IExprInstance {
|
||||
public:
|
||||
/**
|
||||
* @brief 获取表达式的解析规则
|
||||
* @brief 获取表达式的解析规则
|
||||
* @return
|
||||
*/
|
||||
virtual std::shared_ptr<const lib_syntax::ExprRule> definedRule() const = 0;
|
||||
//=====================================================
|
||||
/**
|
||||
* 获取语法节点的源码文件路径.
|
||||
* 获取语法节点的源码文件路径.
|
||||
*
|
||||
* \return 文件路径
|
||||
* \return 文件路径
|
||||
*/
|
||||
virtual QString filePath() const = 0;
|
||||
/**
|
||||
* 获取语法节点关联token序列.
|
||||
* 获取语法节点关联token序列.
|
||||
*
|
||||
* \return token序列
|
||||
* \return token序列
|
||||
*/
|
||||
virtual QList<std::shared_ptr<const lib_token::IToken>> tokens() const = 0;
|
||||
/**
|
||||
* 解析过程中,向表达式内部添加token实例.
|
||||
* 解析过程中,向表达式内部添加token实例.
|
||||
*
|
||||
* \param token_inst 实例
|
||||
* \param token_inst 实例
|
||||
*/
|
||||
virtual void addToken(std::shared_ptr<const lib_token::IToken> token_inst) = 0;
|
||||
//=====================================================
|
||||
/**
|
||||
* @brief 子表达式集合
|
||||
* @brief 子表达式集合
|
||||
* @return
|
||||
*/
|
||||
virtual QList<std::shared_ptr<const IExprInstance>> children() const = 0;
|
||||
/**
|
||||
* @brief 添加子表达式.
|
||||
* @brief 添加子表达式.
|
||||
*
|
||||
* \param inst 子表达式实例
|
||||
* \param inst 子表达式实例
|
||||
*/
|
||||
virtual void addChild(std::shared_ptr<const IExprInstance> inst) = 0;
|
||||
};
|
||||
|
||||
|
||||
// 基础语法树构成 ==========================================================================================
|
||||
// 基础语法树构成 ==========================================================================================
|
||||
/**
|
||||
* @brief 表达式节点
|
||||
* @brief 表达式节点
|
||||
*/
|
||||
class LIBSYNTAX_EXPORT ExprInstance : public IExprInstance, public std::enable_shared_from_this<ExprInstance> {
|
||||
private:
|
||||
|
|
@ -68,7 +68,7 @@ namespace ast_basic {
|
|||
public:
|
||||
ExprInstance(std::shared_ptr<const lib_syntax::ExprRule> bind);
|
||||
|
||||
// 通过 Expression 继承
|
||||
// 通过 Expression 继承
|
||||
std::shared_ptr<const lib_syntax::ExprRule> definedRule() const override;
|
||||
QString filePath() const override;
|
||||
|
||||
|
|
@ -80,7 +80,7 @@ namespace ast_basic {
|
|||
};
|
||||
|
||||
/**
|
||||
* @brief 表达式树根节点
|
||||
* @brief 表达式树根节点
|
||||
*/
|
||||
class LIBSYNTAX_EXPORT ExprProgram : public IExprInstance, public std::enable_shared_from_this<ExprProgram> {
|
||||
private:
|
||||
|
|
@ -90,7 +90,7 @@ namespace ast_basic {
|
|||
public:
|
||||
ExprProgram(const QString &root);
|
||||
|
||||
// 通过 IExprInstance 继承
|
||||
// 通过 IExprInstance 继承
|
||||
std::shared_ptr<const lib_syntax::ExprRule> definedRule() const override;
|
||||
QString filePath() const override;
|
||||
QList<std::shared_ptr<const lib_token::IToken>> tokens() const override;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
namespace ast_gen {
|
||||
|
||||
/**
|
||||
* @brief 语法解析器
|
||||
* @brief 语法解析器
|
||||
*/
|
||||
class LIBSYNTAX_EXPORT SyntaxParser {
|
||||
private:
|
||||
|
|
@ -17,17 +17,17 @@ namespace ast_gen {
|
|||
SyntaxParser(std::shared_ptr<const lib_syntax::IBasicRule> rule);
|
||||
|
||||
/**
|
||||
* @brief 依据源码语法规则,解析源码链表
|
||||
* @param wods 源码链表
|
||||
* @return 所有解析路径,按照错误数量排序:少->多
|
||||
* @brief 依据源码语法规则,解析源码链表
|
||||
* @param wods 源码链表
|
||||
* @return 所有解析路径,按照错误数量排序:少->多
|
||||
*/
|
||||
QList<std::shared_ptr<const lib_syntax::MatchCursor>> parse(std::shared_ptr<const lib_words::IPrimitiveWord> words);
|
||||
|
||||
/**
|
||||
* @brief 依据指定解析路径,提取程序解构
|
||||
* @param cursor 解析路径
|
||||
* @param root 表达式树预制根节点
|
||||
* @return 完善后的根节点
|
||||
* @brief 依据指定解析路径,提取程序解构
|
||||
* @param cursor 解析路径
|
||||
* @param root 表达式树预制根节点
|
||||
* @return 完善后的根节点
|
||||
*/
|
||||
std::shared_ptr<ast_basic::IExprInstance> getAst(
|
||||
std::shared_ptr<const lib_syntax::MatchCursor> cursor, std::shared_ptr<ast_basic::IExprInstance> root);
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ QString TextSection::content() const {
|
|||
}
|
||||
|
||||
QString TextSection::signature() const {
|
||||
return u8"::section";
|
||||
return "::section";
|
||||
}
|
||||
|
||||
PointRefers::PointRefers(std::shared_ptr<const ExprRule> rule_bind)
|
||||
|
|
@ -50,12 +50,12 @@ void PointRefers::setPointRefer(const QString& refer) {
|
|||
}
|
||||
|
||||
QString PointRefers::referSignature() const {
|
||||
return storyRefer() + u8"&" + sliceRefer() + u8"&" + pointRefer();
|
||||
return storyRefer() + "&" + sliceRefer() + "&" + pointRefer();
|
||||
}
|
||||
|
||||
QString PointRefers::signature() const {
|
||||
QString signature = u8"@" + referSignature();
|
||||
return parent().lock()->signature() + u8"&" + signature;
|
||||
QString signature = "@" + referSignature();
|
||||
return parent().lock()->signature() + "&" + signature;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ void PointDefines::setName(const QString& nm) {
|
|||
}
|
||||
|
||||
QString PointDefines::signature() const {
|
||||
return parent().lock()->signature() + u8"&" + name();
|
||||
return parent().lock()->signature() + "&" + name();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -103,7 +103,7 @@ Document::Document(std::shared_ptr<const ExprRule> rule_bind)
|
|||
: AbstractImpl(rule_bind) { }
|
||||
|
||||
QString Document::signature() const {
|
||||
return QString(u8"::document<%1>").arg(path());
|
||||
return QString("::document<%1>").arg(path());
|
||||
}
|
||||
|
||||
VolumeDefine::VolumeDefine(std::shared_ptr<const ExprRule> rule_bind)
|
||||
|
|
@ -133,7 +133,7 @@ void ArticleDefine::setName(const QString& nm) {
|
|||
}
|
||||
|
||||
QString ArticleDefine::signature() const {
|
||||
return parent().lock()->signature() + u8"&" + name();
|
||||
return parent().lock()->signature() + "&" + name();
|
||||
}
|
||||
|
||||
RankDeclare::RankDeclare(std::shared_ptr<const ExprRule> rule)
|
||||
|
|
@ -148,12 +148,12 @@ void RankDeclare::setRank(int nums) {
|
|||
}
|
||||
|
||||
QString RankDeclare::signature() const {
|
||||
return u8"::rank";
|
||||
return "::rank";
|
||||
}
|
||||
|
||||
FragmentSlice::FragmentSlice(std::shared_ptr<const ExprRule> rule)
|
||||
:AbstractImpl(rule) {
|
||||
_slice_name = QString(u8"Ãû³ÆÎ´¶¨Òå_%1").arg((uint64_t)this);
|
||||
_slice_name = QString("名称未定义_%1").arg((uint64_t)this);
|
||||
}
|
||||
|
||||
QString FragmentSlice::name() const {
|
||||
|
|
@ -165,7 +165,7 @@ void FragmentSlice::setName(const QString& nm) {
|
|||
}
|
||||
|
||||
QString FragmentSlice::signature() const {
|
||||
return parent().lock()->signature() + u8"&" + name();
|
||||
return parent().lock()->signature() + "&" + name();
|
||||
}
|
||||
|
||||
std::shared_ptr<const IExprInstance> NGlobalElement::bindExpression() const {
|
||||
|
|
@ -185,7 +185,7 @@ QString NGlobalElement::path() const {
|
|||
}
|
||||
|
||||
QString NGlobalElement::signature() const {
|
||||
return u8"::program";
|
||||
return "::program";
|
||||
}
|
||||
|
||||
std::weak_ptr<const SyntaxElement> NGlobalElement::parent() const {
|
||||
|
|
@ -217,7 +217,7 @@ void GlobalElement::clearCache() {
|
|||
}
|
||||
|
||||
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());
|
||||
auto mixed_key = QString("%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;
|
||||
|
|
@ -225,7 +225,7 @@ std::shared_ptr<const SyntaxElement> GlobalElement::appendToCache(std::shared_pt
|
|||
}
|
||||
|
||||
std::shared_ptr<const SyntaxElement> GlobalElement::getNamedNodeBy(int paramType, const QString& signature) const {
|
||||
auto mixed_key = QString(u8"%1<%2>").arg(signature).arg(paramType);
|
||||
auto mixed_key = QString("%1<%2>").arg(signature).arg(paramType);
|
||||
if (!node_cache.contains(mixed_key))
|
||||
return nullptr;
|
||||
return node_cache[mixed_key];
|
||||
|
|
@ -240,11 +240,11 @@ bool GlobalElement::isAnonymous() const {
|
|||
}
|
||||
|
||||
QString GlobalElement::signature() const {
|
||||
return u8"::global";
|
||||
return "::global";
|
||||
}
|
||||
|
||||
QString GlobalElement::path() const {
|
||||
return u8"";
|
||||
return "";
|
||||
}
|
||||
|
||||
std::weak_ptr<const SyntaxElement> GlobalElement::parent() const {
|
||||
|
|
|
|||
|
|
@ -9,64 +9,64 @@ namespace ast_gen {
|
|||
class TokenAccess;
|
||||
|
||||
/**
|
||||
* @brief 解析上下文
|
||||
* @brief 解析上下文
|
||||
*/
|
||||
class SyntaxElement {
|
||||
public:
|
||||
virtual ~SyntaxElement() = default;
|
||||
/**
|
||||
* 绑定表达式实体.
|
||||
* 绑定表达式实体.
|
||||
*
|
||||
* \return 表达式实例
|
||||
* \return 表达式实例
|
||||
*/
|
||||
virtual std::shared_ptr<const ast_basic::IExprInstance> bindExpression() const = 0;
|
||||
|
||||
/**
|
||||
* @brief 类型标记
|
||||
* @brief 类型标记
|
||||
* @return
|
||||
*/
|
||||
virtual int typeMark() const = 0;
|
||||
|
||||
/**
|
||||
* 是否属于匿名节点.
|
||||
* 是否属于匿名节点.
|
||||
*
|
||||
* \return 匿名标志
|
||||
* \return 匿名标志
|
||||
*/
|
||||
virtual bool isAnonymous() const = 0;
|
||||
|
||||
/**
|
||||
* @brief 文件路径
|
||||
* @brief 文件路径
|
||||
* @return
|
||||
*/
|
||||
virtual QString path() const = 0;
|
||||
|
||||
/**
|
||||
* @brief 元素签名,如果是匿名元素返回空字符串
|
||||
* @brief 元素签名,如果是匿名元素返回空字符串
|
||||
* @return
|
||||
*/
|
||||
virtual QString signature() const = 0;
|
||||
|
||||
/**
|
||||
* @brief 获取父元素
|
||||
* @return 未设置parent,返回nullptr
|
||||
* @brief 获取父元素
|
||||
* @return 未设置parent,返回nullptr
|
||||
*/
|
||||
virtual std::weak_ptr<const SyntaxElement> parent() const = 0;
|
||||
/**
|
||||
* @brief 重置父指针.
|
||||
* @brief 重置父指针.
|
||||
*
|
||||
* \param inst
|
||||
*/
|
||||
virtual void setParent(std::shared_ptr<const SyntaxElement> inst) = 0;
|
||||
|
||||
/**
|
||||
* @brief 定义元素自身的Token集合
|
||||
* @brief 定义元素自身的Token集合
|
||||
* @return
|
||||
*/
|
||||
virtual QList<std::shared_ptr<const TokenAccess>> selfTokens() const = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 语法元素整理访问接口
|
||||
* @brief 语法元素整理访问接口
|
||||
*/
|
||||
class LIBSYNTAX_EXPORT ElementAccess {
|
||||
private:
|
||||
|
|
@ -79,14 +79,14 @@ namespace ast_gen {
|
|||
QList<std::shared_ptr<const ElementAccess>> children() const;
|
||||
|
||||
/**
|
||||
* @brief 获取该元素下所有Token定义
|
||||
* @brief 获取该元素下所有Token定义
|
||||
* @return
|
||||
*/
|
||||
virtual QList<std::shared_ptr<const TokenAccess>> tokens() const;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Token元素访问接口
|
||||
* @brief Token元素访问接口
|
||||
*/
|
||||
class LIBSYNTAX_EXPORT TokenAccess {
|
||||
private:
|
||||
|
|
@ -100,7 +100,7 @@ namespace ast_gen {
|
|||
};
|
||||
|
||||
/**
|
||||
* @brief 根元素定义
|
||||
* @brief 根元素定义
|
||||
*/
|
||||
class LIBSYNTAX_EXPORT GlobalElement : public SyntaxElement {
|
||||
private:
|
||||
|
|
@ -114,10 +114,10 @@ namespace ast_gen {
|
|||
virtual void clearCache();
|
||||
virtual std::shared_ptr<const ast_gen::SyntaxElement> appendToCache(std::shared_ptr<const ast_gen::SyntaxElement> named_node);
|
||||
/**
|
||||
* @brief 通过节点签名获取定义节点
|
||||
* @param signature 完全签名
|
||||
* @brief 通过节点签名获取定义节点
|
||||
* @param signature 完全签名
|
||||
* @return
|
||||
* @throws 没有指定节点抛出异常
|
||||
* @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);
|
||||
|
|
@ -132,7 +132,7 @@ namespace ast_gen {
|
|||
virtual void setParent(std::shared_ptr<const SyntaxElement> inst) override;
|
||||
virtual QList<std::shared_ptr<const TokenAccess>> selfTokens() const override;
|
||||
|
||||
// 通过 SyntaxElement 继承
|
||||
// 通过 SyntaxElement 继承
|
||||
virtual std::shared_ptr<const ast_basic::IExprInstance> bindExpression() const override;
|
||||
};
|
||||
}
|
||||
|
|
@ -182,7 +182,7 @@ namespace example_novel {
|
|||
parent_store.reset();
|
||||
}
|
||||
|
||||
// 通过 SyntaxElement 继承
|
||||
// 通过 SyntaxElement 继承
|
||||
virtual int typeMark() const override {
|
||||
return (int) type;
|
||||
}
|
||||
|
|
@ -213,23 +213,23 @@ namespace example_novel {
|
|||
};
|
||||
|
||||
/**
|
||||
* @brief 文字段落
|
||||
* @brief 文字段落
|
||||
*/
|
||||
class LIBSYNTAX_EXPORT TextSection : public AbstractImpl<NovelNode::TextSection, false> {
|
||||
public:
|
||||
TextSection(std::shared_ptr<const lib_syntax::ExprRule> rule_bind);
|
||||
|
||||
/**
|
||||
* @brief 段落内容
|
||||
* @brief 段落内容
|
||||
*/
|
||||
QString content() const;
|
||||
|
||||
// 通过 AbstractImpl 继承
|
||||
// 通过 AbstractImpl 继承
|
||||
virtual QString signature() const override;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 故事情节
|
||||
* @brief 故事情节
|
||||
*/
|
||||
class LIBSYNTAX_EXPORT FragmentSlice : public AbstractImpl<NovelNode::FragmentSlice, true> {
|
||||
private:
|
||||
|
|
@ -241,12 +241,12 @@ namespace example_novel {
|
|||
QString name() const;
|
||||
void setName(const QString& nm);
|
||||
|
||||
// 通过 AbstractImpl 继承
|
||||
// 通过 AbstractImpl 继承
|
||||
QString signature() const override;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 节点引用定义
|
||||
* @brief 节点引用定义
|
||||
*/
|
||||
class LIBSYNTAX_EXPORT PointRefers : public AbstractImpl<NovelNode::PointRefers, false> {
|
||||
private:
|
||||
|
|
@ -266,12 +266,12 @@ namespace example_novel {
|
|||
|
||||
QString referSignature() const;
|
||||
|
||||
// 通过 AbstractImpl 继承
|
||||
// 通过 AbstractImpl 继承
|
||||
virtual QString signature() const override;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 节点定义
|
||||
* @brief 节点定义
|
||||
*/
|
||||
class LIBSYNTAX_EXPORT PointDefines : public AbstractImpl<NovelNode::PointDefines, true> {
|
||||
private:
|
||||
|
|
@ -283,12 +283,12 @@ namespace example_novel {
|
|||
QString name() const;
|
||||
void setName(const QString& nm);
|
||||
|
||||
// 通过 AbstractImpl 继承
|
||||
// 通过 AbstractImpl 继承
|
||||
virtual QString signature() const override;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 章节定义
|
||||
* @brief 章节定义
|
||||
*/
|
||||
class LIBSYNTAX_EXPORT ArticleDefine : public AbstractImpl<NovelNode::ArticleDefine, true> {
|
||||
public:
|
||||
|
|
@ -297,7 +297,7 @@ namespace example_novel {
|
|||
QString name() const;
|
||||
void setName(const QString& nm);
|
||||
|
||||
// 通过 AbstractImpl 继承
|
||||
// 通过 AbstractImpl 继承
|
||||
virtual QString signature() const override;
|
||||
|
||||
private:
|
||||
|
|
@ -305,7 +305,7 @@ namespace example_novel {
|
|||
};
|
||||
|
||||
/**
|
||||
* @brief 卷宗定义
|
||||
* @brief 卷宗定义
|
||||
*/
|
||||
class LIBSYNTAX_EXPORT VolumeDefine : public AbstractImpl<NovelNode::VolumeDefine, true> {
|
||||
public:
|
||||
|
|
@ -314,7 +314,7 @@ namespace example_novel {
|
|||
QString name() const;
|
||||
void setName(const QString& nm);
|
||||
|
||||
// 通过 AbstractImpl 继承
|
||||
// 通过 AbstractImpl 继承
|
||||
virtual QString signature() const override;
|
||||
|
||||
private:
|
||||
|
|
@ -322,7 +322,7 @@ namespace example_novel {
|
|||
};
|
||||
|
||||
/**
|
||||
* @brief 故事定义
|
||||
* @brief 故事定义
|
||||
*/
|
||||
class LIBSYNTAX_EXPORT StoryDefine : public AbstractImpl<NovelNode::StoryDefine, true> {
|
||||
public:
|
||||
|
|
@ -334,7 +334,7 @@ namespace example_novel {
|
|||
void setSort(int value);
|
||||
int sort() const;
|
||||
|
||||
// 通过 AbstractImpl 继承
|
||||
// 通过 AbstractImpl 继承
|
||||
virtual QString signature() const override;
|
||||
|
||||
private:
|
||||
|
|
@ -343,7 +343,7 @@ namespace example_novel {
|
|||
};
|
||||
|
||||
/**
|
||||
* @brief 排序声明
|
||||
* @brief 排序声明
|
||||
*/
|
||||
class LIBSYNTAX_EXPORT RankDeclare : public AbstractImpl<NovelNode::RankDeclaration, false> {
|
||||
private:
|
||||
|
|
@ -354,29 +354,29 @@ namespace example_novel {
|
|||
int rankNumber() const;
|
||||
void setRank(int nums);
|
||||
|
||||
// 通过 AbstractImpl 继承
|
||||
// 通过 AbstractImpl 继承
|
||||
QString signature() const override;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 文档定义
|
||||
* @brief 文档定义
|
||||
*/
|
||||
class LIBSYNTAX_EXPORT Document : public AbstractImpl<NovelNode::Document, false> {
|
||||
public:
|
||||
Document(std::shared_ptr<const lib_syntax::ExprRule> rule_bind);
|
||||
|
||||
// 通过 AbstractImpl 继承
|
||||
// 通过 AbstractImpl 继承
|
||||
virtual QString signature() const override;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 全局根元素
|
||||
* @brief 全局根元素
|
||||
*/
|
||||
class LIBSYNTAX_EXPORT NGlobalElement : public ast_basic::ExprProgram, public ast_gen::SyntaxElement {
|
||||
public:
|
||||
NGlobalElement(const QString &root);
|
||||
|
||||
// 通过 SyntaxElement 继承
|
||||
// 通过 SyntaxElement 继承
|
||||
std::shared_ptr<const ast_basic::IExprInstance> bindExpression() const override;
|
||||
int typeMark() const override;
|
||||
bool isAnonymous() const override;
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
|
|
@ -73,8 +74,9 @@
|
|||
<AdditionalDependencies>libWords.lib;%(AdditionalDependencies);$(Qt_LIBS_)</AdditionalDependencies>
|
||||
</Link>
|
||||
<ClCompile>
|
||||
<LanguageStandard>Default</LanguageStandard>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<PreprocessToFile>false</PreprocessToFile>
|
||||
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
|
|
@ -123,6 +125,7 @@
|
|||
<ClCompile Include="libsyntax.cpp" />
|
||||
<ClInclude Include="libtokens.h" />
|
||||
<ClInclude Include="syntax_novel.h" />
|
||||
<ClInclude Include="syntax_templets.h" />
|
||||
<ClInclude Include="tokens_impl.h" />
|
||||
<ClInclude Include="tokens_novel.h" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -53,6 +53,9 @@
|
|||
<ClInclude Include="tokens_impl.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="syntax_templets.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="ast_basic.cpp">
|
||||
|
|
|
|||
|
|
@ -29,36 +29,11 @@ QList<std::shared_ptr<const MatchCursor>> Any::parse(std::shared_ptr<const Match
|
|||
QString Any::present() const {
|
||||
QString members_content;
|
||||
for (auto& it : children()) {
|
||||
members_content += it->present() + u8"|";
|
||||
members_content += it->present() + "|";
|
||||
}
|
||||
return members_content.mid(0, members_content.size() - 1);
|
||||
}
|
||||
|
||||
QList<QString> lib_syntax::Any::invokeSegments(const QString& in_cursor_name, const QString& out_list_name) const {
|
||||
QList<QString> lines;
|
||||
|
||||
lines << QString(u8"if (%1->mustStop())").arg(in_cursor_name);
|
||||
lines << QString(u8" return QList<std::shared_ptr<const MatchCursor>>() << %1; ").arg(in_cursor_name);
|
||||
|
||||
lines << QString(u8"QList<std::shared_ptr<const MatchCursor>> result_list_%1;").arg((uint64_t) this);
|
||||
for (auto rule : children()) {
|
||||
auto segments = rule->invokeSegments(in_cursor_name, QString(u8"result_list_%1").arg((uint64_t) this));
|
||||
if (segments.size() == 1) {
|
||||
lines.append(segments);
|
||||
}
|
||||
else {
|
||||
lines << u8"{";
|
||||
lines.append(segments);
|
||||
lines << u8"}";
|
||||
}
|
||||
}
|
||||
lines << QString(u8"%2 = result_list_%1;").arg((uint64_t) this).arg(out_list_name);
|
||||
}
|
||||
|
||||
QString lib_syntax::Any::implementSegments(const QString& in_cursor_name, QList<QString>& lines) const {
|
||||
return QString();
|
||||
}
|
||||
|
||||
Seqs::Seqs(const QList<std::shared_ptr<const IBasicRule>> mbrs) : mbrs_store(mbrs) { }
|
||||
|
||||
QList<std::shared_ptr<const IBasicRule>> Seqs::children() const {
|
||||
|
|
@ -96,28 +71,6 @@ QString Seqs::present() const {
|
|||
return content.mid(0, content.size() - 1);
|
||||
}
|
||||
|
||||
QList<QString> lib_syntax::Seqs::invokeSegments(const QString& in_cursor_name, const QString& out_list_name) const {
|
||||
QList<QString> lines;
|
||||
|
||||
lines << QString(u8"if (%1->mustStop())").arg(in_cursor_name);
|
||||
lines << QString(u8" return QList<std::shared_ptr<const MatchCursor>>() << %1; ").arg(in_cursor_name);
|
||||
|
||||
int times = 0;
|
||||
lines << QString(u8"QList<std::shared_ptr<const MatchCursor>> bridge_list{ %1 };").arg(in_cursor_name);
|
||||
for (auto rule : children()) {
|
||||
auto segments = rule->invokeSegments(in_cursor_name, QString(u8"result_list_%1").arg((uint64_t) this));
|
||||
if (segments.size() == 1) {
|
||||
lines.append(segments);
|
||||
}
|
||||
else {
|
||||
lines << u8"{";
|
||||
lines.append(segments);
|
||||
lines << u8"}";
|
||||
}
|
||||
}
|
||||
lines << QString(u8"%2 = result_list_%1;").arg((uint64_t) this).arg(out_list_name);
|
||||
}
|
||||
|
||||
Rept::Rept(std::shared_ptr<const IBasicRule> rule, int min, int max)
|
||||
: rule_peer(rule), min_match(min), max_match(max) { }
|
||||
|
||||
|
|
@ -131,11 +84,11 @@ QList<std::shared_ptr<const MatchCursor>> Rept::parse(std::shared_ptr<const Matc
|
|||
|
||||
QList<std::shared_ptr<const MatchCursor>> results;
|
||||
QList<std::shared_ptr<const MatchCursor>> bridge_list{ cursor };
|
||||
// 最小重复次数匹配
|
||||
// 最小重复次数匹配
|
||||
for (auto idx = 0; idx < min_match; ++idx) {
|
||||
QList<std::shared_ptr<const MatchCursor>> current_list;
|
||||
|
||||
// 迭代每一次可能匹配
|
||||
// 迭代每一次可能匹配
|
||||
std::for_each(bridge_list.begin(), bridge_list.end(),
|
||||
[&](std::shared_ptr<const MatchCursor> curs) {
|
||||
if (curs->mustStop())
|
||||
|
|
@ -148,31 +101,31 @@ QList<std::shared_ptr<const MatchCursor>> Rept::parse(std::shared_ptr<const Matc
|
|||
bridge_list = current_list;
|
||||
}
|
||||
|
||||
// 归并失败分支
|
||||
// 归并失败分支
|
||||
std::copy_if(bridge_list.begin(), bridge_list.end(), std::back_inserter(results),
|
||||
[&](std::shared_ptr<const MatchCursor> ins) { return ins->mustStop(); });
|
||||
|
||||
// 清除匹配失败分支
|
||||
// 清除匹配失败分支
|
||||
for (auto idx = 0; idx < bridge_list.size(); ++idx)
|
||||
if (bridge_list.at(idx)->mustStop())
|
||||
bridge_list.removeAt(idx--);
|
||||
|
||||
// 不满足最小匹配
|
||||
// 不满足最小匹配
|
||||
if (!bridge_list.size())
|
||||
return results;
|
||||
|
||||
|
||||
// 尝试重复匹配最大次数
|
||||
// 尝试重复匹配最大次数
|
||||
for (auto idx = min_match; idx < max_match; ++idx) {
|
||||
QList<std::shared_ptr<const MatchCursor>> current_list;
|
||||
|
||||
// 匹配迭代一次
|
||||
// 匹配迭代一次
|
||||
std::for_each(bridge_list.begin(), bridge_list.end(),
|
||||
[&](std::shared_ptr<const MatchCursor> ins) {
|
||||
current_list.append(this->rule_peer->parse(ins));
|
||||
});
|
||||
|
||||
// 移除失败分支
|
||||
// 移除失败分支
|
||||
for (auto idx = 0; idx < current_list.size(); ++idx) {
|
||||
auto rst_branch = current_list.at(idx);
|
||||
if (rst_branch->mustStop() && rst_branch->currentWords()) {
|
||||
|
|
@ -197,13 +150,13 @@ QList<std::shared_ptr<const MatchCursor>> Rept::parse(std::shared_ptr<const Matc
|
|||
|
||||
QString Rept::present() const {
|
||||
if (min_match == 0 && max_match == INT_MAX)
|
||||
return u8"(" + this->rule_peer->present() + QString(u8")*");
|
||||
return "(" + this->rule_peer->present() + QString(")*");
|
||||
else if (min_match == 1 && max_match == INT_MAX)
|
||||
return u8"(" + this->rule_peer->present() + QString(u8")+");
|
||||
return "(" + this->rule_peer->present() + QString(")+");
|
||||
else if (min_match == 0 && max_match == 1)
|
||||
return u8"(" + this->rule_peer->present() + QString(u8")?");
|
||||
return "(" + this->rule_peer->present() + QString(")?");
|
||||
|
||||
return u8"(" + this->rule_peer->present() + QString(u8"){%1, %2}").arg(min_match).arg(max_match);
|
||||
return "(" + this->rule_peer->present() + QString("){%1, %2}").arg(min_match).arg(max_match);
|
||||
}
|
||||
|
||||
SyntaxException::SyntaxException(const QString& message) {
|
||||
|
|
@ -217,12 +170,6 @@ QString SyntaxException::message() const {
|
|||
ExprRule::ExprRule(const QString& rule_name, int expr_mark)
|
||||
: name_store(rule_name), mark_store(expr_mark) { }
|
||||
|
||||
std::shared_ptr<const ExprRule> ExprRule::reloadRule(std::shared_ptr<const IBasicRule> rule) const {
|
||||
auto ninst = this->make_copy();
|
||||
ninst->child_store = rule;
|
||||
return ninst;
|
||||
}
|
||||
|
||||
QString ExprRule::name() const {
|
||||
return name_store;
|
||||
}
|
||||
|
|
@ -231,62 +178,7 @@ int ExprRule::typeMark() const {
|
|||
return this->mark_store;
|
||||
}
|
||||
|
||||
QList<std::shared_ptr<const IBasicRule>> ExprRule::children() const {
|
||||
return QList<std::shared_ptr<const IBasicRule>>() << this->child_store;
|
||||
}
|
||||
|
||||
#include <ast_novel.h>
|
||||
QString ExprRule::present() const {
|
||||
return child_store->present();
|
||||
}
|
||||
|
||||
QList<QString> lib_syntax::ExprRule::invokeSegments(const QString& in_cursor_name, const QString& out_list_name) const {
|
||||
return QList<QString>() << QString(u8"%1=exprs_%2(%3); //%4")
|
||||
.arg(out_list_name).arg((uint64_t) this).arg(in_cursor_name).arg(name());
|
||||
}
|
||||
|
||||
QString lib_syntax::ExprRule::implementSegments(const QString& in_cursor_name, QList<QString>& lines) const {
|
||||
lines << u8"if (" + in_cursor_name + "->mustStop())";
|
||||
lines << u8" return QList<std::shared_ptr<const MatchCursor>>() << " + in_cursor_name + ";";
|
||||
lines << u8"auto t_this = " + in_cursor_name + "->currentToken();";
|
||||
lines << u8"auto w_this = " + in_cursor_name + "->currentWords();";
|
||||
lines << u8"auto split_begin = std::make_shared<lib_token::ExprBeginToken<ExprType>>(shared_from_this(), t_this);";
|
||||
lines << u8"auto ncursor = std::make_shared<MatchCursor>(" + in_cursor_name + ");";
|
||||
lines << u8"ncursor->setCurrent(split_begin, w_this);";
|
||||
lines << u8"ncursor->enterExprs();";
|
||||
lines << u8"auto nbranch = this->child_store->parse(ncursor);";
|
||||
lines << u8"decltype(nbranch) list_ok;";
|
||||
lines << u8"// 选择完全匹配成功的";
|
||||
lines << u8"std::copy_if(nbranch.begin(), nbranch.end(), std::back_inserter(list_ok),"
|
||||
"[](std::shared_ptr<const MatchCursor> ins) { return !ins->exprsErrorCount(); });";
|
||||
lines << u8"if (!list_ok.size()) {";
|
||||
lines << u8" // 选择被修正的";
|
||||
lines << u8" std::copy_if(nbranch.begin(), nbranch.end(), std::back_inserter(list_ok),"
|
||||
"[](std::shared_ptr<const MatchCursor> ins) { return !ins->mustStop(); });";
|
||||
lines << u8" // 匹配失败的";
|
||||
lines << u8" if (!list_ok.size())";
|
||||
lines << u8" list_ok = nbranch;";
|
||||
lines << u8"}";
|
||||
lines << u8"decltype(list_ok) branch_procs;";
|
||||
lines << u8"std::for_each(list_ok.begin(), list_ok.end(), [&](std::shared_ptr<const MatchCursor> curs) {";
|
||||
lines << u8" if (curs->mustStop()) {";
|
||||
lines << u8" branch_procs.append(curs);";
|
||||
lines << u8" }";
|
||||
lines << u8" else {";
|
||||
lines << u8" auto t_end = curs->currentToken();";
|
||||
lines << u8" auto w_end = curs->currentWords();";
|
||||
lines << u8" auto ecursor = std::make_shared<MatchCursor>(curs);";
|
||||
lines << u8" ecursor->quitExprs();";
|
||||
lines << u8" auto split_end = std::make_shared<lib_token::ExprEndToken<ExprType>>(split_begin, t_end);";
|
||||
lines << u8" ecursor->setCurrent(split_end, w_end);";
|
||||
lines << u8" branch_procs.append(ecursor);";
|
||||
lines << u8" }";
|
||||
lines << u8"});";
|
||||
lines << u8"return branch_procs;";
|
||||
|
||||
return QString(u8"exprs_%1").arg((uint64_t) this);
|
||||
}
|
||||
|
||||
MatchCursor::MatchCursor(const QString& path) :_file_path(path) { }
|
||||
|
||||
MatchCursor::MatchCursor(std::shared_ptr<const MatchCursor> other_ptr)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
namespace lib_syntax {
|
||||
/**
|
||||
* @brief 语法异常
|
||||
* @brief 语法异常
|
||||
*/
|
||||
class LIBSYNTAX_EXPORT SyntaxException {
|
||||
private:
|
||||
|
|
@ -28,9 +28,9 @@ namespace lib_syntax {
|
|||
|
||||
|
||||
|
||||
// 基础语法解析接口 ====================================================================================
|
||||
// 基础语法解析接口 ====================================================================================
|
||||
/**
|
||||
* @brief 解析上下文接口
|
||||
* @brief 解析上下文接口
|
||||
*/
|
||||
class LIBSYNTAX_EXPORT MatchCursor {
|
||||
public:
|
||||
|
|
@ -68,64 +68,43 @@ namespace lib_syntax {
|
|||
QString _file_path;
|
||||
std::shared_ptr<const MatchCursor> _prev_cursor = nullptr;
|
||||
|
||||
QList<QString> _total_errors; // 所有解析错误
|
||||
QList<std::shared_ptr<ErrsPack>> _exprs_errors; // 当前表达式解析错误
|
||||
std::shared_ptr<const lib_token::IActionToken> _current_token = nullptr; // 当前Token
|
||||
std::shared_ptr<const lib_words::IPrimitiveWord> _remains_word = nullptr; // 剩余词语
|
||||
QList<QString> _total_errors; // 所有解析错误
|
||||
QList<std::shared_ptr<ErrsPack>> _exprs_errors; // 当前表达式解析错误
|
||||
std::shared_ptr<const lib_token::IActionToken> _current_token = nullptr; // 当前Token
|
||||
std::shared_ptr<const lib_words::IPrimitiveWord> _remains_word = nullptr; // 剩余词语
|
||||
|
||||
bool parse_stop() const;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 基础语法匹配规则接口
|
||||
* @brief 基础语法匹配规则接口
|
||||
*/
|
||||
class IBasicRule {
|
||||
public:
|
||||
/**
|
||||
* 返回匹配语法规则的词法序列表达
|
||||
*
|
||||
* \return 词法表达序列
|
||||
*/
|
||||
virtual QString present() const = 0;
|
||||
|
||||
/**
|
||||
* @brief 解析
|
||||
* @param cursor 解析游标
|
||||
* @return 返回结果<匹配分支>
|
||||
*/
|
||||
virtual QList<std::shared_ptr<const MatchCursor>> parse(std::shared_ptr<const MatchCursor> cursor) const = 0;
|
||||
|
||||
/**
|
||||
* @brief 子规则
|
||||
* @brief 子规则
|
||||
* @return
|
||||
*/
|
||||
virtual QList<std::shared_ptr<const IBasicRule>> children() const = 0;
|
||||
|
||||
/**
|
||||
* @brief 翻译此规则
|
||||
* @param in_cursor_name 指定输入cursor名称
|
||||
* @param out_list_name 指定输出list名称
|
||||
*
|
||||
*
|
||||
* out_list_name = element_xxxxxx(in_cursor_name);
|
||||
* ……
|
||||
* @return 返回执行语句段
|
||||
*/
|
||||
virtual QList<QString> invokeSegments(const QString& in_cursor_name, const QString& out_list_name) const = 0;
|
||||
* 返回匹配语法规则的词法序列表达
|
||||
*
|
||||
* \return 词法表达序列
|
||||
*/
|
||||
virtual QString present() const = 0;
|
||||
|
||||
/**
|
||||
* @brief 定义和实现语句
|
||||
* @param in_cursor_name 输入
|
||||
* @param lines 规则实现语句
|
||||
*
|
||||
* @return 表达式规则名称
|
||||
*/
|
||||
virtual QString implementSegments(const QString& in_cursor_name, QList<QString>& lines) const = 0;
|
||||
* @brief 解析
|
||||
* @param cursor 解析游标
|
||||
* @return 返回结果<匹配分支>
|
||||
*/
|
||||
virtual QList<std::shared_ptr<const MatchCursor>> parse(std::shared_ptr<const MatchCursor> cursor) const = 0;
|
||||
};
|
||||
|
||||
// 组合语法实体解析 =====================================================================================
|
||||
// 组合语法实体解析 =====================================================================================
|
||||
/**
|
||||
* @brief 语法规则或匹配
|
||||
* @brief 语法规则或匹配
|
||||
*/
|
||||
class LIBSYNTAX_EXPORT Any : public IBasicRule, public std::enable_shared_from_this<Any> {
|
||||
private:
|
||||
|
|
@ -139,13 +118,10 @@ namespace lib_syntax {
|
|||
virtual QList<std::shared_ptr<const IBasicRule>> children() const override;
|
||||
virtual QList<std::shared_ptr<const MatchCursor>> parse(std::shared_ptr<const MatchCursor> cursor) const override;
|
||||
virtual QString present() const override;
|
||||
|
||||
virtual QList<QString> invokeSegments(const QString& in_cursor_name, const QString& out_list_name) const override;
|
||||
virtual QString implementSegments(const QString& in_cursor_name, QList<QString>& lines) const override;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 语法规则序列匹配
|
||||
* @brief 语法规则序列匹配
|
||||
*/
|
||||
class LIBSYNTAX_EXPORT Seqs : public IBasicRule, public std::enable_shared_from_this<Seqs> {
|
||||
private:
|
||||
|
|
@ -159,13 +135,10 @@ namespace lib_syntax {
|
|||
virtual QList<std::shared_ptr<const IBasicRule>> children() const override;
|
||||
virtual QList<std::shared_ptr<const MatchCursor>> parse(std::shared_ptr<const MatchCursor> cursor) const override;
|
||||
virtual QString present() const override;
|
||||
|
||||
virtual QList<QString> invokeSegments(const QString& in_cursor_name, const QString& out_list_name) const override;
|
||||
virtual QString implementSegments(const QString& in_cursor_name, QList<QString>& lines) const override;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 语法规则重复匹配
|
||||
* @brief 语法规则重复匹配
|
||||
*/
|
||||
class LIBSYNTAX_EXPORT Rept : public IBasicRule, public std::enable_shared_from_this<Rept> {
|
||||
private:
|
||||
|
|
@ -183,7 +156,7 @@ namespace lib_syntax {
|
|||
};
|
||||
|
||||
/**
|
||||
* @brief 对应语法表达式解析规则
|
||||
* @brief 对应语法表达式解析规则
|
||||
*/
|
||||
class LIBSYNTAX_EXPORT ExprRule : public IBasicRule, public std::enable_shared_from_this<ExprRule> {
|
||||
public:
|
||||
|
|
@ -191,18 +164,9 @@ namespace lib_syntax {
|
|||
|
||||
virtual QString name() const;
|
||||
virtual int typeMark() const;
|
||||
virtual std::shared_ptr<const ExprRule> reloadRule(std::shared_ptr<const IBasicRule> rule) const;
|
||||
|
||||
// IBasicRule interface
|
||||
public:
|
||||
virtual QList<std::shared_ptr<const IBasicRule>> children() const override;
|
||||
virtual QString present() const override;
|
||||
virtual QList<QString> invokeSegments(const QString& in_cursor_name, const QString& out_list_name) const override;
|
||||
virtual QString implementSegments(const QString& in_cursor_name, QList<QString> &lines) const override;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<const IBasicRule> child_store;
|
||||
virtual std::shared_ptr<ExprRule> make_copy() const = 0;
|
||||
virtual QList<std::shared_ptr<const MatchCursor>> expr_rule_parse(std::shared_ptr<const MatchCursor> cursor) const = 0;
|
||||
|
||||
private:
|
||||
QString name_store;
|
||||
|
|
@ -212,10 +176,11 @@ namespace lib_syntax {
|
|||
|
||||
|
||||
/**
|
||||
* @brief token匹配
|
||||
* @brief token匹配
|
||||
*/
|
||||
template<typename T, lib_token::TokenProcs<T> XProc = nullptr>
|
||||
class TokenMatch : public IBasicRule, public std::enable_shared_from_this<TokenMatch<T, XProc>> {
|
||||
template<typename ELEM, lib_token::TokenProcs<ELEM> XProc = nullptr>
|
||||
requires std::derived_from<ELEM, ast_basic::IExprInstance>
|
||||
class TokenMatch : public IBasicRule, public std::enable_shared_from_this<TokenMatch<ELEM, XProc>> {
|
||||
private:
|
||||
std::shared_ptr<const lib_token::ITokenProcess> _define_peers;
|
||||
|
||||
|
|
@ -225,15 +190,15 @@ namespace lib_syntax {
|
|||
// IBasicRule interface
|
||||
public:
|
||||
virtual QString present() const override {
|
||||
return QString(u8"%1").arg(this->_define_peers->reviseWords());
|
||||
return QString("%1").arg(this->_define_peers->reviseWords());
|
||||
}
|
||||
virtual QList<std::shared_ptr<const MatchCursor>> parse(std::shared_ptr<const MatchCursor> current) const override {
|
||||
auto w_this = current->currentWords();
|
||||
if (!w_this) {
|
||||
auto clone_ins = std::make_shared<MatchCursor>(current);
|
||||
clone_ins->logExprsError(QString(u8"Syntax[0x00001]语法匹配错误,缺失\"%1\"<file<%2>>")
|
||||
clone_ins->logExprsError(QString("Syntax[0x00001]语法匹配错误,缺失\"%1\"<file<%2>>")
|
||||
.arg(this->_define_peers->reviseWords()).arg(current->filePath()));
|
||||
clone_ins->logExprsError(QString(u8"Syntax[0x00001]输入流提前结束,<%1>").arg(current->filePath()));
|
||||
clone_ins->logExprsError(QString("Syntax[0x00001]输入流提前结束,<%1>").arg(current->filePath()));
|
||||
return QList<std::shared_ptr<const MatchCursor>>() << clone_ins;
|
||||
}
|
||||
|
||||
|
|
@ -242,7 +207,7 @@ namespace lib_syntax {
|
|||
|
||||
auto match_result = _define_peers->analysis(w_this);
|
||||
if (std::get<0>(match_result)) {
|
||||
auto chain = std::make_shared<lib_token::ActionToken<T, XProc>>(std::get<0>(match_result), t_this);
|
||||
auto chain = std::make_shared<lib_token::ActionToken<ELEM, XProc>>(std::get<0>(match_result), t_this);
|
||||
auto remains = w_this->nextWord();
|
||||
if (std::get<1>(match_result)) {
|
||||
remains = std::make_shared<lib_words::WordImpl>(std::get<1>(match_result), remains);
|
||||
|
|
@ -254,42 +219,42 @@ namespace lib_syntax {
|
|||
}
|
||||
else {
|
||||
QList<std::shared_ptr<const MatchCursor>> retvals;
|
||||
// 少一个
|
||||
// 少一个
|
||||
{
|
||||
auto short_one = std::make_shared<MatchCursor>(current);
|
||||
short_one->logExprsError(QString(u8"Syntax[0x00001]语法匹配错误,缺失\"%1\"<row:%2,col:%3,file<%4>>")
|
||||
short_one->logExprsError(QString("Syntax[0x00001]语法匹配错误,缺失\"%1\"<row:%2,col:%3,file<%4>>")
|
||||
.arg(this->_define_peers->reviseWords())
|
||||
.arg(w_this->row()).arg(w_this->column()).arg(w_this->file()));
|
||||
retvals << short_one;
|
||||
}
|
||||
|
||||
// 错一个
|
||||
// 错一个
|
||||
{
|
||||
auto error_one = std::make_shared<MatchCursor>(current);
|
||||
error_one->logExprsError(QString(u8"Syntax[0x00001]语法匹配错误,请修正\"%1\"<row:%2,col:%3,file<%4>>")
|
||||
error_one->logExprsError(QString("Syntax[0x00001]语法匹配错误,请修正\"%1\"<row:%2,col:%3,file<%4>>")
|
||||
.arg(w_this->content()).arg(w_this->row()).arg(w_this->column()).arg(w_this->file()));
|
||||
auto tkins = std::make_shared<lib_token::TokenContent>(
|
||||
w_this->row(), w_this->column(), w_this->position(),
|
||||
QString(u8"%2_%1").arg((uint64_t) error_one.get()).arg(this->_define_peers->reviseWords()),
|
||||
QString("%2_%1").arg((uint64_t) error_one.get()).arg(this->_define_peers->reviseWords()),
|
||||
w_this->file(), this->_define_peers);
|
||||
auto tkchain = std::make_shared<lib_token::ActionToken<T, XProc>>(tkins, t_this);
|
||||
auto tkchain = std::make_shared<lib_token::ActionToken<ELEM, XProc>>(tkins, t_this);
|
||||
error_one->setCurrent(tkchain, w_this->nextWord());
|
||||
retvals << error_one;
|
||||
}
|
||||
|
||||
// 多一个
|
||||
// 多一个
|
||||
if (w_this->nextWord()) {
|
||||
auto nx_word = w_this->nextWord();
|
||||
auto nx_result = this->_define_peers->analysis(nx_word);
|
||||
if (std::get<0>(nx_result)) {
|
||||
auto chain = std::make_shared<lib_token::ActionToken<T, XProc>>(std::get<0>(nx_result), t_this);
|
||||
auto chain = std::make_shared<lib_token::ActionToken<ELEM, XProc>>(std::get<0>(nx_result), t_this);
|
||||
auto remains = nx_word->nextWord();
|
||||
if (std::get<1>(nx_result)) {
|
||||
remains = std::make_shared<lib_words::WordImpl>(std::get<1>(nx_result), remains);
|
||||
}
|
||||
|
||||
auto clone_ins = std::make_shared<MatchCursor>(current);
|
||||
clone_ins->logExprsError(QString(u8"Syntax[0x00001]语法匹配错误,请删除\"%1\"<row:%2,col:%3,file<%4>>")
|
||||
clone_ins->logExprsError(QString("Syntax[0x00001]语法匹配错误,请删除\"%1\"<row:%2,col:%3,file<%4>>")
|
||||
.arg(w_this->content()).arg(w_this->row()).arg(w_this->column()).arg(w_this->file()));
|
||||
clone_ins->setCurrent(chain, remains);
|
||||
retvals << clone_ins;
|
||||
|
|
@ -305,12 +270,20 @@ namespace lib_syntax {
|
|||
};
|
||||
|
||||
/**
|
||||
* 语法元素解析规则.
|
||||
* @brief 基础模板化语法元素解析规则.
|
||||
*/
|
||||
template<class ExprType> class ElementRule : public ExprRule {
|
||||
template<class ExprType, int mark> class ElementRule : public ExprRule {
|
||||
public:
|
||||
ElementRule(const QString& rule_name, int expr_mark)
|
||||
:ExprRule(rule_name, expr_mark) { }
|
||||
ElementRule(const QString& rule_name, std::shared_ptr<const IBasicRule> children)
|
||||
:ExprRule(rule_name, mark), _children_store(children) { }
|
||||
|
||||
virtual QList<std::shared_ptr<const IBasicRule>> children() const {
|
||||
return QList<std::shared_ptr<const IBasicRule>>() << this->_children_store;
|
||||
}
|
||||
|
||||
virtual QString present() const {
|
||||
return this->_children_store->present();
|
||||
}
|
||||
|
||||
virtual QList<std::shared_ptr<const MatchCursor>> parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
||||
if (cursor->mustStop())
|
||||
|
|
@ -324,16 +297,16 @@ namespace lib_syntax {
|
|||
ncursor->setCurrent(split_begin, w_this);
|
||||
ncursor->enterExprs();
|
||||
|
||||
auto nbranch = this->child_store->parse(ncursor);
|
||||
auto nbranch = this->expr_rule_parse(ncursor);
|
||||
decltype(nbranch) list_ok;
|
||||
// 选择完全匹配成功的
|
||||
// 选择完全匹配成功的
|
||||
std::copy_if(nbranch.begin(), nbranch.end(), std::back_inserter(list_ok),
|
||||
[](std::shared_ptr<const MatchCursor> ins) { return !ins->exprsErrorCount(); });
|
||||
if (!list_ok.size()) {
|
||||
// 选择被修正的
|
||||
// 选择被修正的
|
||||
std::copy_if(nbranch.begin(), nbranch.end(), std::back_inserter(list_ok),
|
||||
[](std::shared_ptr<const MatchCursor> ins) { return !ins->mustStop(); });
|
||||
// 匹配失败的
|
||||
// 匹配失败的
|
||||
if (!list_ok.size())
|
||||
list_ok = nbranch;
|
||||
}
|
||||
|
|
@ -354,14 +327,12 @@ namespace lib_syntax {
|
|||
ecursor->setCurrent(split_end, w_end);
|
||||
branch_procs.append(ecursor);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return branch_procs;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual std::shared_ptr<ExprRule> make_copy() const {
|
||||
return std::make_shared<ElementRule<ExprType>>(this->name(), this->typeMark());
|
||||
}
|
||||
std::shared_ptr<const IBasicRule> _children_store;
|
||||
};
|
||||
} // namespace lib_syntax
|
||||
|
|
@ -10,7 +10,7 @@ namespace ast_basic {
|
|||
namespace lib_token {
|
||||
|
||||
/**
|
||||
* @brief 解析异常
|
||||
* @brief 解析异常
|
||||
*/
|
||||
class LIBSYNTAX_EXPORT TokenException {
|
||||
private:
|
||||
|
|
@ -26,53 +26,53 @@ namespace lib_token {
|
|||
|
||||
|
||||
|
||||
// token 解析机制抽象接口==========================================
|
||||
// token 解析机制抽象接口==========================================
|
||||
/**
|
||||
* @brief token类型定义
|
||||
* @brief token类型定义
|
||||
*/
|
||||
class ITokenDefine {
|
||||
public:
|
||||
/**
|
||||
* @brief 整数类型标识.
|
||||
* @brief 整数类型标识.
|
||||
*
|
||||
* \return
|
||||
*/
|
||||
virtual int typeMark() const = 0;
|
||||
/**
|
||||
* @brief 解析机制关键定义
|
||||
* @brief 解析机制关键定义
|
||||
* @return
|
||||
*/
|
||||
virtual QString regex() const = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief token解析结果
|
||||
* @brief token解析结果
|
||||
*/
|
||||
class IToken : public lib_words::IWordBase, public std::enable_shared_from_this<IToken> {
|
||||
public:
|
||||
/**
|
||||
* @brief token解析机制关联
|
||||
* @brief token解析机制关联
|
||||
* @return
|
||||
*/
|
||||
virtual std::shared_ptr<const ITokenDefine> defines() const = 0;
|
||||
};
|
||||
|
||||
|
||||
// 拓展基础接口=========================
|
||||
// 拓展基础接口=========================
|
||||
/**
|
||||
* @brief token解析机制定义
|
||||
* @brief token解析机制定义
|
||||
*/
|
||||
class ITokenProcess : public ITokenDefine {
|
||||
public:
|
||||
/**
|
||||
* @brief 解析机制名称
|
||||
* @brief 解析机制名称
|
||||
* @return
|
||||
*/
|
||||
virtual QString reviseWords() const = 0;
|
||||
/**
|
||||
* @brief 解析词语处理过程
|
||||
* @param content 词语
|
||||
* @return tuple<token/null,remains> 解析结果
|
||||
* @brief 解析词语处理过程
|
||||
* @param content 词语
|
||||
* @return tuple<token/null,remains> 解析结果
|
||||
*/
|
||||
virtual std::tuple<std::shared_ptr<const IToken>, std::shared_ptr<const lib_words::IPrimitiveWord>>
|
||||
analysis(std::shared_ptr<const lib_words::IPrimitiveWord> content) const = 0;
|
||||
|
|
@ -80,20 +80,20 @@ namespace lib_token {
|
|||
|
||||
|
||||
/**
|
||||
* @brief 动作Token
|
||||
* @brief 动作Token
|
||||
*/
|
||||
class IActionToken : public lib_token::IToken {
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief 上一个Token
|
||||
* @brief 上一个Token
|
||||
* @return
|
||||
*/
|
||||
virtual std::shared_ptr<const IActionToken> prevToken() const = 0;
|
||||
/**
|
||||
* @brief 落实本Token内容到指定expr,返回完善状态后的expr
|
||||
* @param expr 目标表达式实例
|
||||
* @return 完善后的表达式
|
||||
* @brief 落实本Token内容到指定expr,返回完善状态后的expr
|
||||
* @param expr 目标表达式实例
|
||||
* @return 完善后的表达式
|
||||
*/
|
||||
virtual std::shared_ptr<ast_basic::IExprInstance> makeSure(std::shared_ptr<ast_basic::IExprInstance> expr) = 0;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -14,13 +14,13 @@ auto refers = std::make_shared<ReferMark>(); // @
|
|||
auto declare = std::make_shared<DeclareSymbo>(); // #
|
||||
auto split_mark = std::make_shared<Split>(); // &
|
||||
|
||||
auto rank_key = std::make_shared<Keywords>(u8"排序", 0xAEu); // 排序
|
||||
auto story_key = std::make_shared<Keywords>(u8"故事", 0xAAu); // 故事
|
||||
auto rank_key = std::make_shared<Keywords>("排序", 0xAEu); // 排序
|
||||
auto story_key = std::make_shared<Keywords>("故事", 0xAAu); // 故事
|
||||
auto numbers = std::make_shared<Numbers>(); // [0-9]+
|
||||
auto slice_key = std::make_shared<Keywords>(u8"剧情", 0xAFu); // 剧情
|
||||
auto point_key = std::make_shared<Keywords>(u8"节点", 0xABu); // 节点
|
||||
auto volume_key = std::make_shared<Keywords>(u8"分卷", 0xACu); // 分卷
|
||||
auto article_key = std::make_shared<Keywords>(u8"章节", 0xADu); // 章节
|
||||
auto slice_key = std::make_shared<Keywords>("剧情", 0xAFu); // 剧情
|
||||
auto point_key = std::make_shared<Keywords>("节点", 0xABu); // 节点
|
||||
auto volume_key = std::make_shared<Keywords>("分卷", 0xACu); // 分卷
|
||||
auto article_key = std::make_shared<Keywords>("章节", 0xADu); // 章节
|
||||
auto vtext = std::make_shared<VTextSection>(); // ^([^\\{\\}@&]+)
|
||||
auto name_text = std::make_shared<NameSection>(); // ^([^\\{\\}@&]+)
|
||||
|
||||
|
|
@ -32,6 +32,8 @@ void apntk(std::shared_ptr<ExprT> expr, std::shared_ptr<const lib_token::IToken>
|
|||
expr->addToken(t);
|
||||
}
|
||||
|
||||
// MakeRule
|
||||
#define MK(type) std::make_shared<const type>()
|
||||
// MatchRule
|
||||
#define MER(E, XProc, t) std::make_shared<const TokenMatch<E, XProc>>(t)
|
||||
#define MR(E, t) MER(E, apntk<E>, t)
|
||||
|
|
@ -47,22 +49,42 @@ void apntk(std::shared_ptr<ExprT> expr, std::shared_ptr<const lib_token::IToken>
|
|||
|
||||
|
||||
|
||||
auto decl_expr = ElementRule<TextSection>(u8"decl_section", (int) NovelNode::TextSection).reloadRule(
|
||||
MultiR(std::make_shared<const Any>(Rules{
|
||||
MR(TextSection, numbers), MR(TextSection, vtext), MR(TextSection, refers), MR(TextSection, split_mark)
|
||||
}))
|
||||
);
|
||||
class DeclExpr : public ElementRule<TextSection, (int) NovelNode::TextSection> {
|
||||
public:
|
||||
DeclExpr() : ElementRule<TextSection, (int) NovelNode::TextSection>(
|
||||
"decl_section",
|
||||
MultiR(std::make_shared<const Any>(Rules{
|
||||
MR(TextSection, numbers), MR(TextSection, vtext), MR(TextSection, refers), MR(TextSection, split_mark)
|
||||
}))) { }
|
||||
|
||||
// 通过 ElementRule 继承
|
||||
QList<std::shared_ptr<const MatchCursor>> expr_rule_parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
||||
return _children_store->parse(cursor);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
void point_nmset(std::shared_ptr<PointDefines> inst, std::shared_ptr<const lib_token::IToken> token) {
|
||||
inst->addToken(token);
|
||||
inst->setName(token->content());
|
||||
}
|
||||
auto point_decl = ElementRule<PointDefines>(u8"point_define", (int) NovelNode::PointDefines).reloadRule(
|
||||
std::make_shared<const Seqs>(Rules{
|
||||
MR(PointDefines, leftb), MR(PointDefines, point_key), MER(PointDefines, point_nmset, name_text) } <<
|
||||
OptR(decl_expr) <<
|
||||
MR(PointDefines, rightb)
|
||||
));
|
||||
class PointSyntax : public ElementRule<PointDefines, (int) NovelNode::PointDefines> {
|
||||
public:
|
||||
PointSyntax() : ElementRule<PointDefines, (int) NovelNode::PointDefines>(
|
||||
"point_define", std::make_shared<const Seqs>(Rules{
|
||||
MR(PointDefines, leftb), MR(PointDefines, point_key), MER(PointDefines, point_nmset, name_text) } <<
|
||||
OptR(MK(DeclExpr)) <<
|
||||
MR(PointDefines, rightb)
|
||||
)) { }
|
||||
|
||||
// 通过 ElementRule 继承
|
||||
QList<std::shared_ptr<const MatchCursor>> expr_rule_parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
||||
return _children_store->parse(cursor);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
void point_ref_story_set(std::shared_ptr<PointRefers> inst, std::shared_ptr<const lib_token::IToken> token) {
|
||||
inst->addToken(token);
|
||||
|
|
@ -76,80 +98,166 @@ void point_ref_point_set(std::shared_ptr<PointRefers> inst, std::shared_ptr<cons
|
|||
inst->addToken(token);
|
||||
inst->setPointRefer(token->content());
|
||||
}
|
||||
auto point_refer = ElementRule<PointRefers>(u8"point_refer", (int) NovelNode::PointRefers).reloadRule(
|
||||
std::make_shared<const Seqs>(Rules{
|
||||
class ReferSyntax : public ElementRule<PointRefers, (int) NovelNode::PointRefers> {
|
||||
public:
|
||||
ReferSyntax() : ElementRule < PointRefers, (int) NovelNode::PointRefers>(
|
||||
"point_refer", std::make_shared<const Seqs>(Rules{
|
||||
MR(PointRefers, leftb), MR(PointRefers, refers), MR(PointRefers, point_key),
|
||||
MER(PointRefers, point_ref_story_set, name_text),
|
||||
MR(PointRefers, split_mark),
|
||||
MER(PointRefers, point_ref_slice_set, name_text),
|
||||
MR(PointRefers, split_mark),
|
||||
MER(PointRefers, point_ref_point_set, name_text) } <<
|
||||
OptR(decl_expr) <<
|
||||
MR(PointRefers, rightb)
|
||||
));
|
||||
OptR(MK(DeclExpr)) <<
|
||||
MR(PointRefers, rightb))) { }
|
||||
|
||||
// 通过 ElementRule 继承
|
||||
QList<std::shared_ptr<const MatchCursor>> expr_rule_parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
||||
return _children_store->parse(cursor);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
void slice_nm_set(std::shared_ptr<FragmentSlice> inst, std::shared_ptr<const lib_token::IToken> token) {
|
||||
inst->addToken(token);
|
||||
inst->setName(token->content());
|
||||
}
|
||||
auto slice_define = ElementRule<FragmentSlice>(u8"slice_define", (int) NovelNode::FragmentSlice).reloadRule(
|
||||
std::make_shared<const Seqs>(Rules{
|
||||
MR(FragmentSlice, leftb), MR(FragmentSlice, slice_key), MER(FragmentSlice, slice_nm_set, name_text) } <<
|
||||
OptMulR(std::make_shared<const Any>(Rules{ point_decl, point_refer, decl_expr })) <<
|
||||
MR(FragmentSlice, rightb)
|
||||
));
|
||||
class SliceSyntax : public ElementRule<FragmentSlice, (int) NovelNode::FragmentSlice> {
|
||||
public:
|
||||
SliceSyntax() : ElementRule<FragmentSlice, (int) NovelNode::FragmentSlice>(
|
||||
"slice_define", std::make_shared<const Seqs>(Rules{
|
||||
MR(FragmentSlice, leftb), MR(FragmentSlice, slice_key), MER(FragmentSlice, slice_nm_set, name_text) } <<
|
||||
OptMulR(std::make_shared<const Any>(Rules{ MK(PointSyntax), MK(ReferSyntax), MK(DeclExpr) })) <<
|
||||
MR(FragmentSlice, rightb))) { }
|
||||
|
||||
// 通过 ElementRule 继承
|
||||
QList<std::shared_ptr<const MatchCursor>> expr_rule_parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
||||
return _children_store->parse(cursor);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
void story_nmset(std::shared_ptr<StoryDefine> inst, std::shared_ptr<const lib_token::IToken> token) {
|
||||
inst->addToken(token);
|
||||
inst->setName(token->content());
|
||||
}
|
||||
auto story_define = ElementRule<StoryDefine>(u8"story_define", (int) NovelNode::StoryDefine).reloadRule(
|
||||
std::make_shared<const Seqs>(Rules{
|
||||
class StorySyntax : public ElementRule<StoryDefine, (int) NovelNode::StoryDefine> {
|
||||
public:
|
||||
StorySyntax() : ElementRule<StoryDefine, (int) NovelNode::StoryDefine>(
|
||||
"story_define",
|
||||
std::make_shared<const Seqs>(Rules{
|
||||
MR(StoryDefine, leftb), MR(StoryDefine, story_key), MER(StoryDefine, story_nmset, name_text) } <<
|
||||
OptMulR(std::make_shared<const Any>(Rules{ slice_define, decl_expr })) <<
|
||||
MR(StoryDefine, rightb)
|
||||
));
|
||||
// ===================================================================
|
||||
OptMulR(std::make_shared<const Any>(Rules{ MK(SliceSyntax), MK(DeclExpr) })) <<
|
||||
MR(StoryDefine, rightb)
|
||||
)) { }
|
||||
|
||||
// 通过 ElementRule 继承
|
||||
QList<std::shared_ptr<const MatchCursor>> expr_rule_parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
||||
return _children_store->parse(cursor);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
void article_nset(std::shared_ptr<ArticleDefine>inst, std::shared_ptr<const lib_token::IToken> token) {
|
||||
inst->addToken(token);
|
||||
inst->setName(token->content());
|
||||
}
|
||||
auto article_decl = ElementRule<ArticleDefine>(u8"article_define", (int) NovelNode::ArticleDefine).reloadRule(
|
||||
std::make_shared<const Seqs>(Rules{
|
||||
class ArticleSyntax : public ElementRule<ArticleDefine, (int) NovelNode::ArticleDefine> {
|
||||
public:
|
||||
ArticleSyntax() : ElementRule<ArticleDefine, (int) NovelNode::ArticleDefine>(
|
||||
"article_define", std::make_shared<const Seqs>(Rules{
|
||||
MR(ArticleDefine, leftb), MR(ArticleDefine, article_key), MER(ArticleDefine, article_nset, name_text) } <<
|
||||
OptMulR(std::make_shared<const Any>(Rules{ point_refer, decl_expr })) <<
|
||||
MR(ArticleDefine, rightb)
|
||||
));
|
||||
OptMulR(std::make_shared<const Any>(Rules{ MK(ReferSyntax), MK(DeclExpr) })) <<
|
||||
MR(ArticleDefine, rightb)
|
||||
)) { }
|
||||
|
||||
// 通过 ElementRule 继承
|
||||
QList<std::shared_ptr<const MatchCursor>> expr_rule_parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
||||
return _children_store->parse(cursor);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
void volume_nset(std::shared_ptr<VolumeDefine> inst, std::shared_ptr<const lib_token::IToken> token) {
|
||||
inst->addToken(token);
|
||||
inst->setName(token->content());
|
||||
}
|
||||
auto volume_decl = ElementRule<VolumeDefine>(u8"volume_define", (int) NovelNode::VolumeDefine).reloadRule(
|
||||
std::make_shared<const Seqs>(Rules{
|
||||
class VolumeSyntax : public ElementRule<VolumeDefine, (int) NovelNode::VolumeDefine> {
|
||||
public:
|
||||
VolumeSyntax() : ElementRule<VolumeDefine, (int) NovelNode::VolumeDefine>(
|
||||
"volume_define", std::make_shared<const Seqs>(Rules{
|
||||
MR(VolumeDefine, leftb), MR(VolumeDefine, volume_key), MER(VolumeDefine, volume_nset, name_text) } <<
|
||||
OptMulR(std::make_shared<const Any>(Rules{ decl_expr, article_decl })) <<
|
||||
MR(VolumeDefine, rightb)
|
||||
));
|
||||
OptMulR(std::make_shared<const Any>(Rules{ MK(DeclExpr), MK(ArticleSyntax) })) <<
|
||||
MR(VolumeDefine, rightb)
|
||||
)) { }
|
||||
|
||||
// 通过 ElementRule 继承
|
||||
QList<std::shared_ptr<const MatchCursor>> expr_rule_parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
||||
return _children_store->parse(cursor);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
void rank_set(std::shared_ptr<RankDeclare> inst, std::shared_ptr<const lib_token::IToken> token) {
|
||||
inst->addToken(token);
|
||||
inst->setRank(token->content().toInt());
|
||||
}
|
||||
auto rank_define = ElementRule<RankDeclare>(u8"rank_define", (int) NovelNode::RankDeclaration).reloadRule(
|
||||
std::make_shared<const Seqs>(Rules{
|
||||
class RankSyntax : public ElementRule<RankDeclare, (int) NovelNode::RankDeclaration> {
|
||||
public:
|
||||
RankSyntax() : ElementRule<RankDeclare, (int) NovelNode::RankDeclaration>(
|
||||
"rank_define", std::make_shared<const Seqs>(Rules{
|
||||
MR(RankDeclare, declare), MR(RankDeclare, rank_key), MER(RankDeclare, rank_set, numbers) }
|
||||
));
|
||||
)) { }
|
||||
|
||||
auto document_define = ElementRule<Document>(u8"decls-doc", (int) NovelNode::Document).reloadRule(
|
||||
std::make_shared<const Seqs>(
|
||||
Rules{
|
||||
std::make_shared<const Rept>(rank_define, 0, 1),
|
||||
MultiR(std::make_shared<const Any>(Rules{story_define, volume_decl}))
|
||||
// 通过 ElementRule 继承
|
||||
QList<std::shared_ptr<const MatchCursor>> expr_rule_parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
||||
return _children_store->parse(cursor);
|
||||
}
|
||||
));
|
||||
};
|
||||
|
||||
|
||||
|
||||
class DocumentSyntax : public ElementRule<Document, (int) NovelNode::Document> {
|
||||
public:
|
||||
DocumentSyntax() : ElementRule<Document, (int) NovelNode::Document>(
|
||||
"decls-doc", std::make_shared<const Seqs>(Rules{
|
||||
OptR(MK(RankSyntax)), MultiR(std::make_shared<const Any>(Rules{ MK(StorySyntax), MK(VolumeSyntax) }))
|
||||
})) { }
|
||||
|
||||
// 通过 ElementRule 继承
|
||||
QList<std::shared_ptr<const MatchCursor>> expr_rule_parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
||||
return _children_store->parse(cursor);
|
||||
}
|
||||
};
|
||||
|
||||
class MM : public lib_syntax::IBasicRule {
|
||||
// 通过 IBasicRule 继承
|
||||
QList<std::shared_ptr<const IBasicRule>> children() const override {
|
||||
return QList<std::shared_ptr<const IBasicRule>>();
|
||||
}
|
||||
QString present() const override {
|
||||
return QString();
|
||||
}
|
||||
QList<std::shared_ptr<const MatchCursor>> parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
||||
return QList<std::shared_ptr<const MatchCursor>>();
|
||||
}
|
||||
};
|
||||
|
||||
#include "syntax_templets.h"
|
||||
std::shared_ptr<const ExprRule> NovalSyntax::getSyntaxTree() {
|
||||
lib_composit::TypeList<MM, MM> vv;
|
||||
|
||||
return std::make_shared<DocumentSyntax>();
|
||||
}
|
||||
|
||||
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)
|
||||
//{
|
||||
// build_objecttree(root, children);
|
||||
|
|
@ -176,7 +284,7 @@ std::shared_ptr<const ExprRule> NovalSyntax::getSyntaxTree() { return document_d
|
|||
// if (!child->isAnonymous()) {
|
||||
// auto check_result = ast_gen::GlobalElement::UniquePtr->appendToCache(child);
|
||||
// if (check_result)
|
||||
// throw new SyntaxException(QString(u8"SyntaxError[0x0004]系统中包含同类型重名命名节点:%1<type:%2>(%3,%4)")
|
||||
// throw new SyntaxException(QString("SyntaxError[0x0004]系统中包含同类型重名命名节点:%1<type:%2>(%3,%4)")
|
||||
// .arg(child->signature()).arg(child->typeMark()).arg(child->path()).arg(check_result->path()));
|
||||
// }
|
||||
//
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ namespace example_novel {
|
|||
class LIBSYNTAX_EXPORT NovalSyntax {
|
||||
public:
|
||||
/**
|
||||
* @brief 获取novel语法解析树
|
||||
* @brief 获取novel语法解析树
|
||||
* @return
|
||||
*/
|
||||
static std::shared_ptr<const lib_syntax::ExprRule> getSyntaxTree();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,51 @@
|
|||
#pragma once
|
||||
|
||||
#include "libsyntax.h"
|
||||
#include <concepts>
|
||||
|
||||
namespace lib_composit {
|
||||
template<typename... TYPES> class TypeList;
|
||||
|
||||
template<> class TypeList<> {
|
||||
public:
|
||||
static QList<std::shared_ptr<const lib_syntax::IBasicRule>> getRules() {
|
||||
return QList<std::shared_ptr<const lib_syntax::IBasicRule>>();
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, typename... Rets>
|
||||
requires std::derived_from<T, lib_syntax::IBasicRule>
|
||||
class TypeList<T, Rets...> : public TypeList<Rets...> {
|
||||
public:
|
||||
static QList<std::shared_ptr<const lib_syntax::IBasicRule>> getRules() {
|
||||
auto list = TypeList<Rets...>::getRules();
|
||||
list.prepend(std::make_shared<const T>());
|
||||
return list;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename... TYPES>
|
||||
class AnyR : public lib_syntax::Any, public TypeList<TYPES...> {
|
||||
public:
|
||||
AnyR() : Any(TypeList<TYPES...>::getRules()){ }
|
||||
};
|
||||
|
||||
template<typename... TYPES>
|
||||
class SeqsR : public lib_syntax::Seqs, public TypeList<TYPES...> {
|
||||
public:
|
||||
SeqsR() : Seqs(TypeList<TYPES...>::getRules()){ }
|
||||
};
|
||||
|
||||
template<typename TYPE, int min, int max>
|
||||
class ReptR : public lib_syntax::Rept {
|
||||
public:
|
||||
ReptR() : Rept(std::make_shared<TYPE>(), min, max){ }
|
||||
};
|
||||
|
||||
template<typename E, typename T, lib_token::TokenProcs<E> xproc = nullptr>
|
||||
requires std::derived_from<E, ast_basic::IExprInstance> && std::derived_from<T, lib_token::ITokenProcess>
|
||||
class TokenR : public lib_syntax::TokenMatch<E, xproc> {
|
||||
public:
|
||||
TokenR() : TokenMatch<E, xproc>(std::make_shared<T>()){ }
|
||||
};
|
||||
}
|
||||
|
|
@ -9,9 +9,9 @@ namespace lib_token {
|
|||
using TokenProcs = void(*)(std::shared_ptr<ExprT> expr, std::shared_ptr<const lib_token::IToken> t);
|
||||
|
||||
|
||||
// 基础token实现 ===================================================
|
||||
// 基础token实现 ===================================================
|
||||
/**
|
||||
* @brief 词法解析成果
|
||||
* @brief 词法解析成果
|
||||
*/
|
||||
class TokenContent : public IToken {
|
||||
private:
|
||||
|
|
@ -21,13 +21,13 @@ namespace lib_token {
|
|||
|
||||
public:
|
||||
/**
|
||||
* @brief 词法解析内容
|
||||
* @param r 行
|
||||
* @param c 列
|
||||
* @param pos 位置
|
||||
* @param t 内容
|
||||
* @brief 词法解析内容
|
||||
* @param r 行
|
||||
* @param c 列
|
||||
* @param pos 位置
|
||||
* @param t 内容
|
||||
* @param p path
|
||||
* @param paramType 类型定义
|
||||
* @param paramType 类型定义
|
||||
*/
|
||||
TokenContent(int r, int c, uint64_t pos, const QString& t, const QString& p, std::shared_ptr<const ITokenDefine> paramType);
|
||||
|
||||
|
|
@ -46,7 +46,7 @@ namespace lib_token {
|
|||
|
||||
|
||||
/**
|
||||
* @brief 动作Token
|
||||
* @brief 动作Token
|
||||
*/
|
||||
template<typename ExprT, TokenProcs<ExprT> proc>
|
||||
class ActionToken : public IActionToken {
|
||||
|
|
@ -64,7 +64,7 @@ namespace lib_token {
|
|||
return expr;
|
||||
}
|
||||
|
||||
// 通过 IActionToken 继承
|
||||
// 通过 IActionToken 继承
|
||||
QString file() const override {
|
||||
return _bind_content->file();
|
||||
}
|
||||
|
|
@ -89,7 +89,7 @@ namespace lib_token {
|
|||
};
|
||||
|
||||
/**
|
||||
* @brief 表达式起始token
|
||||
* @brief 表达式起始token
|
||||
*/
|
||||
template<typename NExpr> class ExprBeginToken : public IActionToken {
|
||||
private:
|
||||
|
|
@ -107,25 +107,25 @@ namespace lib_token {
|
|||
return this->_parent_expr;
|
||||
}
|
||||
|
||||
// 通过 IActionToken 继承
|
||||
// 通过 IActionToken 继承
|
||||
QString file() const override {
|
||||
throw new lib_token::TokenException(u8"不应该直接访问ExprBeginToken");
|
||||
throw new lib_token::TokenException("不应该直接访问ExprBeginToken");
|
||||
}
|
||||
|
||||
uint64_t position() const override {
|
||||
throw new lib_token::TokenException(u8"不应该直接访问ExprBeginToken");
|
||||
throw new lib_token::TokenException("不应该直接访问ExprBeginToken");
|
||||
}
|
||||
|
||||
QString content() const override {
|
||||
throw new lib_token::TokenException(u8"不应该直接访问ExprBeginToken");
|
||||
throw new lib_token::TokenException("不应该直接访问ExprBeginToken");
|
||||
}
|
||||
|
||||
int row() const override {
|
||||
throw new lib_token::TokenException(u8"不应该直接访问ExprBeginToken");
|
||||
throw new lib_token::TokenException("不应该直接访问ExprBeginToken");
|
||||
}
|
||||
|
||||
int column() const override {
|
||||
throw new lib_token::TokenException(u8"不应该直接访问ExprBeginToken");
|
||||
throw new lib_token::TokenException("不应该直接访问ExprBeginToken");
|
||||
}
|
||||
|
||||
std::shared_ptr<const ITokenDefine> defines() const override {
|
||||
|
|
@ -145,7 +145,7 @@ namespace lib_token {
|
|||
};
|
||||
|
||||
/**
|
||||
* @brief 表达式终止token
|
||||
* @brief 表达式终止token
|
||||
*/
|
||||
template<typename ExprT> class ExprEndToken : public IActionToken {
|
||||
private:
|
||||
|
|
@ -156,21 +156,21 @@ namespace lib_token {
|
|||
ExprEndToken(std::shared_ptr<ExprBeginToken<ExprT>> start, std::shared_ptr<const IActionToken> prev)
|
||||
: _prev_token(prev), _self_start(start){ }
|
||||
|
||||
// 通过 IActionToken 继承
|
||||
// 通过 IActionToken 继承
|
||||
QString file() const override {
|
||||
throw new lib_token::TokenException(u8"不应该直接访问ExprEndToken");
|
||||
throw new lib_token::TokenException("不应该直接访问ExprEndToken");
|
||||
}
|
||||
uint64_t position() const override {
|
||||
throw new lib_token::TokenException(u8"不应该直接访问ExprEndToken");
|
||||
throw new lib_token::TokenException("不应该直接访问ExprEndToken");
|
||||
}
|
||||
QString content() const override {
|
||||
throw new lib_token::TokenException(u8"不应该直接访问ExprEndToken");
|
||||
throw new lib_token::TokenException("不应该直接访问ExprEndToken");
|
||||
}
|
||||
int row() const override {
|
||||
throw new lib_token::TokenException(u8"不应该直接访问ExprEndToken");
|
||||
throw new lib_token::TokenException("不应该直接访问ExprEndToken");
|
||||
}
|
||||
int column() const override {
|
||||
throw new lib_token::TokenException(u8"不应该直接访问ExprEndToken");
|
||||
throw new lib_token::TokenException("不应该直接访问ExprEndToken");
|
||||
}
|
||||
std::shared_ptr<const ITokenDefine> defines() const override {
|
||||
return nullptr;
|
||||
|
|
|
|||
|
|
@ -7,14 +7,14 @@ using namespace lib_token;
|
|||
using namespace lib_words;
|
||||
|
||||
|
||||
QString LeftBracket::reviseWords() const { return u8"{"; }
|
||||
QString LeftBracket::reviseWords() const { return "{"; }
|
||||
|
||||
int LeftBracket::typeMark() const
|
||||
{
|
||||
return 0x01000000;
|
||||
}
|
||||
|
||||
QString LeftBracket::regex() const { return u8"{"; }
|
||||
QString LeftBracket::regex() const { return "{"; }
|
||||
|
||||
std::tuple<std::shared_ptr<const IToken>, std::shared_ptr<const IPrimitiveWord>>
|
||||
LeftBracket::analysis(std::shared_ptr<const IPrimitiveWord> content) const {
|
||||
|
|
@ -34,23 +34,23 @@ LeftBracket::analysis(std::shared_ptr<const IPrimitiveWord> content) const {
|
|||
return std::make_tuple(token_inst, nullptr);
|
||||
}
|
||||
|
||||
QString RightBracket::reviseWords() const { return u8"}"; }
|
||||
QString RightBracket::reviseWords() const { return "}"; }
|
||||
|
||||
int RightBracket::typeMark() const
|
||||
{
|
||||
return 0x02000000;
|
||||
}
|
||||
|
||||
QString RightBracket::regex() const { return u8"}"; }
|
||||
QString RightBracket::regex() const { return "}"; }
|
||||
|
||||
QString ReferMark::reviseWords() const { return u8"@"; }
|
||||
QString ReferMark::reviseWords() const { return "@"; }
|
||||
|
||||
int ReferMark::typeMark() const
|
||||
{
|
||||
return 0x03000000;
|
||||
}
|
||||
|
||||
QString ReferMark::regex() const { return u8"@"; }
|
||||
QString ReferMark::regex() const { return "@"; }
|
||||
|
||||
Keywords::Keywords(const QString& val, uint type_code) : means_store(val), type_code(type_code) {}
|
||||
|
||||
|
|
@ -74,14 +74,14 @@ Keywords::analysis(std::shared_ptr<const IPrimitiveWord> content) const {
|
|||
return std::make_tuple(token_inst, nullptr);
|
||||
}
|
||||
|
||||
QString Numbers::reviseWords() const { return u8"ÕýÕûÊý"; }
|
||||
QString Numbers::reviseWords() const { return "正整数"; }
|
||||
|
||||
int Numbers::typeMark() const
|
||||
{
|
||||
return 0x07000000;
|
||||
}
|
||||
|
||||
QString Numbers::regex() const { return u8"^([0-9]+)$"; }
|
||||
QString Numbers::regex() const { return "^([0-9]+)$"; }
|
||||
|
||||
std::tuple<std::shared_ptr<const IToken>, std::shared_ptr<const IPrimitiveWord>>
|
||||
Numbers::analysis(std::shared_ptr<const IPrimitiveWord> content) const {
|
||||
|
|
@ -95,14 +95,14 @@ Numbers::analysis(std::shared_ptr<const IPrimitiveWord> content) const {
|
|||
return std::make_tuple(tinst, nullptr);
|
||||
}
|
||||
|
||||
QString VTextSection::reviseWords() const { return u8"Îı¾"; }
|
||||
QString VTextSection::reviseWords() const { return "文本"; }
|
||||
|
||||
int VTextSection::typeMark() const
|
||||
{
|
||||
return 0x09000000;
|
||||
}
|
||||
|
||||
QString VTextSection::regex() const { return u8"^([^\\{\\}@&]+)"; }
|
||||
QString VTextSection::regex() const { return "^([^\\{\\}@&]+)"; }
|
||||
|
||||
std::tuple<std::shared_ptr<const IToken>, std::shared_ptr<const IPrimitiveWord>>
|
||||
VTextSection::analysis(std::shared_ptr<const IPrimitiveWord> content) const {
|
||||
|
|
@ -125,23 +125,23 @@ VTextSection::analysis(std::shared_ptr<const IPrimitiveWord> content) const {
|
|||
return std::make_tuple(tinst, nullptr);
|
||||
}
|
||||
|
||||
QString Split::reviseWords() const { return u8"&"; }
|
||||
QString Split::reviseWords() const { return "&"; }
|
||||
|
||||
int Split::typeMark() const
|
||||
{
|
||||
return 0x05000000;
|
||||
}
|
||||
|
||||
QString Split::regex() const { return u8"&"; }
|
||||
QString Split::regex() const { return "&"; }
|
||||
|
||||
QString NameSection::reviseWords() const { return u8"Ãû³Æ"; }
|
||||
QString NameSection::reviseWords() const { return "名称"; }
|
||||
|
||||
int NameSection::typeMark() const
|
||||
{
|
||||
return 0x08000000;
|
||||
}
|
||||
|
||||
QString NameSection::regex() const { return u8"^([^\\{\\}@&]+)"; }
|
||||
QString NameSection::regex() const { return "^([^\\{\\}@&]+)"; }
|
||||
|
||||
std::tuple<std::shared_ptr<const IToken>, std::shared_ptr<const IPrimitiveWord> >
|
||||
NameSection::analysis(std::shared_ptr<const IPrimitiveWord> content) const
|
||||
|
|
@ -166,7 +166,7 @@ NameSection::analysis(std::shared_ptr<const IPrimitiveWord> content) const
|
|||
}
|
||||
|
||||
QString DeclareSymbo::reviseWords() const {
|
||||
return u8"#";
|
||||
return "#";
|
||||
}
|
||||
|
||||
int DeclareSymbo::typeMark() const
|
||||
|
|
@ -176,7 +176,7 @@ int DeclareSymbo::typeMark() const
|
|||
|
||||
QString DeclareSymbo::regex() const
|
||||
{
|
||||
return u8"#";
|
||||
return "#";
|
||||
}
|
||||
|
||||
std::tuple<std::shared_ptr<const IToken>, std::shared_ptr<const IPrimitiveWord>>
|
||||
|
|
@ -190,7 +190,7 @@ DeclareSymbo::analysis(std::shared_ptr<const IPrimitiveWord> content) const
|
|||
auto remains = content->content().mid(regex().size());
|
||||
|
||||
auto tinst = std::make_shared<TokenContent>(content->row(), content->column(), content->position(),
|
||||
u8"#", content->file(), shared_from_this());
|
||||
"#", content->file(), shared_from_this());
|
||||
if (remains.length()) {
|
||||
auto t_remains = std::make_shared<WordContent>(content->row(), content->column()+1,
|
||||
content->position() + regex().length(), remains, content->file());
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ namespace example_novel {
|
|||
|
||||
class LIBSYNTAX_EXPORT DeclareSymbo : public lib_token::ITokenProcess, public std::enable_shared_from_this<DeclareSymbo> {
|
||||
public:
|
||||
// 通过 TokenDefine 继承
|
||||
// 通过 TokenDefine 继承
|
||||
virtual QString reviseWords() const override;
|
||||
virtual int typeMark() const override;
|
||||
virtual QString regex() const override;
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
#include "libtoken.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
||||
using namespace lib_token;
|
||||
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "libtoken_global.h"
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <memory>
|
||||
|
||||
namespace lib_token {
|
||||
|
||||
|
||||
} // namespace lib_token
|
||||
|
|
@ -63,6 +63,12 @@
|
|||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="Configuration">
|
||||
<ClCompile>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ QList<std::shared_ptr<const IWordBase>> lib_words::WordReader::extract_primary(Q
|
|||
|
||||
#include <QRegExp>
|
||||
QList<std::shared_ptr<const IWordBase>> WordReader::parse_line(uint64_t start_pos, int row, const QString& line_text, const QString& path) const {
|
||||
QRegExp split_char(u8"\\s");
|
||||
QRegExp split_char("\\s");
|
||||
auto words = line_text.split(split_char, QString::SplitBehavior::SkipEmptyParts);
|
||||
|
||||
QList<std::shared_ptr<const IWordBase>> primary_words;
|
||||
|
|
|
|||
|
|
@ -8,32 +8,32 @@
|
|||
|
||||
namespace lib_words {
|
||||
/**
|
||||
* @brief 源码词语实例
|
||||
* @brief 源码词语实例
|
||||
*/
|
||||
class IWordBase {
|
||||
public:
|
||||
/**
|
||||
* @brief 源文件路径
|
||||
* @brief 源文件路径
|
||||
* @return
|
||||
*/
|
||||
virtual QString file() const = 0;
|
||||
/**
|
||||
* @brief 获取位置
|
||||
* @return 起始位置
|
||||
* @brief 获取位置
|
||||
* @return 起始位置
|
||||
*/
|
||||
virtual uint64_t position() const = 0;
|
||||
/**
|
||||
* @brief 词语内容
|
||||
* @brief 词语内容
|
||||
* @return
|
||||
*/
|
||||
virtual QString content() const = 0;
|
||||
/**
|
||||
* @brief 源码行号
|
||||
* @brief 源码行号
|
||||
* @return
|
||||
*/
|
||||
virtual int row() const = 0;
|
||||
/**
|
||||
* @brief 源码列号
|
||||
* @brief 源码列号
|
||||
* @return
|
||||
*/
|
||||
virtual int column() const = 0;
|
||||
|
|
@ -42,7 +42,7 @@ namespace lib_words {
|
|||
class IPrimitiveWord : public IWordBase {
|
||||
public:
|
||||
/**
|
||||
* @brief 下一个单词.
|
||||
* @brief 下一个单词.
|
||||
*
|
||||
* \return
|
||||
*/
|
||||
|
|
@ -50,7 +50,7 @@ namespace lib_words {
|
|||
};
|
||||
|
||||
/**
|
||||
* @brief 未解析原始词语
|
||||
* @brief 未解析原始词语
|
||||
*/
|
||||
class LIBWORDS_EXPORT WordContent : public IPrimitiveWord {
|
||||
private:
|
||||
|
|
@ -79,7 +79,7 @@ namespace lib_words {
|
|||
public:
|
||||
WordImpl(std::shared_ptr<const IWordBase> content, std::shared_ptr<const IPrimitiveWord> next);
|
||||
|
||||
// 通过 IWordBase 继承
|
||||
// 通过 IWordBase 继承
|
||||
QString file() const override;
|
||||
virtual uint64_t position() const override;
|
||||
QString content() const override;
|
||||
|
|
@ -90,7 +90,7 @@ namespace lib_words {
|
|||
|
||||
|
||||
/**
|
||||
* @brief 源码词语获取器
|
||||
* @brief 源码词语获取器
|
||||
*/
|
||||
class LIBWORDS_EXPORT WordReader {
|
||||
private:
|
||||
|
|
@ -99,7 +99,7 @@ namespace lib_words {
|
|||
|
||||
public:
|
||||
/**
|
||||
* @brief 提取源码中所有的词语
|
||||
* @brief 提取源码中所有的词语
|
||||
*/
|
||||
std::shared_ptr<const IPrimitiveWord> wordsFrom(QTextStream& tin, const QString& path) const;
|
||||
};
|
||||
|
|
@ -107,7 +107,7 @@ namespace lib_words {
|
|||
|
||||
|
||||
/**
|
||||
* @brief 解析异常
|
||||
* @brief 解析异常
|
||||
*/
|
||||
class LIBWORDS_EXPORT WordsException {
|
||||
private:
|
||||
|
|
|
|||
Loading…
Reference in New Issue