46#ifndef GRAMMAR_CONTEXT_H
47#define 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)