69#ifndef PARSER_MANAGER_H
70#define PARSER_MANAGER_H
100#define LIME_PLUGIN_HANDLE_INVALID ((LimePluginHandle)0)
151#define LIME_PLUGIN_ABI_VERSION_MAJOR 1
154#define LIME_PLUGIN_ABI_VERSION_MINOR 0
202 const char *(*get_name)(void);
360#define LIME_PLUGIN_ENTRY_SYMBOL "lime_plugin_entry"
373 #define LIME_PLUGIN_EXPORT __declspec(dllexport)
375 #define LIME_PLUGIN_EXPORT __attribute__((visibility("default")))
612 const char *grammar_file);
703 uint32_t *actual_count);
754 const char *grammar_file);
836 uint32_t required_caps);
LimePluginHandle parser_manager_get_active(const ParserManager *mgr)
Get the handle of the currently active plugin.
ParserManagerStatus parser_manager_set_snapshot(ParserManager *mgr, ParserSnapshot *snap)
Provide or replace the active snapshot directly.
ParserSnapshot * parser_manager_get_snapshot(ParserManager *mgr)
Get the current active snapshot.
ParserManagerStatus parser_manager_set_active(ParserManager *mgr, LimePluginHandle handle, const char *grammar_file)
Set the active parser plugin.
ParserManagerStatus parser_manager_hot_swap(ParserManager *mgr, LimePluginHandle new_handle, const char *grammar_file)
Atomically replace the active plugin and snapshot.
struct ParserManager ParserManager
Opaque parser manager handle.
ParserManager * parser_manager_create(const ParserManagerConfig *config)
Create a new parser manager.
void parser_manager_destroy(ParserManager *mgr)
Destroy a parser manager and release all resources.
const char * parser_manager_status_string(ParserManagerStatus status)
Return a human-readable string for a status code.
ParserManagerStatus
Status codes returned by ParserManager operations.
@ PM_ERR_DLOPEN_FAILED
Could not open shared library.
@ PM_ERR_DUPLICATE_NAME
A plugin with this name is already loaded.
@ PM_ERR_ABI_MISMATCH
Plugin ABI version incompatible.
@ PM_ERR_INIT_FAILED
Plugin init() callback returned false.
@ PM_ERR_INVALID_ARG
NULL or invalid argument.
@ PM_ERR_VALIDATION_FAILED
Snapshot validation failed.
@ PM_ERR_CAPABILITY_MISSING
Plugin lacks a required capability.
@ PM_ERR_NO_ENTRY_POINT
Shared library missing lime_plugin_entry.
@ PM_ERR_SNAPSHOT_FAILED
Plugin failed to create a snapshot.
@ PM_ERR_PLUGIN_NOT_FOUND
Handle does not refer to a loaded plugin.
@ PM_OK
Operation succeeded.
@ PM_ERR_NO_ACTIVE_PLUGIN
No active plugin set.
@ PM_ERR_ALLOC
Memory allocation failed.
@ PM_ERR_PLUGIN_IN_USE
Cannot unload: active sessions reference it.
LimePluginCaps
Bit flags describing what a plugin supports.
@ LIME_CAP_SNAPSHOT
Plugin produces ParserSnapshot objects.
@ LIME_CAP_INCREMENTAL
Plugin can produce incremental snapshots.
@ LIME_CAP_SERIALIZABLE
Plugin supports serializing/deserializing state.
@ LIME_CAP_JIT
Plugin's snapshots are JIT-compilable.
@ LIME_CAP_EXTENSIBLE
Plugin supports runtime grammar extension.
uint32_t LimePluginHandle
Opaque handle identifying a loaded parser plugin within a manager.
ParserManagerStatus parser_manager_list_plugins(const ParserManager *mgr, LimePluginInfo *infos, uint32_t max_count, uint32_t *actual_count)
Enumerate all loaded plugins.
ParserManagerStatus parser_manager_get_plugin_info(const ParserManager *mgr, LimePluginHandle handle, LimePluginInfo *info)
Get information about a specific plugin.
uint32_t parser_manager_plugin_count(const ParserManager *mgr)
Get the number of loaded plugins.
LimePluginHandle parser_manager_find_by_name(const ParserManager *mgr, const char *name)
Look up a plugin by name.
ParserManagerStatus parser_manager_load(ParserManager *mgr, const char *path, void *user_data, LimePluginHandle *handle_out)
Load a parser plugin from a shared library.
ParserManagerStatus parser_manager_register(ParserManager *mgr, const LimeParserPlugin *plugin, void *user_data, LimePluginHandle *handle_out)
Register a statically linked parser plugin.
ParserManagerStatus parser_manager_unload(ParserManager *mgr, LimePluginHandle handle)
Unload a previously loaded or registered plugin.
bool lime_plugin_has_capability(const LimeParserPlugin *plugin, LimePluginCaps cap)
Check if a plugin has a specific capability.
void lime_plugin_dump(const LimeParserPlugin *plugin, FILE *out)
Print a diagnostic summary of a plugin to a file stream.
bool lime_plugin_has_all_capabilities(const LimeParserPlugin *plugin, uint32_t required_caps)
Check if a plugin has all of the specified capabilities.
ParserManagerStatus lime_plugin_validate(const LimeParserPlugin *plugin)
Validate that a plugin struct has all required callbacks and a compatible ABI version.
const char * lime_plugin_capability_name(LimePluginCaps cap)
Return a human-readable name for a single capability flag.
char * lime_plugin_capabilities_string(uint32_t caps, char *buf, size_t buflen)
Format a capability bitmask as a comma-separated string of names.
bool lime_plugin_version_satisfies(LimePluginVersion actual, LimePluginVersion required)
Check if a plugin version satisfies a minimum requirement.
char * lime_plugin_version_string(LimePluginVersion v, char *buf, size_t buflen)
Format a version as a string.
int lime_plugin_version_compare(LimePluginVersion a, LimePluginVersion b)
Compare two plugin versions.
The plugin interface struct – the contract between the manager and a parser implementation.
uint32_t(* get_capabilities)(void)
Return a bitmask of LimePluginCaps describing this plugin.
bool(* validate_snapshot)(const ParserSnapshot *snap, char **error)
Validate that a snapshot is internally consistent.
uint16_t(* get_abi_major)(void)
Return the ABI major version this plugin was compiled against.
uint16_t(* get_abi_minor)(void)
Return the ABI minor version this plugin was compiled against.
void(* destroy)(void)
Teardown callback.
void * _reserved[8]
Reserved for ABI-compatible future additions.
bool(* init)(void *user_data)
One-time initialization.
LimePluginVersion(* get_version)(void)
Return the plugin's semantic version.
bool(* serialize_snapshot)(const ParserSnapshot *snap, uint8_t **buf_out, size_t *len_out)
Serialize a snapshot to a byte buffer.
Plugin information returned by enumeration functions.
bool is_active
True if this is the active plugin.
const char * name
Human-readable plugin name.
uint32_t capabilities
Bitmask of LimePluginCaps.
LimePluginVersion version
Plugin semantic version.
LimePluginHandle handle
Plugin handle.
bool is_dynamic
True if loaded from shared library.
Semantic version for a plugin.
uint16_t major
Major version (breaking changes)
uint16_t patch
Patch version (bug fixes)
uint16_t minor
Minor version (backwards-compatible additions)
Configuration for creating a ParserManager.
const char ** plugin_search_paths
Search paths for plugin shared libraries.
uint32_t max_plugins
Maximum number of plugins that can be registered simultaneously.
bool validate_on_load
If true, validate snapshots produced by plugins before use.
bool auto_jit
If true, attempt to JIT-compile snapshots from capable plugins.