patterns: Updated pattern language
This commit is contained in:
parent
a639dddd19
commit
01af2f364c
2
lib/external/pattern_language
vendored
2
lib/external/pattern_language
vendored
@ -1 +1 @@
|
||||
Subproject commit 173fed3182b2b2d82f952f41cc9d9ce2d19fa2e7
|
||||
Subproject commit 37b4bc7f2c0c342b6c70e6757d402aceb0d4a35b
|
@ -450,6 +450,14 @@ namespace hex {
|
||||
bool dangerous;
|
||||
};
|
||||
|
||||
struct TypeDefinition {
|
||||
pl::api::Namespace ns;
|
||||
std::string name;
|
||||
|
||||
pl::api::FunctionParameterCount parameterCount;
|
||||
pl::api::TypeCallback callback;
|
||||
};
|
||||
|
||||
struct Visualizer {
|
||||
pl::api::FunctionParameterCount parameterCount;
|
||||
VisualizerFunctionCallback callback;
|
||||
@ -459,6 +467,7 @@ namespace hex {
|
||||
const std::map<std::string, Visualizer>& getInlineVisualizers();
|
||||
const std::map<std::string, pl::api::PragmaHandler>& getPragmas();
|
||||
const std::vector<FunctionDefinition>& getFunctions();
|
||||
const std::vector<TypeDefinition>& getTypes();
|
||||
|
||||
}
|
||||
|
||||
@ -517,6 +526,20 @@ namespace hex {
|
||||
const pl::api::FunctionCallback &func
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief Adds a new type to the pattern language
|
||||
* @param ns The namespace of the type
|
||||
* @param name The name of the type
|
||||
* @param parameterCount The amount of non-type template parameters the type takes
|
||||
* @param func The type callback
|
||||
*/
|
||||
void addType(
|
||||
const pl::api::Namespace &ns,
|
||||
const std::string &name,
|
||||
pl::api::FunctionParameterCount parameterCount,
|
||||
const pl::api::TypeCallback &func
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief Adds a new visualizer to the pattern language
|
||||
* @note Visualizers are extensions to the [[hex::visualize]] attribute, used to visualize data
|
||||
|
@ -552,6 +552,11 @@ namespace hex {
|
||||
return *s_functions;
|
||||
}
|
||||
|
||||
static AutoReset<std::vector<TypeDefinition>> s_types;
|
||||
const std::vector<TypeDefinition>& getTypes() {
|
||||
return *s_types;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static std::string getFunctionName(const pl::api::Namespace &ns, const std::string &name) {
|
||||
@ -605,6 +610,10 @@ namespace hex {
|
||||
runtime.addFunction(ns, name, paramCount, callback);
|
||||
}
|
||||
|
||||
for (const auto &[ns, name, paramCount, callback] : impl::getTypes()) {
|
||||
runtime.addType(ns, name, paramCount, callback);
|
||||
}
|
||||
|
||||
for (const auto &[name, callback] : impl::getPragmas()) {
|
||||
runtime.addPragma(name, callback);
|
||||
}
|
||||
@ -639,6 +648,15 @@ namespace hex {
|
||||
});
|
||||
}
|
||||
|
||||
void addType(const pl::api::Namespace &ns, const std::string &name, pl::api::FunctionParameterCount parameterCount, const pl::api::TypeCallback &func) {
|
||||
log::debug("Registered new pattern language type: {}", getFunctionName(ns, name));
|
||||
|
||||
impl::s_types->push_back({
|
||||
ns, name,
|
||||
parameterCount, func
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
void addVisualizer(const std::string &name, const impl::VisualizerFunctionCallback &function, pl::api::FunctionParameterCount parameterCount) {
|
||||
log::debug("Registered new pattern visualizer function: {}", name);
|
||||
|
Loading…
Reference in New Issue
Block a user