#pragma once #include #include #include #include #include #include #include #include #include #include namespace hex::prv { class Provider; } namespace hex::pl { class Preprocessor; class Lexer; class Parser; class Validator; class Evaluator; class Pattern; class ASTNode; class PatternLanguage { public: PatternLanguage(); ~PatternLanguage(); [[nodiscard]] std::optional>> parseString(const std::string &code); [[nodiscard]] bool executeString(prv::Provider *provider, const std::string &string, const std::map &envVars = {}, const std::map &inVariables = {}, bool checkResult = true); [[nodiscard]] bool executeFile(prv::Provider *provider, const std::fs::path &path, const std::map &envVars = {}, const std::map &inVariables = {}); [[nodiscard]] std::pair> executeFunction(prv::Provider *provider, const std::string &code); [[nodiscard]] const std::vector> &getCurrentAST() const; void abort(); [[nodiscard]] const std::vector> &getConsoleLog(); [[nodiscard]] const std::optional &getError(); [[nodiscard]] std::map getOutVariables() const; [[nodiscard]] u32 getCreatedPatternCount(); [[nodiscard]] u32 getMaximumPatternCount(); [[nodiscard]] bool hasDangerousFunctionBeenCalled() const; void allowDangerousFunctions(bool allow); [[nodiscard]] const std::vector> &getPatterns() { const static std::vector> empty; if (isRunning()) return empty; else return this->m_patterns; } void reset(); [[nodiscard]] bool isRunning() const { return this->m_running; } private: Preprocessor *m_preprocessor; Lexer *m_lexer; Parser *m_parser; Validator *m_validator; Evaluator *m_evaluator; std::vector> m_currAST; std::optional m_currError; std::vector> m_patterns; bool m_running = false; }; }