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, const char *library_path,
70 const char *grammar_file, void *user_data);
71
72/*
73** Register a static plugin and activate it immediately.
74**
75** Equivalent to:
76** 1. parser_manager_register(mgr, plugin, user_data, &handle)
77** 2. parser_manager_set_active(mgr, handle, grammar_file)
78**
79** If step 2 fails, the plugin is automatically unloaded.
80*/
81ParserOpResult parser_op_add_static(ParserManager *mgr, const LimeParserPlugin *plugin,
82 const char *grammar_file, void *user_data);
83
84/* ================================================================== */
85/* Remove operations */
86/* ================================================================== */
87
88/*
89** Remove a parser by handle.
90**
91** If the parser is currently active:
92** - If fallback_handle is not LIME_PLUGIN_HANDLE_INVALID, activates
93** the fallback plugin (with fallback_grammar if non-NULL) before
94** removing the target.
95** - If fallback_handle is INVALID, deactivates the target and leaves
96** no active parser.
97**
98** Returns PM_OK on success.
99*/
100ParserOpResult parser_op_remove(ParserManager *mgr, LimePluginHandle handle,
101 LimePluginHandle fallback_handle, const char *fallback_grammar);
102
103/*
104** Remove a parser by name.
105**
106** Looks up the plugin by name and delegates to parser_op_remove().
107*/
108ParserOpResult parser_op_remove_by_name(ParserManager *mgr, const char *name,
109 LimePluginHandle fallback_handle,
110 const char *fallback_grammar);
111
112/* ================================================================== */
113/* Update operations */
114/* ================================================================== */
115
116/*
117** Update (replace) the active parser with a new plugin version.
118**
119** Loads the new plugin from new_library_path, creates a snapshot from
120** grammar_file, validates it (if the plugin supports validation), and
121** atomically swaps it in as the active parser via hot_swap.
122**
123** If any step fails, the old parser remains active and the new plugin
124** is unloaded. The operation is all-or-nothing.
125**
126** If new_library_path is NULL, re-uses the currently active plugin
127** (useful for reloading a grammar without changing the plugin binary).
128**
129** version_check: if true, the new plugin must have a version >= the
130** current active plugin. Set to false to allow downgrades.
131*/
132ParserOpResult parser_op_update(ParserManager *mgr, const char *new_library_path,
133 const char *grammar_file, bool version_check, void *user_data);
134
135/*
136** Reload the grammar for the currently active plugin.
137**
138** Creates a new snapshot from grammar_file using the current active
139** plugin and atomically replaces the active snapshot. The plugin
140** itself is not unloaded or replaced.
141**
142** Useful for picking up grammar file changes at runtime.
143*/
144ParserOpResult parser_op_reload_grammar(ParserManager *mgr, const char *grammar_file);
145
146/* ================================================================== */
147/* Query operations */
148/* ================================================================== */
149
164
165/*
166** Collect runtime statistics about the parser manager.
167**
168** The returned stats struct contains pointers into plugin-owned
169** memory (active_name). These are valid only while the plugin
170** remains loaded. Copy the string if you need to keep it.
171*/
172ParserOpResult parser_op_get_stats(const ParserManager *mgr, ParserManagerStats *stats);
173
174/*
175** Write a formatted summary of all loaded plugins to the given stream.
176**
177** Output format:
178** [1] sql_parser v1.2.3 (active) [snapshot, extensible, jit]
179** [2] json_parser v2.0.0 [snapshot]
180**
181** Returns PM_OK on success.
182*/
183ParserOpResult parser_op_list_formatted(const ParserManager *mgr, FILE *out);
184
185/*
186** Check if a specific plugin version is loaded by name.
187**
188** If min_version is non-NULL, returns true only if a plugin with
189** the given name is loaded AND its version >= *min_version.
190** If min_version is NULL, returns true if any version is loaded.
191*/
192bool parser_op_is_loaded(const ParserManager *mgr, const char *name,
193 const LimePluginVersion *min_version);
194
195#ifdef __cplusplus
196}
197#endif
198
199#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.