#pragma once #include "libparse_global.h" #include #include #include namespace lib_parse { /** * @brief 检查机制异常 */ class LIBPARSE_EXPORT CheckException { private: QString msg_store; public: CheckException(const QString& msg); virtual ~CheckException() = default; virtual QString message() const; }; /** * @brief 校验机制提供类型 */ class CheckProvider { public: virtual QString name() const = 0; virtual void validCheck(std::shared_ptr root) const = 0; }; /** * @brief 分析器对外接口 */ class LIBPARSE_EXPORT Analyzer { private: QList> check_providers; public: /** * @brief 构建AST分析器. * * \param providers */ Analyzer(const QList>& providers); /** * @brief 使用本分析器分析指定Ast. * * \param root * \return */ std::shared_ptr validCheckWith(std::shared_ptr root) const; }; /** * @brief 遍历模式. */ enum class VisitMode { FirstParent, // 先序遍历 LastParent, // 后序遍历 }; /** * @brief Ast树遍历模式. */ class TreeVisitor { public: /** * 获取访问器的遍历模式. * * \return */ virtual VisitMode mode() const = 0; /** * 对语法树执行节点遍历. * * \param syntax_element 当前访问节点 * \return 是否继续执行遍历 */ virtual bool visit(std::shared_ptr syntax_element) = 0; }; /** * @brief Ast遍历控制接口. */ class LIBPARSE_EXPORT VisitEntry { public: bool visitWith(std::shared_ptr syntax_elm, std::shared_ptr visitor); }; }