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) */
13typedef struct ParseContext ParseContext;
14
25
26/*
27** Create a parse context with the given snapshot.
28** Acquires a reference to the snapshot.
29*/
30ParseContext *parse_context_create(ParserSnapshot *snap);
31
32/*
33** Destroy a parse context, releasing the snapshot.
34*/
35void parse_context_destroy(ParseContext *ctx);
36
37/* ------------------------------------------------------------------ */
38/* parser.h wrappers */
39/* ------------------------------------------------------------------ */
40
41ParseContext *parse_begin(ParserSnapshot *snap);
42void parse_end(ParseContext *ctx);
43ParserSnapshot *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*/
57int 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
75uint16_t snap_find_shift_action(const ParserSnapshot *snap,
76 uint16_t stateno,
77 uint16_t iLookAhead);
78uint16_t snap_find_reduce_action(const ParserSnapshot *snap,
79 uint16_t stateno,
80 uint16_t iLookAhead);
81
82#endif /* PARSE_CONTEXT_H */
Per-parse-session state.
ParserSnapshot * snapshot
Snapshot pinned for this parse session.
Opaque snapshot handle.
Definition snapshot.h:117