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, uint32_t nextensions);
149
162 bool (*resolve)(void *strategy_context, const ConflictPoint *conflict,
163 struct ParseContext *parse_ctx, int lookahead, StrategyResult *result);
164
175 void (*update)(void *strategy_context, struct ExtensionRegistry *registry, bool success);
176
182 void (*destroy)(void *strategy_context);
183
185
/* end strat_vtable */
187
188/* ================================================================== */
193/* ================================================================== */
194
197
/* end disambig_ctx */
199
200/* ================================================================== */
205/* ================================================================== */
206
219
230 struct ExtensionRegistry *reg);
231
242 struct ParseContext *parse_ctx);
243
254
262
270
277
/* end disambig_api */
279
280#ifdef __cplusplus
281}
282#endif
283
284#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:213
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:201
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.