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,
278 char **error);
279
290 bool (*validate_snapshot)(const ParserSnapshot *snap, char **error);
291
292 /* -------------------------------------------------------------- */
293 /* Serialization (optional, requires LIME_CAP_SERIALIZABLE) */
294 /* -------------------------------------------------------------- */
295
307 uint8_t **buf_out,
308 size_t *len_out);
309
319 ParserSnapshot *(*deserialize_snapshot)(const uint8_t *buf,
320 size_t len,
321 char **error);
322
323 /* -------------------------------------------------------------- */
324 /* Reserved for future expansion */
325 /* -------------------------------------------------------------- */
326
327 void *_reserved[8];
330
/* end plugin_interface */
332
333/* ================================================================== */
338/* ================================================================== */
339
357typedef const LimeParserPlugin *(*LimePluginEntryFn)(void);
358
360#define LIME_PLUGIN_ENTRY_SYMBOL "lime_plugin_entry"
361
372#ifdef _WIN32
373 #define LIME_PLUGIN_EXPORT __declspec(dllexport)
374#else
375 #define LIME_PLUGIN_EXPORT __attribute__((visibility("default")))
376#endif
377
/* end plugin_entry */
379
380/* ================================================================== */
385/* ================================================================== */
386
392typedef struct ParserManagerConfig {
398 uint32_t max_plugins;
399
407
414
423
425
/* end manager_config */
427
428/* ================================================================== */
433/* ================================================================== */
434
454
462
/* end manager_status */
464
465/* ================================================================== */
470/* ================================================================== */
471
474
/* end manager_handle */
476
477/* ================================================================== */
482/* ================================================================== */
483
495
509
/* end manager_lifecycle */
511
512/* ================================================================== */
517/* ================================================================== */
518
544 const char *path,
545 void *user_data,
546 LimePluginHandle *handle_out);
547
562 const LimeParserPlugin *plugin,
563 void *user_data,
564 LimePluginHandle *handle_out);
565
582 LimePluginHandle handle);
583
/* end plugin_loading */
585
586/* ================================================================== */
591/* ================================================================== */
592
611 LimePluginHandle handle,
612 const char *grammar_file);
613
622
637 ParserSnapshot *snap);
638
651
/* end active_parser */
653
654/* ================================================================== */
659/* ================================================================== */
660
675
685 LimePluginHandle handle,
686 LimePluginInfo *info);
687
701 LimePluginInfo *infos,
702 uint32_t max_count,
703 uint32_t *actual_count);
704
714 const char *name);
715
723
/* end plugin_introspection */
725
726/* ================================================================== */
731/* ================================================================== */
732
753 LimePluginHandle new_handle,
754 const char *grammar_file);
755
/* end hot_swap */
757
758/* ================================================================== */
763/* ================================================================== */
764
773
783 LimePluginVersion required);
784
795char *lime_plugin_version_string(LimePluginVersion v, char *buf, size_t buflen);
796
/* end version_utils */
798
799/* ================================================================== */
804/* ================================================================== */
805
815
825 LimePluginCaps cap);
826
836 uint32_t required_caps);
837
846
855char *lime_plugin_capabilities_string(uint32_t caps, char *buf, size_t buflen);
856
865void lime_plugin_dump(const LimeParserPlugin *plugin, FILE *out);
866
/* end plugin_validation */
868
869#ifdef __cplusplus
870}
871#endif
872
873#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:117