2020-11-17 01:31:51 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <hex.hpp>
|
|
|
|
|
2020-11-21 13:39:01 +00:00
|
|
|
#include <functional>
|
2021-08-31 18:03:08 +00:00
|
|
|
#include <optional>
|
2020-11-21 13:39:01 +00:00
|
|
|
#include <set>
|
2020-11-17 01:31:51 +00:00
|
|
|
#include <string>
|
2020-11-21 13:39:01 +00:00
|
|
|
#include <unordered_map>
|
2020-11-17 01:31:51 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2022-01-30 16:49:18 +00:00
|
|
|
#include <hex/helpers/paths.hpp>
|
|
|
|
|
2022-01-31 13:37:12 +00:00
|
|
|
#include <hex/pattern_language/error.hpp>
|
|
|
|
|
2021-09-08 13:18:24 +00:00
|
|
|
namespace hex::pl {
|
2020-11-17 01:31:51 +00:00
|
|
|
|
|
|
|
class Preprocessor {
|
|
|
|
public:
|
2022-01-31 13:37:12 +00:00
|
|
|
Preprocessor() = default;
|
2020-11-17 01:31:51 +00:00
|
|
|
|
2022-01-24 19:53:17 +00:00
|
|
|
std::optional<std::string> preprocess(const std::string &code, bool initialRun = true);
|
2020-11-21 13:39:01 +00:00
|
|
|
|
2022-01-24 19:53:17 +00:00
|
|
|
void addPragmaHandler(const std::string &pragmaType, const std::function<bool(const std::string &)> &function);
|
2020-11-27 20:20:23 +00:00
|
|
|
void addDefaultPragmaHandlers();
|
|
|
|
|
2022-01-31 13:37:12 +00:00
|
|
|
const std::optional<PatternLanguageError> &getError() { return this->m_error; }
|
2020-11-17 01:31:51 +00:00
|
|
|
|
|
|
|
private:
|
2022-01-31 13:37:12 +00:00
|
|
|
[[noreturn]] static void throwPreprocessorError(const std::string &error, u32 lineNumber) {
|
|
|
|
throw PatternLanguageError(lineNumber, "Preprocessor: " + error);
|
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
|
|
|
}
|
|
|
|
|
2020-11-21 13:39:01 +00:00
|
|
|
std::unordered_map<std::string, std::function<bool(std::string)>> m_pragmaHandlers;
|
|
|
|
|
2021-03-15 07:11:19 +00:00
|
|
|
std::set<std::tuple<std::string, std::string, u32>> m_defines;
|
|
|
|
std::set<std::tuple<std::string, std::string, u32>> m_pragmas;
|
2020-11-27 20:20:23 +00:00
|
|
|
|
2022-01-30 16:49:18 +00:00
|
|
|
std::set<fs::path> m_onceIncludedFiles;
|
|
|
|
|
2022-01-31 13:37:12 +00:00
|
|
|
std::optional<PatternLanguageError> m_error;
|
2020-11-17 01:31:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|