Lime Parser Generator 0.1.0
Runtime-extensible LALR(1) parser with SIMD tokenization and LLVM JIT
Loading...
Searching...
No Matches
multi_grammar.h
Go to the documentation of this file.
1
36#ifndef MULTI_GRAMMAR_H
37#define MULTI_GRAMMAR_H
38
39#include <stdbool.h>
40#include <stddef.h>
41#include <stdint.h>
42
43#include "parse_context.h" /* ParserSnapshot, LimeForkTrial, lime_simulate_parse */
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
49/* ================================================================== */
50/* Tier 1: full-statement fork-resolve */
51/* ================================================================== */
52
53/* Forward-declared here; the full typedef is in the Tier 2 section. */
54struct LimeBayesStore;
55
63typedef struct LimeForkCandidate {
65 int32_t priority;
66 uint32_t ext_id;
68
76
102int lime_mg_resolve(const LimeForkCandidate *cands, uint32_t ncands,
103 const int *lookahead, uint32_t nlook,
104 struct LimeBayesStore *bayes, uint16_t bayes_state,
105 uint16_t bayes_token, LimeForkRank *out_ranks);
106
107/* ================================================================== */
108/* Tier 2: Bayesian tie-break with persistence */
109/* ================================================================== */
110
113
116
119
124void lime_bayes_observe(LimeBayesStore *s, uint16_t state, uint16_t token,
125 uint32_t ext_id, bool success);
126
134int lime_bayes_rank(LimeBayesStore *s, uint16_t state, uint16_t token,
135 const uint32_t *ext_ids, uint32_t n, float *out_confidence);
136
143size_t lime_bayes_serialize(const LimeBayesStore *s, void *buf, size_t buflen);
144
149LimeBayesStore *lime_bayes_deserialize(const void *buf, size_t buflen);
150
151/* ================================================================== */
152/* Tier 3: dialect mode selection */
153/* ================================================================== */
154
157
160
166
175bool lime_dialect_register(LimeDialectRegistry *reg, const char *name, ParserSnapshot *snap);
176
185
203bool lime_dialect_parse_sigil(const LimeDialectRegistry *reg, const char *input,
204 ParserSnapshot **out_snap, size_t *out_offset);
205
206#ifdef __cplusplus
207}
208#endif
209
210#endif /* MULTI_GRAMMAR_H */
ParserSnapshot * lime_dialect_select(const LimeDialectRegistry *reg, const char *name)
Look up the composed snapshot for a dialect name.
bool lime_dialect_parse_sigil(const LimeDialectRegistry *reg, const char *input, ParserSnapshot **out_snap, size_t *out_offset)
Parse a leading @dialect sigil at the start of input.
struct LimeBayesStore LimeBayesStore
Opaque Beta-Bernoulli store keyed by (state, token, ext_id).
LimeDialectRegistry * lime_dialect_registry_create(void)
Create an empty dialect registry.
bool lime_dialect_register(LimeDialectRegistry *reg, const char *name, ParserSnapshot *snap)
Register a composed snapshot under a dialect name.
int lime_bayes_rank(LimeBayesStore *s, uint16_t state, uint16_t token, const uint32_t *ext_ids, uint32_t n, float *out_confidence)
Rank ext_ids at (state, token) by posterior mean.
LimeBayesStore * lime_bayes_create(void)
Create an empty store (entries allocated lazily).
int lime_mg_resolve(const LimeForkCandidate *cands, uint32_t ncands, const int *lookahead, uint32_t nlook, struct LimeBayesStore *bayes, uint16_t bayes_state, uint16_t bayes_token, LimeForkRank *out_ranks)
Resolve a collision by simulating each candidate over the upcoming token stream and ranking the outco...
void lime_bayes_destroy(LimeBayesStore *s)
Destroy a store.
LimeBayesStore * lime_bayes_deserialize(const void *buf, size_t buflen)
Rebuild a store from a blob produced by lime_bayes_serialize.
size_t lime_bayes_serialize(const LimeBayesStore *s, void *buf, size_t buflen)
Serialize the store to a flat blob for host-side persistence.
void lime_bayes_observe(LimeBayesStore *s, uint16_t state, uint16_t token, uint32_t ext_id, bool success)
Record that ext_id won at (state, token) and the parse success-ceeded – updates that arm's Beta poste...
struct LimeDialectRegistry LimeDialectRegistry
Opaque name -> composed-snapshot registry.
void lime_dialect_registry_destroy(LimeDialectRegistry *reg)
Destroy the registry.
One candidate grammar for a collision.
int32_t priority
Lower = preferred (final tie-break).
uint32_t ext_id
Extension id (Tier-2 Bayesian key).
const ParserSnapshot * snapshot
Grammar to simulate.
Per-candidate ranking detail (optional output of lime_mg_resolve).
bool tied_winner
True if it tied for first on Tier-1 metrics.
LimeForkTrial trial
How far this candidate got.
Opaque snapshot handle.
Definition snapshot.h:177