Lime Parser Generator 0.1.0
Runtime-extensible LALR(1) parser with SIMD tokenization and LLVM JIT
Loading...
Searching...
No Matches
parser.h File Reference

Core public API for the Lime Parser library. More...

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Functions

ParserSnapshotlime_compile_grammar_text (const char *grammar_text, size_t len, char **error)
 Build a base snapshot from in-memory grammar text.
 
void lime_extension_registry_destroy (void)
 Destroy the global extension registry.
 
bool lime_extension_registry_init (void)
 Initialize the global extension registry.
 
bool lime_jit_available (void)
 Check whether JIT compilation support is available at runtime.
 
int lime_jit_compile (ParserSnapshot *snap)
 Compile and attach JIT code to a snapshot's action tables.
 
const char * lime_parser_version (void)
 Return the Lime parser library version string.
 
ParserSnapshotlime_snapshot_acquire (ParserSnapshot *snap)
 Acquire a reference to a snapshot.
 
ParserSnapshotlime_snapshot_create (const char *grammar_file, char **error)
 Create a base snapshot by parsing a grammar file.
 
uint16_t lime_snapshot_first_token (const ParserSnapshot *snap)
 The first_token offset baked into a snapshot.
 
void lime_snapshot_release (ParserSnapshot *snap)
 Release a snapshot reference.
 
int lime_snapshot_token_code (const ParserSnapshot *snap, const char *name)
 Map a token name to its external code in a snapshot.
 
ParseContextparse_begin (ParserSnapshot *snap)
 Begin a parse session pinned to a snapshot.
 
void parse_end (ParseContext *ctx)
 End the parse session.
 
ParserSnapshotparse_get_snapshot (ParseContext *ctx)
 Return the snapshot pinned by this context.
 
int parse_token (ParseContext *ctx, int token_code, void *token_value, int location)
 Feed a token to the parser.
 

Detailed Description

Core public API for the Lime Parser library.

This is the main header for consumers of the Lime runtime library. It provides:

  • Snapshot lifecycle (create, acquire, release)
  • Parse session management (begin, token, end)
  • JIT compilation control
  • Extension registry initialization
Basic Usage
// Create a snapshot from a grammar file
char *error = NULL;
ParserSnapshot *snap = lime_snapshot_create("sql.y", &error);
if (!snap) { fprintf(stderr, "%s\n", error); free(error); return 1; }
// Begin a parse session
ParseContext *ctx = parse_begin(snap);
// Feed tokens
parse_token(ctx, TK_SELECT, NULL, LIME_LOC_UNKNOWN);
parse_token(ctx, TK_STAR, NULL, LIME_LOC_UNKNOWN);
parse_token(ctx, 0, NULL, LIME_LOC_UNKNOWN); // end-of-input
// End the session
parse_end(ctx);
ParserSnapshot * lime_snapshot_create(const char *grammar_file, char **error)
Create a base snapshot by parsing a grammar file.
void lime_snapshot_release(ParserSnapshot *snap)
Release a snapshot reference.
Per-parse-session state.
Opaque snapshot handle.
Definition snapshot.h:177
See also
parser_manager.h for plugin-based parser management.
snapshot.h for the full ParserSnapshot definition.

Definition in file parser.h.

Function Documentation

◆ lime_parser_version()

const char * lime_parser_version ( void  )

Return the Lime parser library version string.

Returns
Static NUL-terminated version string (e.g. "0.1.0").