#pragma once #include "libparse_global.h" #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: Analyzer(const QList>& providers); std::shared_ptr validCheckWith(std::shared_ptr root) const; }; enum class VisitMode { FirstParent, // 先序遍历 LastParent, // 后序遍历 }; class TreeVisitor { public: /** * 获取访问器的遍历模式. * * \return */ virtual VisitMode mode() const = 0; /** * 对语法树执行节点遍历. * * \param syntax_element 当前访问节点 * \return 是否继续执行遍历 */ virtual bool visit(std::shared_ptr syntax_element) = 0; }; class LIBPARSE_EXPORT VisitorControl { public: bool visitWith(std::shared_ptr syntax_elm, std::shared_ptr visitor); }; }