1
0
mirror of synced 2024-12-01 02:37:18 +01:00
ImHex/lib/libimhex/include/hex/pattern_language/preprocessor.hpp

44 lines
1.2 KiB
C++
Raw Normal View History

#pragma once
#include <hex.hpp>
2020-11-21 14:39:01 +01:00
#include <functional>
#include <optional>
2020-11-21 14:39:01 +01:00
#include <set>
#include <string>
2020-11-21 14:39:01 +01:00
#include <unordered_map>
#include <utility>
#include <hex/helpers/paths.hpp>
namespace hex::pl {
class Preprocessor {
public:
Preprocessor();
std::optional<std::string> preprocess(const std::string &code, bool initialRun = true);
2020-11-21 14:39:01 +01:00
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);
}
2020-11-21 14:39:01 +01:00
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::set<fs::path> m_onceIncludedFiles;
std::pair<u32, std::string> m_error;
};
}