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
|
|
|
|
|
|
|
namespace hex::prv { class Provider; }
|
|
|
|
|
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();
|
|
|
|
|
2021-12-18 22:56:36 +01:00
|
|
|
[[nodiscard]]
|
|
|
|
std::optional<std::vector<ASTNode*>> parseString(const std::string &code);
|
|
|
|
[[nodiscard]]
|
|
|
|
std::optional<std::vector<PatternData*>> executeString(prv::Provider *provider, const std::string &string, const std::map<std::string, Token::Literal> &envVars = { }, const std::map<std::string, Token::Literal> &inVariables = { });
|
|
|
|
[[nodiscard]]
|
|
|
|
std::optional<std::vector<PatternData*>> executeFile(prv::Provider *provider, const std::string &path, const std::map<std::string, Token::Literal> &envVars = { }, const std::map<std::string, Token::Literal> &inVariables = { });
|
|
|
|
[[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();
|
|
|
|
|
2021-12-18 22:56:36 +01:00
|
|
|
[[nodiscard]]
|
2021-01-23 14:00:09 +01:00
|
|
|
const std::vector<std::pair<LogConsole::Level, std::string>>& getConsoleLog();
|
2021-12-18 22:56:36 +01:00
|
|
|
[[nodiscard]]
|
2021-01-23 14:00:09 +01:00
|
|
|
const std::optional<std::pair<u32, std::string>>& getError();
|
2021-12-18 22:56:36 +01:00
|
|
|
[[nodiscard]]
|
|
|
|
std::map<std::string, Token::Literal> getOutVariables() const;
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2021-12-18 22:56:36 +01:00
|
|
|
[[nodiscard]]
|
2021-10-02 15:22:38 +02:00
|
|
|
u32 getCreatedPatternCount();
|
2021-12-18 22:56:36 +01:00
|
|
|
[[nodiscard]]
|
2021-10-02 15:22:38 +02:00
|
|
|
u32 getMaximumPatternCount();
|
|
|
|
|
2021-01-22 18:01:39 +01:00
|
|
|
private:
|
|
|
|
Preprocessor *m_preprocessor;
|
|
|
|
Lexer *m_lexer;
|
|
|
|
Parser *m_parser;
|
|
|
|
Validator *m_validator;
|
|
|
|
Evaluator *m_evaluator;
|
|
|
|
|
2021-09-21 21:29:18 +02:00
|
|
|
std::vector<ASTNode*> m_currAST;
|
|
|
|
|
2021-01-22 18:01:39 +01:00
|
|
|
std::optional<std::pair<u32, std::string>> m_currError;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|