Lime Parser Generator 0.1.0
Runtime-extensible LALR(1) parser with SIMD tokenization and LLVM JIT
Loading...
Searching...
No Matches
parser_manager.h
Go to the documentation of this file.
1
69#ifndef PARSER_MANAGER_H
70#define PARSER_MANAGER_H
71
72#include <stdint.h>
73#include <stdbool.h>
74#include <stddef.h>
75#include <stdio.h>
76
77#ifdef __cplusplus
78extern "C" {
79#endif
80
81/* Forward declarations */
82typedef struct ParserSnapshot ParserSnapshot;
83typedef struct ParseContext ParseContext;
84
85/* ================================================================== */
90/* ================================================================== */
91
97typedef uint32_t LimePluginHandle;
98
100#define LIME_PLUGIN_HANDLE_INVALID ((LimePluginHandle)0)
101
/* end plugin_handle */
103
104/* ================================================================== */
109/* ================================================================== */
110
124
/* end plugin_caps */
126
127/* ================================================================== */
132/* ================================================================== */
133
139typedef struct LimePluginVersion {
140 uint16_t major;
141 uint16_t minor;
142 uint16_t patch;
144
151#define LIME_PLUGIN_ABI_VERSION_MAJOR 1
152
154#define LIME_PLUGIN_ABI_VERSION_MINOR 0
155
/* end plugin_version */
157
158/* ================================================================== */
163/* ================================================================== */
164
192typedef struct LimeParserPlugin {
193 /* -------------------------------------------------------------- */
194 /* Identity */
195 /* -------------------------------------------------------------- */
196
202 const char *(*get_name)(void);
203
209
217 uint16_t (*get_abi_major)(void);
218
223 uint16_t (*get_abi_minor)(void);
224
229 uint32_t (*get_capabilities)(void);
230
231 /* -------------------------------------------------------------- */
232 /* Lifecycle */
233 /* -------------------------------------------------------------- */
234
248 bool (*init)(void *user_data);
249
260 void (*destroy)(void);
261
262 /* -------------------------------------------------------------- */
263 /* Snapshot production */
264 /* -------------------------------------------------------------- */
265
277 ParserSnapshot *(*create_snapshot)(const char *grammar_file, char **error);
278
289 bool (*validate_snapshot)(const ParserSnapshot *snap, char **error);
290
291 /* -------------------------------------------------------------- */
292 /* Serialization (optional, requires LIME_CAP_SERIALIZABLE) */
293 /* -------------------------------------------------------------- */
294
305 bool (*serialize_snapshot)(const ParserSnapshot *snap, uint8_t **buf_out, size_t *len_out);
306
316 ParserSnapshot *(*deserialize_snapshot)(const uint8_t *buf, size_t len, char **error);
317
318 /* -------------------------------------------------------------- */
319 /* Reserved for future expansion */
320 /* -------------------------------------------------------------- */
321
322 void *_reserved[8];
325
/* end plugin_interface */
327
328/* ================================================================== */
333/* ================================================================== */
334
352typedef const LimeParserPlugin *(*LimePluginEntryFn)(void);
353
355#define LIME_PLUGIN_ENTRY_SYMBOL "lime_plugin_entry"
356
367#ifdef _WIN32
368#define LIME_PLUGIN_EXPORT __declspec(dllexport)
369#else
370#define LIME_PLUGIN_EXPORT __attribute__((visibility("default")))
371#endif
372
/* end plugin_entry */
374
375/* ================================================================== */
380/* ================================================================== */
381
387typedef struct ParserManagerConfig {
393 uint32_t max_plugins;
394
402
409
418
420
/* end manager_config */
422
423/* ================================================================== */
428/* ================================================================== */
429
449
457
/* end manager_status */
459
460/* ================================================================== */
465/* ================================================================== */
466
469
/* end manager_handle */
471
472/* ================================================================== */
477/* ================================================================== */
478
490
504
/* end manager_lifecycle */
506
507/* ================================================================== */
512/* ================================================================== */
513
538ParserManagerStatus parser_manager_load(ParserManager *mgr, const char *path, void *user_data,
539 LimePluginHandle *handle_out);
540
555 void *user_data, LimePluginHandle *handle_out);
556
573
/* end plugin_loading */
575
576/* ================================================================== */
581/* ================================================================== */
582
601 const char *grammar_file);
602
611
626
639
/* end active_parser */
641
642/* ================================================================== */
647/* ================================================================== */
648
663
673 LimePluginHandle handle, LimePluginInfo *info);
674
688 uint32_t max_count, uint32_t *actual_count);
689
699
707
/* end plugin_introspection */
709
710/* ================================================================== */
715/* ================================================================== */
716
737 const char *grammar_file);
738
/* end hot_swap */
740
741/* ================================================================== */
746/* ================================================================== */
747
756
766
777char *lime_plugin_version_string(LimePluginVersion v, char *buf, size_t buflen);
778
/* end version_utils */
780
781/* ================================================================== */
786/* ================================================================== */
787
797
807
816bool lime_plugin_has_all_capabilities(const LimeParserPlugin *plugin, uint32_t required_caps);
817
826
835char *lime_plugin_capabilities_string(uint32_t caps, char *buf, size_t buflen);
836
845void lime_plugin_dump(const LimeParserPlugin *plugin, FILE *out);
846
/* end plugin_validation */
848
849#ifdef __cplusplus
850}
851#endif
852
853#endif /* PARSER_MANAGER_H */
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)
Per-parse-session state.
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.
Opaque snapshot handle.
Definition snapshot.h:177