QtNovelUI/libParse/SyntaxBase.h

90 lines
1.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef SYNTAXBASE_H
#define SYNTAXBASE_H
#include "libParse.h"
#include "LexFoundation.h"
namespace Syntax {
/**
* 解析结果标志.
*/
enum class ParseResult
{
SelfManipulate = 1,
EnterNext = 2,
Completed = 3,
Failed = 4,
};
/**
* 解析器接口.
*/
class SyntaxParser
{
public:
virtual ~SyntaxParser() = default;
/**
* 设置当前活动的Doc实例.
*
* \param ins
*/
virtual void docActive(Parse::Result::DocCore *ins) = 0;
/**
* 当前指向的文档.
*
* \return 文档实例
*/
virtual Parse::Result::DocCore* docRef() const = 0;
/**
* 适配当前解析.
*
* \param seqs
* \return
*/
virtual bool applied(const QList<Lex::LexResult>& seqs) = 0;
/**
* 重置解析器
*/
virtual void reset() = 0;
/**
* 针对性的解析当前Token序列对已经解析过的序列做摘除处理返回下一步可能用到的解析器列表。
*
* \param seqs 标记序列
* \param next_ps 下一步需要用到的解析器
* \return 解析操作类型
*/
virtual ParseResult parse(QList<Lex::LexResult>& seqs)= 0;
/**
* 子解析器集合.
*
* \return
*/
virtual QList<SyntaxParser*> children() const = 0;
/**
* 当前聚焦的节点.
*
* \return
*/
virtual Parse::Result::DesNode* currNode() const = 0;
protected:
/**
* 设置子元素解析器,内部元素解析器集合.
*
* \param parsers 解析器集合
*/
virtual void addChild(QList<SyntaxParser*> parsers) = 0;
};
}
#endif // SYNTAXBASE_H