WsParser_VS/libParse/libparse.h

95 lines
2.1 KiB
C
Raw Permalink Normal View History

2024-03-17 07:58:28 +00:00
#pragma once
#include "libparse_global.h"
#include <ast_basic.h>
#include <ast_gen.h>
2025-02-15 12:25:51 +00:00
#include <ast_novel.h>
2024-03-17 07:58:28 +00:00
namespace lib_parse {
/**
2025-02-15 12:25:51 +00:00
* @brief
2024-03-17 07:58:28 +00:00
*/
class LIBPARSE_EXPORT CheckException {
private:
QString msg_store;
public:
CheckException(const QString& msg);
virtual ~CheckException() = default;
virtual QString message() const;
};
/**
2025-02-15 12:25:51 +00:00
* @brief
2024-03-17 07:58:28 +00:00
*/
class CheckProvider {
public:
2024-06-15 01:18:33 +00:00
virtual QString name() const = 0;
2024-03-17 07:58:28 +00:00
virtual void validCheck(std::shared_ptr<const ast_gen::ElementAccess> root) const = 0;
};
/**
2025-02-15 12:25:51 +00:00
* @brief
2024-03-17 07:58:28 +00:00
*/
class LIBPARSE_EXPORT Analyzer {
private:
QList<std::shared_ptr<const CheckProvider>> check_providers;
public:
2025-02-15 12:25:51 +00:00
/**
* @brief AST分析器.
*
* \param providers
*/
2024-03-17 07:58:28 +00:00
Analyzer(const QList<std::shared_ptr<const CheckProvider>>& providers);
2025-02-15 12:25:51 +00:00
/**
* @brief 使Ast.
*
* \param root
* \return
*/
2024-03-17 07:58:28 +00:00
std::shared_ptr<const ast_gen::ElementAccess> validCheckWith(std::shared_ptr<const ast_gen::ElementAccess> root) const;
};
2024-06-22 15:19:14 +00:00
2025-02-15 12:25:51 +00:00
/**
* @brief .
*/
2024-06-22 15:19:14 +00:00
enum class VisitMode {
2025-02-15 12:25:51 +00:00
FirstParent, // 先序遍历
LastParent, // 后序遍历
2024-06-22 15:19:14 +00:00
};
2025-02-15 12:25:51 +00:00
/**
* @brief Ast树遍历模式.
*/
2024-06-22 15:19:14 +00:00
class TreeVisitor {
public:
/**
2025-02-15 12:25:51 +00:00
* 访.
2024-06-22 15:19:14 +00:00
*
* \return
*/
virtual VisitMode mode() const = 0;
/**
2025-02-15 12:25:51 +00:00
* .
2024-06-22 15:19:14 +00:00
*
2025-02-15 12:25:51 +00:00
* \param syntax_element 访
* \return
2024-06-22 15:19:14 +00:00
*/
virtual bool visit(std::shared_ptr<const ast_gen::ElementAccess> syntax_element) = 0;
};
2025-02-15 12:25:51 +00:00
/**
* @brief Ast遍历控制接口.
*/
class LIBPARSE_EXPORT VisitEntry {
2024-06-22 15:19:14 +00:00
public:
bool visitWith(std::shared_ptr<const ast_gen::ElementAccess> syntax_elm, std::shared_ptr<TreeVisitor> visitor);
};
2024-03-17 07:58:28 +00:00
}