Lime Parser Generator 0.1.0
Runtime-extensible LALR(1) parser with SIMD tokenization and LLVM JIT
Loading...
Searching...
No Matches
snapshot_build.h
Go to the documentation of this file.
1
32#ifndef SNAPSHOT_BUILD_H
33#define SNAPSHOT_BUILD_H
34
35#include "snapshot.h"
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
49typedef struct LimeParserTables {
50 /* Action tables */
51 const uint16_t *yy_action;
52 uint32_t yy_action_count;
53 const uint16_t *yy_lookahead;
54 uint32_t yy_lookahead_count;
55 const int32_t *yy_shift_ofst;
56 const int32_t *yy_reduce_ofst;
57 const uint16_t *yy_default;
58 uint32_t nstate;
59
60 /* Rule metadata */
61 const int16_t *yy_rule_info_lhs;
62 const int8_t *yy_rule_info_nrhs;
63 uint32_t nrule;
64
65 /* Counts */
66 uint32_t nsymbol;
67 uint32_t nterminal;
68
69 /* Optional symbol-name table (the generated yyTokenName[]), indexed
70 ** by internal symbol index: [0]="$", [1..nterminal-1]=terminals,
71 ** [nterminal..nsymbol-1]=nonterminals. When supplied,
72 ** snapshot_build_from_tables deep-copies it so the snapshot can map
73 ** a token NAME -> external code (lime_snapshot_token_code), which a
74 ** scanner needs to emit the right code for an extension keyword in
75 ** a recompiled/composed snapshot. NULL when the generator did not
76 ** emit names (recognition-only / pre-name-table lime); the lookup
77 ** then returns -1. */
78 const char *const *token_names;
79 uint32_t token_names_count; /* = nsymbol when token_names != NULL */
80 uint16_t ntoken; /* YYNTOKEN = highest terminal + 1 */
81 /* YYFIRSTTOKEN: the %first_token directive value (0 when not
82 ** declared). Subtracted from external token codes by parse_token
83 ** to compute the internal action-table index. Paired with
84 ** ntoken: the valid external code range is
85 ** [first_token, first_token + ntoken). */
86 uint16_t first_token;
87
88 /* Action-range constants */
89 uint16_t yy_max_shift;
90 uint16_t yy_min_shiftreduce;
91 uint16_t yy_max_shiftreduce;
92 uint16_t yy_error_action;
93 uint16_t yy_accept_action;
94 uint16_t yy_no_action;
95 uint16_t yy_min_reduce;
96
97 /* Optional fallback (NULL when grammar has no %fallback) */
98 const uint16_t *yy_fallback;
99 uint32_t nfallback;
100
101 /* Optional original grammar source text. Embedded by `lime -n`
102 ** so the runtime extension framework can rebuild the LALR(1)
103 ** automaton from a base snapshot plus a list of modifications:
104 ** publish_modified_snapshot() concatenates this text with
105 ** lime_modifications_to_grammar_text(mods) and reruns the
106 ** subprocess pipeline (lime + cc) on the merged grammar.
107 **
108 ** NULL when the snapshot was built by a path that did not have
109 ** access to the original .y text (e.g. a hand-built snapshot
110 ** for testing). Callers that want runtime grammar mutation
111 ** must supply this, or a base snapshot whose generated builder
112 ** populated it. Length is the byte count NOT including a
113 ** trailing NUL (the array always has one for C-string-friendly
114 ** consumption). */
115 const char *grammar_source;
116 uint32_t grammar_source_len;
117
118 /* Magic + ABI version pair. Set unconditionally by the
119 ** generator. snapshot_build_from_tables checks both and
120 ** rejects mismatched bundles with a clear error rather than
121 ** silently producing a wrong snapshot. v0.6.3 generated
122 ** *_snapshot.c files leave these zero (partial initialiser);
123 ** v0.7.0+ runtime detects that and reports "snapshot was
124 ** built against pre-v0.7.0 lime; rebuild required". */
125 uint32_t magic; /* LIME_TABLES_MAGIC */
126 uint16_t abi_version; /* LIME_TABLES_ABI_VERSION */
127
128 /* Optional host-reduce hook (Letter 30). `lime -n` sets this to
129 ** the generated, exported <Name>HostReduce wrapper so the push
130 ** parser can run BASE-grammar reduce actions over the snapshot.
131 ** NULL for recognition-only snapshots (and for tables emitted by
132 ** pre-host-reduce lime), in which case parse_token accepts/rejects
133 ** without running actions. Copied verbatim into the snapshot. */
134 LimeHostReduceFn host_reduce;
135 void *host_reduce_user;
137
138#define LIME_TABLES_MAGIC 0x4C494D45U /* 'L','I','M','E' */
139#define LIME_TABLES_ABI_VERSION 1
140
153
154#ifdef __cplusplus
155}
156#endif
157
158#endif /* SNAPSHOT_BUILD_H */
ParserSnapshot * snapshot_build_from_tables(const LimeParserTables *tables)
Build a fresh ParserSnapshot from a LimeParserTables bundle.
Bundle of pointers + sizes the generator emits for a parser.
Opaque snapshot handle.
Definition snapshot.h:177