Lime Parser Generator 0.1.0
Runtime-extensible LALR(1) parser with SIMD tokenization and LLVM JIT
Loading...
Searching...
No Matches
grammar_context.h
Go to the documentation of this file.
1
46#ifndef GRAMMAR_CONTEXT_H
47#define GRAMMAR_CONTEXT_H
48
49#include <stdbool.h>
50#include <stdint.h>
51
52/* ------------------------------------------------------------------ */
53/* Forward declarations */
54/* ------------------------------------------------------------------ */
55
56typedef struct ParserSnapshot ParserSnapshot;
57
58/* ------------------------------------------------------------------ */
63/* ------------------------------------------------------------------ */
64
77
/* end grammar_modes */
79
80/* ------------------------------------------------------------------ */
85/* ------------------------------------------------------------------ */
86
97
/* end ctx_entry */
99
100/* ------------------------------------------------------------------ */
105/* ------------------------------------------------------------------ */
106
138
/* end mode_info */
140
141/* ------------------------------------------------------------------ */
146/* ------------------------------------------------------------------ */
147
150
/* end ctx_stack */
152
153/* ------------------------------------------------------------------ */
158/* ------------------------------------------------------------------ */
159
172typedef bool (*ContextSwitchCallback)(GrammarMode prev_mode,
173 GrammarMode new_mode,
174 void *user_data);
175
/* end ctx_switch_cb */
177
178/* ------------------------------------------------------------------ */
183/* ------------------------------------------------------------------ */
184
196
203
215 const GrammarModeInfo *info);
216
232 int token_code,
233 const char *lexeme,
234 uint32_t offset);
235
248 int token_code);
249
260 GrammarMode mode,
261 uint32_t offset);
262
271
279 const GrammarContextStack *stack);
280
288 const GrammarContextStack *stack);
289
297
307 void *user_data);
308
318
330
342
/* end grammar_ctx_api */
344
345#endif /* GRAMMAR_CONTEXT_H */
struct GrammarContextStack GrammarContextStack
Opaque grammar context stack handle.
bool(* ContextSwitchCallback)(GrammarMode prev_mode, GrammarMode new_mode, void *user_data)
Called when a context switch occurs.
bool grammar_context_pop(GrammarContextStack *stack)
Pop the current grammar context.
GrammarContextStack * grammar_context_create(ParserSnapshot *root_snapshot)
Create a context stack with the given root grammar snapshot.
GrammarMode grammar_context_current_mode(const GrammarContextStack *stack)
Return the current grammar mode.
void grammar_context_destroy(GrammarContextStack *stack)
Destroy the context stack and release all snapshot references.
bool grammar_context_detect_exit(GrammarContextStack *stack, int token_code)
Detect whether the current embedded context should end.
ParserSnapshot * grammar_context_current_snapshot(const GrammarContextStack *stack)
Return the snapshot for the current (topmost) grammar context.
bool grammar_context_is_root_only(const GrammarContextStack *stack)
Check if only the root grammar is active.
bool grammar_context_register_mode(GrammarContextStack *stack, const GrammarModeInfo *info)
Register a grammar mode.
void grammar_context_set_switch_callback(GrammarContextStack *stack, ContextSwitchCallback cb, void *user_data)
Register a callback to be invoked on context switches.
bool grammar_context_push(GrammarContextStack *stack, GrammarMode mode, uint32_t offset)
Explicitly push a grammar mode onto the context stack.
uint32_t grammar_context_depth(const GrammarContextStack *stack)
Return the current nesting depth (0 = root).
bool grammar_context_close_bracket(GrammarContextStack *stack)
Notify the context stack that a bracket/parenthesis was closed.
void grammar_context_open_bracket(GrammarContextStack *stack)
Notify the context stack that a bracket/parenthesis was opened.
bool grammar_context_detect_switch(GrammarContextStack *stack, int token_code, const char *lexeme, uint32_t offset)
Detect whether a context switch should occur.
GrammarMode
Grammar mode identifiers.
@ MODE_CUSTOM
User-defined / extension grammar.
@ MODE_JSON
JSON embedded literal.
@ MODE_SQL
Standard SQL (root grammar)
@ MODE_COUNT_
Sentinel (number of built-in modes)
@ MODE_XPATH
XPath embedded expression.
@ MODE_XQUERY
XQuery embedded expression.
@ MODE_EDN
EDN (Extensible Data Notation)
One level of the grammar context stack.
int depth
Nesting depth (for bracket matching)
ParserSnapshot * snapshot
Snapshot for this grammar.
const char * mode_name
Human-readable name (borrowed)
GrammarMode mode
Active grammar mode.
uint32_t start_offset
Input offset where mode began.
Describes a grammar mode that can be entered during parsing.
const char * name
Human-readable name.
GrammarMode mode
Which mode this describes.
const char * trigger_lexeme
Entry trigger: lexeme prefix that initiates this mode.
int trigger_token
Entry trigger: token code that initiates this mode.
int exit_token
Exit trigger: token code that terminates this mode.
ParserSnapshot * snapshot
Snapshot to use (reference acquired)
Opaque snapshot handle.
Definition snapshot.h:117