Lime Parser Generator 0.1.0
Runtime-extensible LALR(1) parser with SIMD tokenization and LLVM JIT
Loading...
Searching...
No Matches
disambiguation.h
Go to the documentation of this file.
1
37#ifndef DISAMBIGUATION_H
38#define DISAMBIGUATION_H
39
40#include <stdint.h>
41#include <stdbool.h>
42#include <stddef.h>
43
44/* LimeContext and ConflictPoint are defined here */
45#include "conflict.h"
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
51/* Forward declarations */
53struct Extension;
54struct ParseContext;
55
56/* ================================================================== */
61/* ================================================================== */
62
79
/* end strat_ids */
81
82/* ================================================================== */
87/* ================================================================== */
88
102
109
119
/* end strat_result */
121
122/* ================================================================== */
127/* ================================================================== */
128
148 void *(*init)(const struct Extension *const *extensions,
149 uint32_t nextensions);
150
163 bool (*resolve)(void *strategy_context,
164 const ConflictPoint *conflict,
165 struct ParseContext *parse_ctx,
166 int lookahead,
167 StrategyResult *result);
168
179 void (*update)(void *strategy_context,
180 struct ExtensionRegistry *registry,
181 bool success);
182
188 void (*destroy)(void *strategy_context);
189
191
/* end strat_vtable */
193
194/* ================================================================== */
199/* ================================================================== */
200
203
/* end disambig_ctx */
205
206/* ================================================================== */
211/* ================================================================== */
212
225 LimeStrategy strategy,
226 struct ExtensionRegistry *reg);
227
238 const DisambiguationStrategyVTable *vtable,
239 struct ExtensionRegistry *reg);
240
252 const ConflictPoint *conflict,
253 struct ParseContext *parse_ctx);
254
266 bool success);
267
275 const DisambiguationContext *ctx);
276
284
291
/* end disambig_api */
293
294#ifdef __cplusplus
295}
296#endif
297
298#endif /* DISAMBIGUATION_H */
Conflict detection for the extension system.
StrategyResult disambiguation_resolve(DisambiguationContext *ctx, const ConflictPoint *conflict, struct ParseContext *parse_ctx)
Resolve a conflict using the configured strategy.
DisambiguationContext * disambiguation_create(LimeStrategy strategy, struct ExtensionRegistry *reg)
Create a disambiguation context using a built-in strategy.
const char * disambiguation_strategy_name(LimeStrategy strategy)
Get the name of a strategy as a string.
DisambiguationContext * disambiguation_create_custom(const DisambiguationStrategyVTable *vtable, struct ExtensionRegistry *reg)
Create a disambiguation context using a user-supplied vtable.
void disambiguation_destroy(DisambiguationContext *ctx)
Destroy a disambiguation context and free all resources.
LimeStrategy disambiguation_get_strategy(const DisambiguationContext *ctx)
Get the strategy type used by this context.
void disambiguation_update(DisambiguationContext *ctx, bool success)
Provide feedback after a parse.
struct DisambiguationContext DisambiguationContext
Opaque disambiguation context handle.
struct ExtensionRegistry ExtensionRegistry
Opaque extension registry handle.
LimeStrategy
Enumeration of available disambiguation strategies.
@ STRAT_FORK_RESOLVE
Fork parse, try each, pick survivor.
@ STRAT_PRIORITY
Resolve by extension priority metadata.
@ STRAT_LLM
Query LLM oracle for resolution advice.
@ STRAT_CUSTOM
User-provided vtable.
@ STRAT_BAYESIAN
Evidence accumulation (posterior probs)
void strategy_result_cleanup(StrategyResult *result)
Free memory owned by a StrategyResult.
void strategy_result_init(StrategyResult *result)
Initialize a StrategyResult to a safe empty state.
A specific ambiguity where multiple grammars can handle the same token in the same parser state.
Definition conflict.h:227
Function pointer table for a disambiguation strategy implementation.
void(* destroy)(void *strategy_context)
Tear down the strategy and free all resources.
bool(* resolve)(void *strategy_context, const ConflictPoint *conflict, struct ParseContext *parse_ctx, int lookahead, StrategyResult *result)
Resolve a single conflict.
void(* update)(void *strategy_context, struct ExtensionRegistry *registry, bool success)
Provide feedback after a parse completes.
A grammar context – one possible interpretation of a token within a particular grammar/extension.
Definition conflict.h:215
Per-parse-session state.
The result of a disambiguation resolution.
LimeContext * winning_contexts
Array of winners (malloc'd)
char * explanation
Human-readable reason (malloc'd, may be NULL)
int nwinners
Number of winners (usually 1)
float confidence
Confidence: 0.0 = no idea, 1.0 = certain.