Lime Parser Generator
0.1.0
Runtime-extensible LALR(1) parser with SIMD tokenization and LLVM JIT
Loading...
Searching...
No Matches
parse_context.h
1
/*
2
** Parse context - manages parser state for a single parse session
3
**
4
** The parse context pins a snapshot for the duration of parsing,
5
** ensuring grammar stability even if extensions are modified.
6
*/
7
#ifndef PARSE_CONTEXT_H
8
#define PARSE_CONTEXT_H
9
10
#include "snapshot.h"
11
12
/* Forward declaration (full definition in parser.h) */
13
typedef
struct
ParseContext
ParseContext
;
14
22
struct
ParseContext
{
23
ParserSnapshot
*
snapshot
;
24
};
25
26
/*
27
** Create a parse context with the given snapshot.
28
** Acquires a reference to the snapshot.
29
*/
30
ParseContext
*parse_context_create(
ParserSnapshot
*snap);
31
32
/*
33
** Destroy a parse context, releasing the snapshot.
34
*/
35
void
parse_context_destroy(
ParseContext
*ctx);
36
37
/* ------------------------------------------------------------------ */
38
/* parser.h wrappers */
39
/* ------------------------------------------------------------------ */
40
41
ParseContext
*parse_begin(
ParserSnapshot
*snap);
42
void
parse_end(
ParseContext
*ctx);
43
ParserSnapshot
*parse_get_snapshot(
ParseContext
*ctx);
44
45
/*
46
** Feed a token to the push parser.
47
**
48
** ctx Active parse context.
49
** token_code Token code (0 for end-of-input).
50
** token_value Semantic value (may be NULL).
51
** location Byte offset of the token in the source, or
52
** LIME_LOC_UNKNOWN if the grammar does not declare
53
** %locations or the caller does not track positions.
54
**
55
** Returns 0 on success, non-zero on parse error.
56
*/
57
int
parse_token(
ParseContext
*ctx,
58
int
token_code,
59
void
*token_value,
60
int
location);
61
62
/*
63
** Sentinel value for `location` callers who do not track positions
64
** (or who cannot attribute a position to a given token, e.g. an
65
** injected end-of-input marker). Guaranteed to be -1 so that
66
** existing code that passed an integer offset happens to be
67
** forward-compatible when offsets are always >= 0.
68
*/
69
#define LIME_LOC_UNKNOWN (-1)
70
71
/* ------------------------------------------------------------------ */
72
/* Snapshot action table lookup helpers */
73
/* ------------------------------------------------------------------ */
74
75
uint16_t snap_find_shift_action(
const
ParserSnapshot
*snap,
76
uint16_t stateno,
77
uint16_t iLookAhead);
78
uint16_t snap_find_reduce_action(
const
ParserSnapshot
*snap,
79
uint16_t stateno,
80
uint16_t iLookAhead);
81
82
#endif
/* PARSE_CONTEXT_H */
ParseContext
Per-parse-session state.
Definition
parse_context.h:22
ParseContext::snapshot
ParserSnapshot * snapshot
Snapshot pinned for this parse session.
Definition
parse_context.h:23
ParserSnapshot
Opaque snapshot handle.
Definition
snapshot.h:117
include
parse_context.h
Generated by
1.9.8