|
Lime Parser Generator 0.1.0
Runtime-extensible LALR(1) parser with SIMD tokenization and LLVM JIT
|
Create, manage, and query the grammar context stack. More...
Functions | |
| bool | grammar_context_close_bracket (GrammarContextStack *stack) |
| Notify the context stack that a bracket/parenthesis was closed. | |
| 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. | |
| ParserSnapshot * | grammar_context_current_snapshot (const GrammarContextStack *stack) |
| Return the snapshot for the current (topmost) grammar context. | |
| uint32_t | grammar_context_depth (const GrammarContextStack *stack) |
| Return the current nesting depth (0 = root). | |
| 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. | |
| bool | grammar_context_detect_switch (GrammarContextStack *stack, int token_code, const char *lexeme, uint32_t offset) |
| Detect whether a context switch should occur. | |
| bool | grammar_context_is_root_only (const GrammarContextStack *stack) |
| Check if only the root grammar is active. | |
| void | grammar_context_open_bracket (GrammarContextStack *stack) |
| Notify the context stack that a bracket/parenthesis was opened. | |
| bool | grammar_context_pop (GrammarContextStack *stack) |
| Pop the current grammar context. | |
| bool | grammar_context_push (GrammarContextStack *stack, GrammarMode mode, uint32_t offset) |
| Explicitly push a grammar mode onto the context stack. | |
| 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. | |
Create, manage, and query the grammar context stack.
| bool grammar_context_close_bracket | ( | GrammarContextStack * | stack | ) |
#include <include/grammar_context.h>
Notify the context stack that a bracket/parenthesis was closed.
May trigger an automatic context pop if the mode's depth returns to its entry depth.
| stack | The context stack. |
| true | A context pop was triggered by bracket close. |
| false | No pop occurred. |
| GrammarContextStack * grammar_context_create | ( | ParserSnapshot * | root_snapshot | ) |
#include <include/grammar_context.h>
Create a context stack with the given root grammar snapshot.
The root mode is MODE_SQL. Acquires a reference to root_snapshot.
| root_snapshot | Snapshot for the root (SQL) grammar. |
| GrammarMode grammar_context_current_mode | ( | const GrammarContextStack * | stack | ) |
#include <include/grammar_context.h>
Return the current grammar mode.
| stack | The context stack. |
| ParserSnapshot * grammar_context_current_snapshot | ( | const GrammarContextStack * | stack | ) |
#include <include/grammar_context.h>
Return the snapshot for the current (topmost) grammar context.
| stack | The context stack. |
| uint32_t grammar_context_depth | ( | const GrammarContextStack * | stack | ) |
#include <include/grammar_context.h>
Return the current nesting depth (0 = root).
| stack | The context stack. |
| void grammar_context_destroy | ( | GrammarContextStack * | stack | ) |
#include <include/grammar_context.h>
Destroy the context stack and release all snapshot references.
| stack | Stack to destroy. Passing NULL is safe. |
| bool grammar_context_detect_exit | ( | GrammarContextStack * | stack, |
| int | token_code | ||
| ) |
#include <include/grammar_context.h>
Detect whether the current embedded context should end.
If so, the context is popped and the function returns true. The caller should switch back to grammar_context_current_snapshot().
| stack | The context stack. |
| token_code | The token code just lexed. |
| true | Context was popped; previous mode is now active. |
| false | No exit detected; continue in the current mode. |
| bool grammar_context_detect_switch | ( | GrammarContextStack * | stack, |
| int | token_code, | ||
| const char * | lexeme, | ||
| uint32_t | offset | ||
| ) |
#include <include/grammar_context.h>
Detect whether a context switch should occur.
If a switch is detected, the appropriate context is pushed and the function returns true. The caller should then use grammar_context_current_snapshot() for subsequent parsing.
| stack | The context stack. |
| token_code | The token code just lexed. |
| lexeme | The lexeme text (may be NULL). |
| offset | Current offset in the input stream. |
| true | A context switch occurred; new mode is active. |
| false | No switch; continue with the current mode. |
| bool grammar_context_is_root_only | ( | const GrammarContextStack * | stack | ) |
#include <include/grammar_context.h>
Check if only the root grammar is active.
This is the fast-path check: if true, the parser can skip all mode-detection logic.
| stack | The context stack. |
| true | Only the root grammar is active (no embedded contexts). |
| false | One or more embedded contexts are active. |
| void grammar_context_open_bracket | ( | GrammarContextStack * | stack | ) |
#include <include/grammar_context.h>
Notify the context stack that a bracket/parenthesis was opened.
Used for depth tracking in modes that exit when their enclosing brackets close.
| stack | The context stack. |
| bool grammar_context_pop | ( | GrammarContextStack * | stack | ) |
#include <include/grammar_context.h>
Pop the current grammar context.
| stack | The context stack. |
| true | A context was popped. |
| false | Already at the root (nothing to pop). |
| bool grammar_context_push | ( | GrammarContextStack * | stack, |
| GrammarMode | mode, | ||
| uint32_t | offset | ||
| ) |
#include <include/grammar_context.h>
Explicitly push a grammar mode onto the context stack.
| stack | The context stack. |
| mode | Grammar mode to push. |
| offset | Current input offset. |
| true | Push succeeded. |
| false | Mode not registered or allocation failed. |
| bool grammar_context_register_mode | ( | GrammarContextStack * | stack, |
| const GrammarModeInfo * | info | ||
| ) |
#include <include/grammar_context.h>
Register a grammar mode.
The stack acquires a reference to the mode's snapshot.
| stack | Stack to register the mode with. |
| info | Mode descriptor. |
| true | Registration succeeded. |
| false | Mode already registered or allocation failed. |
| void grammar_context_set_switch_callback | ( | GrammarContextStack * | stack, |
| ContextSwitchCallback | cb, | ||
| void * | user_data | ||
| ) |
#include <include/grammar_context.h>
Register a callback to be invoked on context switches.
| stack | The context stack. |
| cb | Callback function (may be NULL to unregister). |
| user_data | Opaque pointer forwarded to cb. |