#pragma once #include #include #include #include #include #include #include #include #include namespace hex::pl { class Preprocessor { public: Preprocessor() = default; std::optional preprocess(const std::string &code, bool initialRun = true); void addPragmaHandler(const std::string &pragmaType, const std::function &function); void removePragmaHandler(const std::string &pragmaType); void addDefaultPragmaHandlers(); const std::optional &getError() { return this->m_error; } bool shouldOnlyIncludeOnce() { return this->m_onlyIncludeOnce; } private: [[noreturn]] static void throwPreprocessorError(const std::string &error, u32 lineNumber) { throw PatternLanguageError(lineNumber, "Preprocessor: " + error); } std::unordered_map> m_pragmaHandlers; std::set> m_defines; std::set> m_pragmas; std::set m_onceIncludedFiles; std::optional m_error; bool m_onlyIncludeOnce = false; }; }