Lime Parser Generator 0.1.0
Runtime-extensible LALR(1) parser with SIMD tokenization and LLVM JIT
Loading...
Searching...
No Matches
extension_registry.h
Go to the documentation of this file.
1
39#ifndef EXTENSION_REGISTRY_H
40#define EXTENSION_REGISTRY_H
41
42#include <stdbool.h>
43#include <stdint.h>
44#include <stddef.h>
45
46/* ------------------------------------------------------------------ */
47/* Forward declarations */
48/* ------------------------------------------------------------------ */
49
50struct ParserSnapshot;
51struct GrammarModification;
52
53/* ------------------------------------------------------------------ */
58/* ------------------------------------------------------------------ */
59
71
/* end disambig_strategy */
73
74/* ------------------------------------------------------------------ */
79/* ------------------------------------------------------------------ */
80
91
/* end exec_policy */
93
94/* ------------------------------------------------------------------ */
99/* ------------------------------------------------------------------ */
100
112
122typedef int (*OracleCallback)(const OracleContext *ctx);
123
/* end oracle_cb */
125
126/* ------------------------------------------------------------------ */
131/* ------------------------------------------------------------------ */
132
139typedef struct GrammarExtensionMetadata {
142 const char *name;
143 const char *version;
170
177 const char **requires;
178
185 const char **conflicts_with;
186
190 struct GrammarModification *modifications;
191
195
/* end ext_metadata */
197
198/* ------------------------------------------------------------------ */
203/* ------------------------------------------------------------------ */
204
207
/* end registry_handle */
209
210/* ------------------------------------------------------------------ */
215/* ------------------------------------------------------------------ */
216
221typedef struct ExtensionOrder {
222 char **names;
223 uint32_t count;
225
232
/* end ext_order */
234
235/* ------------------------------------------------------------------ */
240/* ------------------------------------------------------------------ */
241
250
264 const GrammarExtensionMetadata *metadata);
265
278 const char *name);
279
298 char **error_out);
299
312 ExtensionOrder *order_out,
313 char **error_out);
314
324 const char *name);
325
333
343 void *user_data);
344
356 ExtensionVisitorFn visitor,
357 void *user_data);
358
365
/* end registry_api */
367
368#endif /* EXTENSION_REGISTRY_H */
DisambiguationStrategy
How an extension prefers to resolve ambiguities introduced by its grammar modifications.
@ DISAMBIG_ORACLE
Delegate to a runtime oracle callback.
@ DISAMBIG_FORK_RESOLVE
Fork the parse and resolve after lookahead.
@ DISAMBIG_CONTEXT
Use grammar context to disambiguate.
@ DISAMBIG_PRIORITY
Resolve by numeric priority (higher wins)
@ DISAMBIG_NONE
No disambiguation; conflicts are errors.
ExecutionPolicy
Controls how an extension's modifications are applied relative to other extensions.
@ EXEC_PARALLEL
Apply concurrently where safe.
@ EXEC_SEQUENTIAL
Apply modifications one at a time.
@ EXEC_LAZY
Defer application until first use.
@ EXEC_PIPELINE
Apply as a pipeline stage.
void extension_order_destroy(ExtensionOrder *order)
Free an ExtensionOrder and all owned strings.
int(* OracleCallback)(const OracleContext *ctx)
Oracle callback type.
void extension_registry_foreach(const ExtensionRegistry *reg, ExtensionVisitorFn visitor, void *user_data)
Iterate over all registered extensions.
bool extension_registry_register(ExtensionRegistry *reg, const GrammarExtensionMetadata *metadata)
Register an extension with its metadata.
bool extension_registry_check_dependencies(ExtensionRegistry *reg, char **error_out)
Validate all dependency and conflict declarations.
bool extension_registry_unregister(ExtensionRegistry *reg, const char *name)
Unregister an extension by name.
uint32_t extension_registry_count(const ExtensionRegistry *reg)
Return the number of registered extensions.
void extension_registry_destroy(ExtensionRegistry *reg)
Destroy the registry and free all owned memory.
ExtensionRegistry * extension_registry_create(void)
Create an empty extension registry.
bool extension_registry_get_order(ExtensionRegistry *reg, ExtensionOrder *order_out, char **error_out)
Produce a topological ordering of all registered extensions.
const GrammarExtensionMetadata * extension_registry_find(ExtensionRegistry *reg, const char *name)
Look up an extension by name.
bool(* ExtensionVisitorFn)(const GrammarExtensionMetadata *meta, void *user_data)
Visitor callback for extension iteration.
struct ExtensionRegistry ExtensionRegistry
Opaque extension registry handle.
Result of dependency resolution: a sorted array of extension names in load order (dependencies before...
uint32_t count
Number of entries.
char ** names
malloc'd array of strdup'd names
Metadata describing a grammar extension participant in the execution pipeline.
DisambiguationStrategy strategy
How to resolve ambiguities.
const char * version
Semver string (required)
const char * name
Extension name (borrowed pointer)
int priority
Priority for DISAMBIG_PRIORITY (higher wins)
OracleCallback oracle
Callback for DISAMBIG_ORACLE (may be NULL)
ExecutionPolicy policy
How to apply modifications.
uint32_t nmodifications
Number of entries in the modifications array.
float conflict_threshold
Conflict threshold.
struct GrammarModification * modifications
Grammar modifications (may be NULL if provided later via load).
const char **const char ** conflicts_with
Dependencies.
Context passed to an oracle callback when the system needs a disambiguation decision.
void * user_data
Extension's user_data pointer.
const char * conflict_description
Human-readable conflict info.
const char ** candidate_labels
Labels for each candidate.
const char * extension_name
Extension requesting resolution.
int candidate_count
Number of candidate resolutions.
Opaque snapshot handle.
Definition snapshot.h:117