2021-01-22 18:01:39 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <hex.hpp>
|
|
|
|
|
|
|
|
#include <bit>
|
2021-12-10 11:55:27 +01:00
|
|
|
#include <map>
|
2021-01-22 18:01:39 +01:00
|
|
|
#include <optional>
|
|
|
|
#include <string>
|
|
|
|
#include <string_view>
|
|
|
|
#include <vector>
|
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
#include <hex/pattern_language/log_console.hpp>
|
2021-12-10 11:55:27 +01:00
|
|
|
#include <hex/pattern_language/token.hpp>
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
namespace hex::prv {
|
|
|
|
class Provider;
|
|
|
|
}
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
namespace hex::pl {
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
|
|
class Preprocessor;
|
|
|
|
class Lexer;
|
|
|
|
class Parser;
|
|
|
|
class Validator;
|
|
|
|
class Evaluator;
|
2021-08-29 22:15:18 +02:00
|
|
|
class PatternData;
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2021-09-21 21:29:18 +02:00
|
|
|
class ASTNode;
|
|
|
|
|
2021-01-22 18:01:39 +01:00
|
|
|
class PatternLanguage {
|
|
|
|
public:
|
2021-01-23 14:00:09 +01:00
|
|
|
PatternLanguage();
|
2021-01-22 18:01:39 +01:00
|
|
|
~PatternLanguage();
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
[[nodiscard]] std::optional<std::vector<ASTNode *>> parseString(const std::string &code);
|
2022-02-06 00:18:04 +01:00
|
|
|
[[nodiscard]] bool executeString(prv::Provider *provider, const std::string &string, const std::map<std::string, Token::Literal> &envVars = {}, const std::map<std::string, Token::Literal> &inVariables = {}, bool checkResult = true);
|
2022-02-01 18:09:40 +01:00
|
|
|
[[nodiscard]] bool executeFile(prv::Provider *provider, const fs::path &path, const std::map<std::string, Token::Literal> &envVars = {}, const std::map<std::string, Token::Literal> &inVariables = {});
|
2022-02-06 00:18:04 +01:00
|
|
|
[[nodiscard]] std::pair<bool, std::optional<Token::Literal>> executeFunction(prv::Provider *provider, const std::string &code);
|
2022-01-24 20:53:17 +01:00
|
|
|
[[nodiscard]] const std::vector<ASTNode *> &getCurrentAST() const;
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2021-10-07 11:34:46 +02:00
|
|
|
void abort();
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
[[nodiscard]] const std::vector<std::pair<LogConsole::Level, std::string>> &getConsoleLog();
|
2022-01-31 14:37:12 +01:00
|
|
|
[[nodiscard]] const std::optional<PatternLanguageError> &getError();
|
2022-01-24 20:53:17 +01:00
|
|
|
[[nodiscard]] std::map<std::string, Token::Literal> getOutVariables() const;
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
[[nodiscard]] u32 getCreatedPatternCount();
|
|
|
|
[[nodiscard]] u32 getMaximumPatternCount();
|
2021-10-02 15:22:38 +02:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
[[nodiscard]] bool hasDangerousFunctionBeenCalled() const;
|
2021-12-19 12:32:15 +01:00
|
|
|
void allowDangerousFunctions(bool allow);
|
|
|
|
|
2022-02-01 22:09:44 +01:00
|
|
|
[[nodiscard]] std::vector<PatternData *> &getPatterns() {
|
2022-02-01 18:09:40 +01:00
|
|
|
return this->m_patterns;
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset();
|
|
|
|
bool isRunning() const { return this->m_running; }
|
|
|
|
|
2021-01-22 18:01:39 +01:00
|
|
|
private:
|
|
|
|
Preprocessor *m_preprocessor;
|
|
|
|
Lexer *m_lexer;
|
|
|
|
Parser *m_parser;
|
|
|
|
Validator *m_validator;
|
|
|
|
Evaluator *m_evaluator;
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
std::vector<ASTNode *> m_currAST;
|
2021-09-21 21:29:18 +02:00
|
|
|
|
2022-01-31 14:37:12 +01:00
|
|
|
std::optional<PatternLanguageError> m_currError;
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2022-02-01 22:09:44 +01:00
|
|
|
std::vector<PatternData *> m_patterns;
|
2022-02-01 18:09:40 +01:00
|
|
|
|
|
|
|
bool m_running = false;
|
2021-01-22 18:01:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|