Lime Parser Generator 0.1.0
Runtime-extensible LALR(1) parser with SIMD tokenization and LLVM JIT
Loading...
Searching...
No Matches
parser_operations.h
1/*
2** Parser Operations - High-level runtime parser management operations.
3**
4** Builds on the ParserManager primitives to provide production-ready
5** workflows for common parser management tasks:
6**
7** - Add and activate a parser in one call
8** - Update a parser with automatic rollback on failure
9** - Safely remove a parser (deactivate-first semantics)
10** - Reload a parser's grammar without changing plugins
11** - Enumerate parsers with formatted output
12** - Collect runtime statistics
13**
14** These are convenience functions that compose the lower-level
15** parser_manager_* API. They add error recovery, logging, and
16** version-aware upgrade logic that applications would otherwise
17** need to implement themselves.
18**
19** Thread safety: All functions are thread-safe. They acquire the
20** appropriate locks internally via the ParserManager.
21*/
22#ifndef PARSER_OPERATIONS_H
23#define PARSER_OPERATIONS_H
24
25#include "parser_manager.h"
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31/* ================================================================== */
32/* Operation result with detail */
33/* ================================================================== */
34
46
47/*
48** Free the message inside a ParserOpResult (if any).
49** Does not free the result struct itself (it is stack-allocated).
50*/
51void parser_op_result_cleanup(ParserOpResult *result);
52
53/* ================================================================== */
54/* Add operations */
55/* ================================================================== */
56
57/*
58** Load a plugin from a shared library and activate it immediately.
59**
60** Equivalent to:
61** 1. parser_manager_load(mgr, library_path, user_data, &handle)
62** 2. parser_manager_set_active(mgr, handle, grammar_file)
63**
64** If step 2 fails, the plugin is automatically unloaded (rolled back).
65**
66** grammar_file may be NULL to load the plugin without activating a
67** grammar (the plugin is registered but no snapshot is created).
68*/
69ParserOpResult parser_op_add_dynamic(ParserManager *mgr,
70 const char *library_path,
71 const char *grammar_file,
72 void *user_data);
73
74/*
75** Register a static plugin and activate it immediately.
76**
77** Equivalent to:
78** 1. parser_manager_register(mgr, plugin, user_data, &handle)
79** 2. parser_manager_set_active(mgr, handle, grammar_file)
80**
81** If step 2 fails, the plugin is automatically unloaded.
82*/
83ParserOpResult parser_op_add_static(ParserManager *mgr,
84 const LimeParserPlugin *plugin,
85 const char *grammar_file,
86 void *user_data);
87
88/* ================================================================== */
89/* Remove operations */
90/* ================================================================== */
91
92/*
93** Remove a parser by handle.
94**
95** If the parser is currently active:
96** - If fallback_handle is not LIME_PLUGIN_HANDLE_INVALID, activates
97** the fallback plugin (with fallback_grammar if non-NULL) before
98** removing the target.
99** - If fallback_handle is INVALID, deactivates the target and leaves
100** no active parser.
101**
102** Returns PM_OK on success.
103*/
104ParserOpResult parser_op_remove(ParserManager *mgr,
105 LimePluginHandle handle,
106 LimePluginHandle fallback_handle,
107 const char *fallback_grammar);
108
109/*
110** Remove a parser by name.
111**
112** Looks up the plugin by name and delegates to parser_op_remove().
113*/
114ParserOpResult parser_op_remove_by_name(ParserManager *mgr,
115 const char *name,
116 LimePluginHandle fallback_handle,
117 const char *fallback_grammar);
118
119/* ================================================================== */
120/* Update operations */
121/* ================================================================== */
122
123/*
124** Update (replace) the active parser with a new plugin version.
125**
126** Loads the new plugin from new_library_path, creates a snapshot from
127** grammar_file, validates it (if the plugin supports validation), and
128** atomically swaps it in as the active parser via hot_swap.
129**
130** If any step fails, the old parser remains active and the new plugin
131** is unloaded. The operation is all-or-nothing.
132**
133** If new_library_path is NULL, re-uses the currently active plugin
134** (useful for reloading a grammar without changing the plugin binary).
135**
136** version_check: if true, the new plugin must have a version >= the
137** current active plugin. Set to false to allow downgrades.
138*/
139ParserOpResult parser_op_update(ParserManager *mgr,
140 const char *new_library_path,
141 const char *grammar_file,
142 bool version_check,
143 void *user_data);
144
145/*
146** Reload the grammar for the currently active plugin.
147**
148** Creates a new snapshot from grammar_file using the current active
149** plugin and atomically replaces the active snapshot. The plugin
150** itself is not unloaded or replaced.
151**
152** Useful for picking up grammar file changes at runtime.
153*/
154ParserOpResult parser_op_reload_grammar(ParserManager *mgr,
155 const char *grammar_file);
156
157/* ================================================================== */
158/* Query operations */
159/* ================================================================== */
160
175
176/*
177** Collect runtime statistics about the parser manager.
178**
179** The returned stats struct contains pointers into plugin-owned
180** memory (active_name). These are valid only while the plugin
181** remains loaded. Copy the string if you need to keep it.
182*/
183ParserOpResult parser_op_get_stats(const ParserManager *mgr,
184 ParserManagerStats *stats);
185
186/*
187** Write a formatted summary of all loaded plugins to the given stream.
188**
189** Output format:
190** [1] sql_parser v1.2.3 (active) [snapshot, extensible, jit]
191** [2] json_parser v2.0.0 [snapshot]
192**
193** Returns PM_OK on success.
194*/
195ParserOpResult parser_op_list_formatted(const ParserManager *mgr,
196 FILE *out);
197
198/*
199** Check if a specific plugin version is loaded by name.
200**
201** If min_version is non-NULL, returns true only if a plugin with
202** the given name is loaded AND its version >= *min_version.
203** If min_version is NULL, returns true if any version is loaded.
204*/
205bool parser_op_is_loaded(const ParserManager *mgr,
206 const char *name,
207 const LimePluginVersion *min_version);
208
209#ifdef __cplusplus
210}
211#endif
212
213#endif /* PARSER_OPERATIONS_H */
struct ParserManager ParserManager
Opaque parser manager handle.
ParserManagerStatus
Status codes returned by ParserManager operations.
uint32_t LimePluginHandle
Opaque handle identifying a loaded parser plugin within a manager.
Parser Manager – runtime parser plugin management system.
The plugin interface struct – the contract between the manager and a parser implementation.
Semantic version for a plugin.
Runtime statistics for the parser manager.
uint32_t dynamic_plugins
Loaded from shared libraries.
const char * active_name
Name of active plugin, or NULL.
bool has_active
Whether an active plugin is set.
uint32_t active_capabilities
Bitmap of capabilities advertised by the active plugin.
uint32_t static_plugins
Registered statically.
bool snapshot_available
Whether get_snapshot would return non-NULL.
uint32_t total_plugins
Currently loaded plugins.
LimePluginVersion active_version
Version of the active plugin.
LimePluginHandle active_handle
Handle of the active plugin.
Extended result from a high-level operation.
char * message
Malloc'd detail string, or NULL.
LimePluginHandle handle
Relevant handle, or INVALID.
ParserManagerStatus status
Operation status code.