2020-11-10 14:26:38 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-02-01 17:09:40 +00:00
|
|
|
#include <hex/ui/view.hpp>
|
2022-04-17 14:57:30 +00:00
|
|
|
#include <pl/pattern_language.hpp>
|
2022-08-06 19:38:09 +00:00
|
|
|
#include <pl/core/errors/error.hpp>
|
2021-01-13 16:28:27 +00:00
|
|
|
#include <hex/providers/provider.hpp>
|
2020-11-10 14:26:38 +00:00
|
|
|
|
|
|
|
#include <cstring>
|
2020-11-21 13:39:16 +00:00
|
|
|
#include <filesystem>
|
2021-02-07 12:40:47 +00:00
|
|
|
#include <string_view>
|
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 19:27:11 +00:00
|
|
|
#include <thread>
|
2021-01-23 13:01:23 +00:00
|
|
|
#include <vector>
|
2020-11-10 14:26:38 +00:00
|
|
|
|
2021-01-13 16:28:27 +00:00
|
|
|
#include <TextEditor.h>
|
2020-11-12 20:20:51 +00:00
|
|
|
|
2022-08-06 19:38:09 +00:00
|
|
|
namespace pl::ptrn { class Pattern; }
|
2022-05-27 18:42:07 +00:00
|
|
|
|
2021-12-07 21:47:41 +00:00
|
|
|
namespace hex::plugin::builtin {
|
2020-11-10 14:26:38 +00:00
|
|
|
|
2021-08-28 19:51:33 +00:00
|
|
|
class ViewPatternEditor : public View {
|
2020-11-10 14:26:38 +00:00
|
|
|
public:
|
2021-08-28 19:51:33 +00:00
|
|
|
ViewPatternEditor();
|
|
|
|
~ViewPatternEditor() override;
|
2020-11-10 14:26:38 +00:00
|
|
|
|
2021-02-07 13:29:13 +00:00
|
|
|
void drawAlwaysVisible() override;
|
2020-12-22 17:10:01 +00:00
|
|
|
void drawContent() override;
|
2020-11-10 14:26:38 +00:00
|
|
|
|
|
|
|
private:
|
2021-12-18 21:56:36 +00:00
|
|
|
struct PatternVariable {
|
|
|
|
bool inVariable;
|
|
|
|
bool outVariable;
|
|
|
|
|
2022-08-06 19:38:09 +00:00
|
|
|
pl::core::Token::ValueType type;
|
|
|
|
pl::core::Token::Literal value;
|
2021-12-18 21:56:36 +00:00
|
|
|
};
|
|
|
|
|
2022-02-27 22:25:39 +00:00
|
|
|
enum class EnvVarType
|
|
|
|
{
|
2021-12-10 10:55:27 +00:00
|
|
|
Integer,
|
|
|
|
Float,
|
|
|
|
String,
|
|
|
|
Bool
|
|
|
|
};
|
|
|
|
|
|
|
|
struct EnvVar {
|
2021-12-18 21:56:36 +00:00
|
|
|
u64 id;
|
2021-12-10 10:55:27 +00:00
|
|
|
std::string name;
|
2022-08-06 19:38:09 +00:00
|
|
|
pl::core::Token::Literal value;
|
2021-12-10 10:55:27 +00:00
|
|
|
EnvVarType type;
|
2021-12-18 21:56:36 +00:00
|
|
|
|
|
|
|
bool operator==(const EnvVar &other) const {
|
|
|
|
return this->id == other.id;
|
|
|
|
}
|
2021-12-10 10:55:27 +00:00
|
|
|
};
|
|
|
|
|
2022-04-17 14:57:30 +00:00
|
|
|
enum class DangerousFunctionPerms : u8 {
|
|
|
|
Ask,
|
|
|
|
Allow,
|
|
|
|
Deny
|
|
|
|
};
|
|
|
|
|
2022-07-31 18:07:15 +00:00
|
|
|
private:
|
|
|
|
std::unique_ptr<pl::PatternLanguage> m_parserRuntime;
|
|
|
|
|
|
|
|
std::vector<std::fs::path> m_possiblePatternFiles;
|
|
|
|
u32 m_selectedPatternFile = 0;
|
|
|
|
bool m_runAutomatically = false;
|
|
|
|
|
|
|
|
bool m_lastEvaluationProcessed = true;
|
|
|
|
bool m_lastEvaluationResult = false;
|
2022-08-06 19:38:09 +00:00
|
|
|
std::optional<pl::core::err::PatternLanguageError> m_lastEvaluationError;
|
|
|
|
std::vector<std::pair<pl::core::LogConsole::Level, std::string>> m_lastEvaluationLog;
|
|
|
|
std::map<std::string, pl::core::Token::Literal> m_lastEvaluationOutVars;
|
2022-07-31 18:07:15 +00:00
|
|
|
|
|
|
|
std::atomic<u32> m_runningEvaluators = 0;
|
|
|
|
std::atomic<u32> m_runningParsers = 0;
|
|
|
|
|
|
|
|
bool m_hasUnevaluatedChanges = false;
|
|
|
|
|
|
|
|
bool m_acceptPatternWindowOpen = false;
|
|
|
|
|
|
|
|
TextEditor m_textEditor;
|
2022-08-06 19:38:09 +00:00
|
|
|
std::vector<std::pair<pl::core::LogConsole::Level, std::string>> m_console;
|
2022-07-31 18:07:15 +00:00
|
|
|
|
|
|
|
std::map<std::string, PatternVariable> m_patternVariables;
|
|
|
|
|
|
|
|
u64 m_envVarIdCounter;
|
|
|
|
std::list<EnvVar> m_envVarEntries;
|
|
|
|
|
2022-04-17 14:57:30 +00:00
|
|
|
std::atomic<bool> m_dangerousFunctionCalled = false;
|
|
|
|
std::atomic<DangerousFunctionPerms> m_dangerousFunctionsAllowed = DangerousFunctionPerms::Ask;
|
|
|
|
|
2022-07-31 18:07:15 +00:00
|
|
|
bool m_syncPatternSourceCode = false;
|
|
|
|
bool m_autoLoadPatterns = true;
|
|
|
|
|
|
|
|
private:
|
2021-12-18 21:56:36 +00:00
|
|
|
void drawConsole(ImVec2 size);
|
|
|
|
void drawEnvVars(ImVec2 size);
|
|
|
|
void drawVariableSettings(ImVec2 size);
|
2021-12-10 10:55:27 +00:00
|
|
|
|
2022-08-06 19:38:09 +00:00
|
|
|
void drawPatternTooltip(pl::ptrn::Pattern *pattern);
|
2022-05-27 18:42:07 +00:00
|
|
|
|
2022-03-04 10:36:37 +00:00
|
|
|
void loadPatternFile(const std::fs::path &path);
|
2021-12-18 21:56:36 +00:00
|
|
|
|
|
|
|
void parsePattern(const std::string &code);
|
|
|
|
void evaluatePattern(const std::string &code);
|
2022-10-21 08:03:37 +00:00
|
|
|
|
|
|
|
void registerEvents();
|
|
|
|
void registerMenuItems();
|
|
|
|
void registerHandlers();
|
2020-11-10 14:26:38 +00:00
|
|
|
};
|
|
|
|
|
2022-07-14 09:37:02 +00:00
|
|
|
}
|