1
0
mirror of synced 2024-12-15 01:01:15 +01:00
ImHex/plugins/libimhex/include/hex/pattern_language/preprocessor.hpp
WerWolv e74c0f5cf5 sys: Tons of long overdue cleanup
- std::string -> const std::string& where needed
- Added a FileIO abstraction class
- Fixed recent files not updating
- Removed localization file from global include
- Renamed lang to pattern_language/pl
- Renamed EventFileDropped to RequestFileOpen
2021-09-08 15:18:24 +02:00

40 lines
1.1 KiB
C++

#pragma once
#include <hex.hpp>
#include <functional>
#include <optional>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
namespace hex::pl {
class Preprocessor {
public:
Preprocessor();
std::optional<std::string> preprocess(const std::string& code, bool initialRun = true);
void addPragmaHandler(const std::string &pragmaType, const std::function<bool(const std::string&)> &function);
void addDefaultPragmaHandlers();
const std::pair<u32, std::string>& getError() { return this->m_error; }
private:
using PreprocessorError = std::pair<u32, std::string>;
[[noreturn]] void throwPreprocessorError(const std::string &error, u32 lineNumber) const {
throw PreprocessorError(lineNumber, "Preprocessor: " + error);
}
std::unordered_map<std::string, std::function<bool(std::string)>> m_pragmaHandlers;
std::set<std::tuple<std::string, std::string, u32>> m_defines;
std::set<std::tuple<std::string, std::string, u32>> m_pragmas;
std::pair<u32, std::string> m_error;
};
}