2020-11-17 02:31:51 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <hex.hpp>
|
|
|
|
|
|
|
|
#include "token.hpp"
|
|
|
|
|
2020-11-21 14:39:01 +01:00
|
|
|
#include <functional>
|
|
|
|
#include <set>
|
2020-11-17 02:31:51 +01:00
|
|
|
#include <string>
|
2020-11-21 14:39:01 +01:00
|
|
|
#include <unordered_map>
|
2020-11-17 02:31:51 +01:00
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
namespace hex::lang {
|
|
|
|
|
|
|
|
class Preprocessor {
|
|
|
|
public:
|
|
|
|
Preprocessor();
|
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
std::optional<std::string> preprocess(const std::string& code, bool initialRun = true);
|
2020-11-21 14:39:01 +01:00
|
|
|
|
|
|
|
void addPragmaHandler(std::string pragmaType, std::function<bool(std::string)> function);
|
2020-11-27 21:20:23 +01:00
|
|
|
void addDefaultPragmaHandlers();
|
|
|
|
|
|
|
|
const std::pair<u32, std::string>& getError() { return this->m_error; }
|
2020-11-17 02:31:51 +01:00
|
|
|
|
|
|
|
private:
|
2020-11-21 14:39:01 +01:00
|
|
|
std::unordered_map<std::string, std::function<bool(std::string)>> m_pragmaHandlers;
|
|
|
|
|
2020-11-17 02:31:51 +01:00
|
|
|
std::set<std::pair<std::string, std::string>> m_defines;
|
2020-11-21 14:39:01 +01:00
|
|
|
std::set<std::pair<std::string, std::string>> m_pragmas;
|
2020-11-27 21:20:23 +01:00
|
|
|
|
|
|
|
std::pair<u32, std::string> m_error;
|
2020-11-17 02:31:51 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|