teptris 0.3.11.1 → 0.3.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/teptris_ext/engine/README.md +1 -1
- data/ext/teptris_ext/engine/src/include/teptris/teptris.h +14 -0
- data/ext/teptris_ext/engine/src/include/teptris/version.h +1 -1
- data/ext/teptris_ext/engine/src/teptris/edit/edit.c +384 -0
- data/ext/teptris_ext/engine/src/teptris/parse/keys.c +9 -0
- data/ext/teptris_ext/engine/src/teptris/parse/scalars.c +4 -2
- data/ext/teptris_ext/materialize.c +14 -6
- data/lib/teptris/error.rb +3 -0
- data/lib/teptris/toml.rb +17 -4
- data/lib/teptris/version.rb +1 -1
- data/sig/teptris.rbs +5 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e108b3072897b64aec6e9cb6d89d2bf505b247f134d14d3502bb27f4ed6f2125
|
|
4
|
+
data.tar.gz: 82edfba1bb80ce7b5c99d47aa061bb2693ae1789fc1d98e5970dc481f7da82cd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 01e0acb7edcc07f47315fd8653f8769aee3ec52498c8bc35bdb49d7a416735301de6f4652ed10f0cdd5a3bf799be64976c822a60de7114fc04f3e3960091cdad
|
|
7
|
+
data.tar.gz: b141f8fef9f74cef8984d07ce7d7b79f3a08ba7206e26ce0da7a844ae090ed4c741b29fe024bbb6b61b71cc4f34d3adc75d2ed890453ad56251f43d634722806
|
|
@@ -143,6 +143,20 @@ TEPTRIS_API const teptris_node * teptris_node_table_get(const teptris_node *node
|
|
|
143
143
|
TEPTRIS_API teptris_status teptris_document_emit(const teptris_document *doc,
|
|
144
144
|
char **buf, size_t *len);
|
|
145
145
|
|
|
146
|
+
/* In-place scalar edit (format-preserving v1): rewrite exactly the
|
|
147
|
+
* value bytes of one key = value line; every other byte of the source
|
|
148
|
+
* is preserved (comments, blank lines, formatting). dotted.key.path
|
|
149
|
+
* addresses the key (bare and quoted components; the path may carry a
|
|
150
|
+
* [table] prefix, e.g. "t.x" for x inside [t]). replacement is the
|
|
151
|
+
* value's TEXT (e.g. "42", "\"str\"", "2026-01-01") and must form a
|
|
152
|
+
* valid single-line value: it is validated by parsing "k = <text>".
|
|
153
|
+
* v1 rejects multiline and inline-collection targets with
|
|
154
|
+
* TEPTRIS_ERR_ARG. Memory: *buf is malloc'd; caller frees. */
|
|
155
|
+
TEPTRIS_API teptris_status teptris_edit_scalar(const char *src, size_t len,
|
|
156
|
+
const char *keypath,
|
|
157
|
+
const char *replacement,
|
|
158
|
+
char **buf, size_t *out_len);
|
|
159
|
+
|
|
146
160
|
/* Emit the toml-test wire shape: scalars as {"type":..,"value":..},
|
|
147
161
|
* tables as objects, arrays as lists, insertion order.
|
|
148
162
|
* Memory: *buf is malloc'd; caller frees with free(). */
|
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
/* Format-preserving scalar edit (v1): rewrite exactly the value bytes
|
|
2
|
+
* of one key = value line; every other byte of the source is
|
|
3
|
+
* preserved. The target is addressed by a dotted key path that may
|
|
4
|
+
* carry a [table] prefix ("t.x" addresses x inside [t]; the LAST
|
|
5
|
+
* component is the key, everything before it is the table path that
|
|
6
|
+
* must match the current [section]). The replacement is the value's
|
|
7
|
+
* TEXT and is validated by parsing "k = <replacement>" - the editor
|
|
8
|
+
* stays value-agnostic.
|
|
9
|
+
*
|
|
10
|
+
* v1 scope: single-line scalar values (numbers, booleans, dates,
|
|
11
|
+
* single-line quoted strings). Multiline strings and inline
|
|
12
|
+
* collections are rejected with TEPTRIS_ERR_ARG rather than
|
|
13
|
+
* half-understood. */
|
|
14
|
+
#include <stdio.h>
|
|
15
|
+
#include <stdlib.h>
|
|
16
|
+
#include <string.h>
|
|
17
|
+
|
|
18
|
+
#include "teptris/teptris.h"
|
|
19
|
+
|
|
20
|
+
static int edit_is_ws(char c)
|
|
21
|
+
{
|
|
22
|
+
return c == ' ' || c == '\t';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static const char *edit_skip_ws(const char *p, const char *end)
|
|
26
|
+
{
|
|
27
|
+
while (p < end && edit_is_ws(*p)) {
|
|
28
|
+
p++;
|
|
29
|
+
}
|
|
30
|
+
return p;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/* match one key component (bare or quoted) against the source at p;
|
|
34
|
+
* returns the pointer past the component, else NULL */
|
|
35
|
+
static const char *edit_match_component(const char *p, const char *end,
|
|
36
|
+
const char *comp, size_t comp_len)
|
|
37
|
+
{
|
|
38
|
+
if (p >= end) {
|
|
39
|
+
return NULL;
|
|
40
|
+
}
|
|
41
|
+
if (*p == '\'' || *p == '"') {
|
|
42
|
+
char q = *p;
|
|
43
|
+
p++;
|
|
44
|
+
size_t ci = 0;
|
|
45
|
+
while (p < end && *p != q) {
|
|
46
|
+
char c = *p;
|
|
47
|
+
if (c == '\n') {
|
|
48
|
+
return NULL;
|
|
49
|
+
}
|
|
50
|
+
if (q == '"' && c == '\\' && p + 1 < end) {
|
|
51
|
+
/* raw-byte comparison: an escaped component character
|
|
52
|
+
* simply fails to match (v1 keeps key matching
|
|
53
|
+
* escape-naive) */
|
|
54
|
+
if (ci < comp_len && comp[ci] != c) {
|
|
55
|
+
return NULL;
|
|
56
|
+
}
|
|
57
|
+
ci++;
|
|
58
|
+
p += 2;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (ci >= comp_len || comp[ci] != c) {
|
|
62
|
+
return NULL;
|
|
63
|
+
}
|
|
64
|
+
ci++;
|
|
65
|
+
p++;
|
|
66
|
+
}
|
|
67
|
+
if (p >= end || ci != comp_len) {
|
|
68
|
+
return NULL;
|
|
69
|
+
}
|
|
70
|
+
return p + 1;
|
|
71
|
+
}
|
|
72
|
+
if (comp_len == 0) {
|
|
73
|
+
return NULL;
|
|
74
|
+
}
|
|
75
|
+
if ((size_t)(end - p) < comp_len || memcmp(p, comp, comp_len) != 0) {
|
|
76
|
+
return NULL;
|
|
77
|
+
}
|
|
78
|
+
p += comp_len;
|
|
79
|
+
if (p == end || p[0] == '.' || edit_is_ws(p[0]) || p[0] == '=' ||
|
|
80
|
+
p[0] == ']') {
|
|
81
|
+
return p;
|
|
82
|
+
}
|
|
83
|
+
return NULL;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/* match a full dotted path at p; returns the pointer past the path,
|
|
87
|
+
* else NULL. Dots inside quotes do not split. */
|
|
88
|
+
static const char *edit_match_path(const char *p, const char *end,
|
|
89
|
+
const char *path, size_t path_len)
|
|
90
|
+
{
|
|
91
|
+
const char *pc = path;
|
|
92
|
+
const char *pend = path + path_len;
|
|
93
|
+
for (;;) {
|
|
94
|
+
while (pc < pend && edit_is_ws(*pc)) {
|
|
95
|
+
pc++;
|
|
96
|
+
}
|
|
97
|
+
const char *cstart = pc;
|
|
98
|
+
int quoted = 0;
|
|
99
|
+
while (pc < pend) {
|
|
100
|
+
if (*pc == '\'' || *pc == '"') {
|
|
101
|
+
quoted = !quoted;
|
|
102
|
+
} else if (*pc == '.' && !quoted) {
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
pc++;
|
|
106
|
+
}
|
|
107
|
+
if (quoted) {
|
|
108
|
+
return NULL;
|
|
109
|
+
}
|
|
110
|
+
const char *cend = pc;
|
|
111
|
+
while (cend > cstart && edit_is_ws(cend[-1])) {
|
|
112
|
+
cend--;
|
|
113
|
+
}
|
|
114
|
+
while (cstart < cend && edit_is_ws(*cstart)) {
|
|
115
|
+
cstart++;
|
|
116
|
+
}
|
|
117
|
+
if (cstart == cend) {
|
|
118
|
+
return NULL;
|
|
119
|
+
}
|
|
120
|
+
p = edit_match_component(p, end, cstart, (size_t)(cend - cstart));
|
|
121
|
+
if (p == NULL) {
|
|
122
|
+
return NULL;
|
|
123
|
+
}
|
|
124
|
+
p = edit_skip_ws(p, end);
|
|
125
|
+
if (pc < pend && *pc == '.') {
|
|
126
|
+
pc++;
|
|
127
|
+
if (p < end && *p == '.') {
|
|
128
|
+
p++; /* consume the source's separator too */
|
|
129
|
+
p = edit_skip_ws(p, end);
|
|
130
|
+
}
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
return p;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/* does the line carry a [section] or [[aot]] header? fills the path
|
|
138
|
+
* span (between the brackets, trimmed) */
|
|
139
|
+
static int edit_section_header(const char *p, const char *end,
|
|
140
|
+
const char **path, size_t *path_len)
|
|
141
|
+
{
|
|
142
|
+
p = edit_skip_ws(p, end);
|
|
143
|
+
if (p >= end || *p != '[') {
|
|
144
|
+
return 0;
|
|
145
|
+
}
|
|
146
|
+
p++;
|
|
147
|
+
if (p < end && *p == '[') {
|
|
148
|
+
p++;
|
|
149
|
+
}
|
|
150
|
+
p = edit_skip_ws(p, end);
|
|
151
|
+
const char *start = p;
|
|
152
|
+
while (p < end && *p != ']') {
|
|
153
|
+
if (*p == '\n') {
|
|
154
|
+
return 0;
|
|
155
|
+
}
|
|
156
|
+
p++;
|
|
157
|
+
}
|
|
158
|
+
if (p >= end) {
|
|
159
|
+
return 0;
|
|
160
|
+
}
|
|
161
|
+
const char *stop = p;
|
|
162
|
+
while (stop > start && edit_is_ws(stop[-1])) {
|
|
163
|
+
stop--;
|
|
164
|
+
}
|
|
165
|
+
*path = start;
|
|
166
|
+
*path_len = (size_t)(stop - start);
|
|
167
|
+
return 1;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/* the value span on a keyval line: p sits past '='. Absolute [start,
|
|
171
|
+
* end) of the value bytes. Single-line scalars only: returns 0, or
|
|
172
|
+
* -1 for multiline/inline targets. */
|
|
173
|
+
static int edit_value_span(const char *p, const char *end,
|
|
174
|
+
const char **vstart, const char **vend)
|
|
175
|
+
{
|
|
176
|
+
p = edit_skip_ws(p, end);
|
|
177
|
+
if (p >= end) {
|
|
178
|
+
return -1;
|
|
179
|
+
}
|
|
180
|
+
const char *vs = p;
|
|
181
|
+
if (*p == '\'') {
|
|
182
|
+
p++;
|
|
183
|
+
while (p < end && *p != '\'') {
|
|
184
|
+
if (*p == '\n') {
|
|
185
|
+
return -1;
|
|
186
|
+
}
|
|
187
|
+
p++;
|
|
188
|
+
}
|
|
189
|
+
if (p >= end) {
|
|
190
|
+
return -1;
|
|
191
|
+
}
|
|
192
|
+
p++;
|
|
193
|
+
} else if (*p == '"') {
|
|
194
|
+
if (p + 2 < end && p[1] == '"' && p[2] == '"') {
|
|
195
|
+
return -1; /* multiline basic */
|
|
196
|
+
}
|
|
197
|
+
p++;
|
|
198
|
+
while (p < end && *p != '"') {
|
|
199
|
+
if (*p == '\n') {
|
|
200
|
+
return -1;
|
|
201
|
+
}
|
|
202
|
+
if (*p == '\\' && p + 1 < end) {
|
|
203
|
+
p += 2;
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
p++;
|
|
207
|
+
}
|
|
208
|
+
if (p >= end) {
|
|
209
|
+
return -1;
|
|
210
|
+
}
|
|
211
|
+
p++;
|
|
212
|
+
} else if (*p == '{' || *p == '[') {
|
|
213
|
+
return -1; /* inline collections: v1 out of scope */
|
|
214
|
+
} else {
|
|
215
|
+
while (p < end && *p != '\n' && *p != '#') {
|
|
216
|
+
p++;
|
|
217
|
+
}
|
|
218
|
+
while (p > vs && edit_is_ws(p[-1])) {
|
|
219
|
+
p--;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
*vstart = vs;
|
|
223
|
+
*vend = p;
|
|
224
|
+
return 0;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/* Split the target keypath at its LAST unquoted '.': the prefix is
|
|
228
|
+
* the table path (must textually match the open [section]), the last
|
|
229
|
+
* component is the key written on the line. A dotted key LINE
|
|
230
|
+
* ("a.b = 1") additionally matches when its full written path equals
|
|
231
|
+
* the target - handled by trying the full-path match first. */
|
|
232
|
+
static void edit_split_target(const char *keypath, size_t klen,
|
|
233
|
+
const char **prefix, size_t *prefix_len,
|
|
234
|
+
const char **last, size_t *last_len)
|
|
235
|
+
{
|
|
236
|
+
const char *kp_end = keypath + klen;
|
|
237
|
+
const char *dot = NULL;
|
|
238
|
+
int quoted = 0;
|
|
239
|
+
for (const char *q = keypath; q < kp_end; q++) {
|
|
240
|
+
if (*q == '\'' || *q == '"') {
|
|
241
|
+
quoted = !quoted;
|
|
242
|
+
} else if (*q == '.' && !quoted) {
|
|
243
|
+
dot = q;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (dot == NULL) {
|
|
247
|
+
*prefix = NULL;
|
|
248
|
+
*prefix_len = 0;
|
|
249
|
+
*last = keypath;
|
|
250
|
+
*last_len = klen;
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
*prefix = keypath;
|
|
254
|
+
*prefix_len = (size_t)(dot - keypath);
|
|
255
|
+
*last = dot + 1;
|
|
256
|
+
*last_len = (size_t)(kp_end - (dot + 1));
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/* raw textual comparison of the open section against the target's
|
|
260
|
+
* table prefix (v1: quoting/spacing variants of the same path do not
|
|
261
|
+
* match; the canonical form does) */
|
|
262
|
+
static int edit_section_matches(const char *prefix, size_t prefix_len,
|
|
263
|
+
const char *sec, size_t sec_len)
|
|
264
|
+
{
|
|
265
|
+
const char *ps = prefix;
|
|
266
|
+
while (prefix_len > 0 && edit_is_ws(ps[0])) {
|
|
267
|
+
ps++;
|
|
268
|
+
prefix_len--;
|
|
269
|
+
}
|
|
270
|
+
while (prefix_len > 0 && edit_is_ws(ps[prefix_len - 1])) {
|
|
271
|
+
prefix_len--;
|
|
272
|
+
}
|
|
273
|
+
if (prefix_len == 0) {
|
|
274
|
+
return sec_len == 0; /* bare key: root only */
|
|
275
|
+
}
|
|
276
|
+
if (sec_len != prefix_len) {
|
|
277
|
+
return 0;
|
|
278
|
+
}
|
|
279
|
+
return memcmp(sec, ps, prefix_len) == 0;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
teptris_status teptris_edit_scalar(const char *src, size_t len,
|
|
283
|
+
const char *keypath,
|
|
284
|
+
const char *replacement,
|
|
285
|
+
char **buf, size_t *out_len)
|
|
286
|
+
{
|
|
287
|
+
if (src == NULL || keypath == NULL || replacement == NULL ||
|
|
288
|
+
buf == NULL || out_len == NULL) {
|
|
289
|
+
return TEPTRIS_ERR_ARG;
|
|
290
|
+
}
|
|
291
|
+
const char *end = src + len;
|
|
292
|
+
|
|
293
|
+
/* validate the replacement by parsing it as a keyval */
|
|
294
|
+
{
|
|
295
|
+
size_t rlen = strlen(replacement);
|
|
296
|
+
if (rlen == 0 || rlen > 4096) {
|
|
297
|
+
return TEPTRIS_ERR_ARG;
|
|
298
|
+
}
|
|
299
|
+
if (strchr(replacement, '\n') != NULL) {
|
|
300
|
+
return TEPTRIS_ERR_ARG; /* v1: single-line replacements */
|
|
301
|
+
}
|
|
302
|
+
char probe[4200];
|
|
303
|
+
int n = snprintf(probe, sizeof probe, "k = %s\n", replacement);
|
|
304
|
+
if (n <= 0 || (size_t)n >= sizeof probe) {
|
|
305
|
+
return TEPTRIS_ERR_ARG;
|
|
306
|
+
}
|
|
307
|
+
teptris_document *probe_doc = NULL;
|
|
308
|
+
teptris_status st = teptris_parse(probe, (size_t)n, NULL, &probe_doc);
|
|
309
|
+
if (st != TEPTRIS_OK) {
|
|
310
|
+
if (probe_doc != NULL) {
|
|
311
|
+
teptris_document_free(probe_doc);
|
|
312
|
+
}
|
|
313
|
+
return TEPTRIS_ERR_ARG;
|
|
314
|
+
}
|
|
315
|
+
teptris_document_free(probe_doc);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
size_t klen = strlen(keypath);
|
|
319
|
+
const char *sec = NULL; /* current [section] path span */
|
|
320
|
+
size_t sec_len = 0;
|
|
321
|
+
|
|
322
|
+
const char *p = src;
|
|
323
|
+
while (p < end) {
|
|
324
|
+
const char *nl = memchr(p, '\n', (size_t)(end - p));
|
|
325
|
+
const char *le = nl ? nl : end;
|
|
326
|
+
const char *t = edit_skip_ws(p, le);
|
|
327
|
+
if (t < le && *t != '#') {
|
|
328
|
+
const char *hp;
|
|
329
|
+
size_t hlen;
|
|
330
|
+
if (edit_section_header(t, le, &hp, &hlen)) {
|
|
331
|
+
sec = hp;
|
|
332
|
+
sec_len = hlen;
|
|
333
|
+
} else {
|
|
334
|
+
const char *after = NULL;
|
|
335
|
+
if (sec_len == 0) {
|
|
336
|
+
/* root: a dotted key LINE may carry the full path */
|
|
337
|
+
after = edit_match_path(t, le, keypath, klen);
|
|
338
|
+
}
|
|
339
|
+
if (after == NULL) {
|
|
340
|
+
/* the line carries just the key: the last target
|
|
341
|
+
* component, under a matching open section */
|
|
342
|
+
const char *pfx;
|
|
343
|
+
size_t pfx_len;
|
|
344
|
+
const char *lastc;
|
|
345
|
+
size_t last_len;
|
|
346
|
+
edit_split_target(keypath, klen, &pfx, &pfx_len,
|
|
347
|
+
&lastc, &last_len);
|
|
348
|
+
if (last_len > 0 &&
|
|
349
|
+
edit_section_matches(pfx, pfx_len, sec, sec_len)) {
|
|
350
|
+
after = edit_match_path(t, le, lastc, last_len);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
if (after != NULL) {
|
|
354
|
+
const char *eq = edit_skip_ws(after, le);
|
|
355
|
+
if (eq < le && *eq == '=') {
|
|
356
|
+
const char *vs;
|
|
357
|
+
const char *ve;
|
|
358
|
+
if (edit_value_span(eq + 1, le, &vs, &ve) != 0) {
|
|
359
|
+
return TEPTRIS_ERR_ARG;
|
|
360
|
+
}
|
|
361
|
+
size_t rlen = strlen(replacement);
|
|
362
|
+
size_t pre = (size_t)(vs - src);
|
|
363
|
+
size_t post = (size_t)(end - ve);
|
|
364
|
+
char *out = malloc(pre + rlen + post);
|
|
365
|
+
if (out == NULL) {
|
|
366
|
+
return TEPTRIS_ERR_ALLOC;
|
|
367
|
+
}
|
|
368
|
+
memcpy(out, src, pre);
|
|
369
|
+
memcpy(out + pre, replacement, rlen);
|
|
370
|
+
memcpy(out + pre + rlen, ve, post);
|
|
371
|
+
*buf = out;
|
|
372
|
+
*out_len = pre + rlen + post;
|
|
373
|
+
return TEPTRIS_OK;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
if (nl == NULL) {
|
|
379
|
+
break;
|
|
380
|
+
}
|
|
381
|
+
p = nl + 1;
|
|
382
|
+
}
|
|
383
|
+
return TEPTRIS_ERR_STATE; /* key not found */
|
|
384
|
+
}
|
|
@@ -104,6 +104,15 @@ teptris_status teptris_parse_key_path(teptris_parser *ps,
|
|
|
104
104
|
}
|
|
105
105
|
v[n++] = key;
|
|
106
106
|
|
|
107
|
+
/* each dotted component is one table level in the DOM - cap it
|
|
108
|
+
* against the same ceiling as '['/'{' nesting, or a hostile
|
|
109
|
+
* a.b.b.b...=1 line builds an uncapped-depth tree that blows
|
|
110
|
+
* the recursive emit/free passes */
|
|
111
|
+
if (n > ps->max_depth) {
|
|
112
|
+
return tep_fail_at(ps, NULL, TEPTRIS_ERR_DEPTH,
|
|
113
|
+
"key path too deep");
|
|
114
|
+
}
|
|
115
|
+
|
|
107
116
|
st = tep_skip_ws(ps);
|
|
108
117
|
if (st != TEPTRIS_OK) {
|
|
109
118
|
return st;
|
|
@@ -201,7 +201,8 @@ teptris_status tep_scan_basic(teptris_parser *ps, bool ml, char *out,
|
|
|
201
201
|
}
|
|
202
202
|
if (c == '\r') {
|
|
203
203
|
if (ml && ps->p + 1 < ps->end && ps->p[1] == '\n') {
|
|
204
|
-
PUTCH(out, n, '\
|
|
204
|
+
PUTCH(out, n, '\n'); /* CRLF normalizes to LF inside multi-line
|
|
205
|
+
strings (tomllib reference) */
|
|
205
206
|
tep_adv(ps, 2);
|
|
206
207
|
continue;
|
|
207
208
|
}
|
|
@@ -267,7 +268,8 @@ teptris_status tep_scan_literal(teptris_parser *ps, bool ml, char *out,
|
|
|
267
268
|
}
|
|
268
269
|
if (c == '\r') {
|
|
269
270
|
if (ml && ps->p + 1 < ps->end && ps->p[1] == '\n') {
|
|
270
|
-
PUTCH(out, n, '\
|
|
271
|
+
PUTCH(out, n, '\n'); /* CRLF normalizes to LF inside multi-line
|
|
272
|
+
strings (tomllib reference) */
|
|
271
273
|
tep_adv(ps, 2);
|
|
272
274
|
continue;
|
|
273
275
|
}
|
|
@@ -1132,10 +1132,13 @@ static VALUE ext_load_lazy_batch(VALUE self, VALUE strings) {
|
|
|
1132
1132
|
}
|
|
1133
1133
|
if (first_fail != -1) {
|
|
1134
1134
|
const teptris_error *e = teptris_document_error(s->docs[first_fail]);
|
|
1135
|
-
|
|
1136
|
-
|
|
1135
|
+
char msg[192];
|
|
1136
|
+
snprintf(msg, sizeof msg, "document %ld: %s", first_fail,
|
|
1137
|
+
e->message);
|
|
1138
|
+
VALUE ex = rb_exc_new(eParseError, msg, (long)strlen(msg));
|
|
1137
1139
|
rb_iv_set(ex, "@line", SIZET2NUM(e->line));
|
|
1138
1140
|
rb_iv_set(ex, "@column", SIZET2NUM(e->column));
|
|
1141
|
+
rb_iv_set(ex, "@index", LONG2NUM(first_fail));
|
|
1139
1142
|
for (long i = 0; i < n; i++) teptris_document_free(s->docs[i]);
|
|
1140
1143
|
batch_scratch_free(s);
|
|
1141
1144
|
rb_exc_raise(ex);
|
|
@@ -1224,10 +1227,12 @@ static VALUE ext_load_slice(int argc, VALUE *argv, VALUE self) {
|
|
|
1224
1227
|
}
|
|
1225
1228
|
const teptris_error *e = teptris_document_error(docs[i]);
|
|
1226
1229
|
if (stats[i] != TEPTRIS_OK) {
|
|
1227
|
-
|
|
1228
|
-
|
|
1230
|
+
char msg[192];
|
|
1231
|
+
snprintf(msg, sizeof msg, "document %ld: %s", i, e->message);
|
|
1232
|
+
VALUE ex = rb_exc_new(eParseError, msg, (long)strlen(msg));
|
|
1229
1233
|
rb_iv_set(ex, "@line", SIZET2NUM(e->line));
|
|
1230
1234
|
rb_iv_set(ex, "@column", SIZET2NUM(e->column));
|
|
1235
|
+
rb_iv_set(ex, "@index", LONG2NUM(i));
|
|
1231
1236
|
long j;
|
|
1232
1237
|
for (j = i; j < n; j++) teptris_document_free(docs[j]);
|
|
1233
1238
|
kc_free(&kc);
|
|
@@ -1281,10 +1286,13 @@ static VALUE ext_load_batch(int argc, VALUE *argv, VALUE self) {
|
|
|
1281
1286
|
}
|
|
1282
1287
|
if (first_fail != -1) {
|
|
1283
1288
|
const teptris_error *e = teptris_document_error(s->docs[first_fail]);
|
|
1284
|
-
|
|
1285
|
-
|
|
1289
|
+
char msg[192];
|
|
1290
|
+
snprintf(msg, sizeof msg, "document %ld: %s", first_fail,
|
|
1291
|
+
e->message);
|
|
1292
|
+
VALUE ex = rb_exc_new(eParseError, msg, (long)strlen(msg));
|
|
1286
1293
|
rb_iv_set(ex, "@line", SIZET2NUM(e->line));
|
|
1287
1294
|
rb_iv_set(ex, "@column", SIZET2NUM(e->column));
|
|
1295
|
+
rb_iv_set(ex, "@index", LONG2NUM(first_fail));
|
|
1288
1296
|
for (long i = 0; i < n; i++) teptris_document_free(s->docs[i]);
|
|
1289
1297
|
batch_scratch_free(s);
|
|
1290
1298
|
rb_exc_raise(ex);
|
data/lib/teptris/error.rb
CHANGED
|
@@ -5,6 +5,9 @@ module Teptris
|
|
|
5
5
|
|
|
6
6
|
class ParseError < Error
|
|
7
7
|
attr_reader :line, :column
|
|
8
|
+
# batch context: load_batch/load_slice set this to the 0-based
|
|
9
|
+
# position of the failing document in the batch
|
|
10
|
+
attr_accessor :index
|
|
8
11
|
|
|
9
12
|
def initialize(message, line = 0, column = 0)
|
|
10
13
|
@line = line
|
data/lib/teptris/toml.rb
CHANGED
|
@@ -121,13 +121,26 @@ module Teptris::TOML
|
|
|
121
121
|
end
|
|
122
122
|
end
|
|
123
123
|
end.each(&:join)
|
|
124
|
-
if first_error
|
|
125
|
-
_, err = first_error
|
|
126
|
-
raise err
|
|
127
|
-
end
|
|
124
|
+
raise_batch_error!(first_error) if first_error
|
|
128
125
|
results
|
|
129
126
|
end
|
|
130
127
|
|
|
128
|
+
# the slice's error is slice-local (its message and @index count
|
|
129
|
+
# from the slice's first document); translate both to batch-global
|
|
130
|
+
def raise_batch_error!(first_error)
|
|
131
|
+
return unless first_error
|
|
132
|
+
|
|
133
|
+
base, err = first_error
|
|
134
|
+
return unless err
|
|
135
|
+
|
|
136
|
+
global = (base || 0) + (err.index || 0)
|
|
137
|
+
text = err.message.sub(/\Adocument \d+: /, "")
|
|
138
|
+
wrapped = Teptris::ParseError.new("document #{global}: #{text}",
|
|
139
|
+
err.line, err.column)
|
|
140
|
+
wrapped.index = global
|
|
141
|
+
raise wrapped
|
|
142
|
+
end
|
|
143
|
+
|
|
131
144
|
# Lazy twin of load_batch: parse N inputs eagerly, hand back an
|
|
132
145
|
# Array of Lazy wrappers — materialization happens only on access.
|
|
133
146
|
# Same per-doc error semantics as load_lazy (first failure raises).
|
data/lib/teptris/version.rb
CHANGED
data/sig/teptris.rbs
CHANGED
|
@@ -10,6 +10,9 @@ module Teptris
|
|
|
10
10
|
class ParseError < Error
|
|
11
11
|
attr_reader line: Integer
|
|
12
12
|
attr_reader column: Integer
|
|
13
|
+
# batch context: set by load_batch/load_slice on batch failures -
|
|
14
|
+
# the 0-based position of the failing document in the batch
|
|
15
|
+
attr_accessor index: Integer?
|
|
13
16
|
|
|
14
17
|
def initialize: (String message, ?Integer line, ?Integer column) -> void
|
|
15
18
|
end
|
|
@@ -39,6 +42,8 @@ module Teptris
|
|
|
39
42
|
?threads: Integer)
|
|
40
43
|
-> Array[Hash[String, untyped]]
|
|
41
44
|
|
|
45
|
+
def self.raise_batch_error!: ([Integer, ParseError]?) -> void
|
|
46
|
+
|
|
42
47
|
def self.load_lazy_batch: (Array[String] tomls)
|
|
43
48
|
-> Array[TeptrisExt::LazyValue]
|
|
44
49
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: teptris
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.14.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- teptris contributors
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-10-
|
|
11
|
+
date: 2026-10-31 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: A native C extension over libteptris, a C99 TOML 1.1 parser/emitter.
|
|
14
14
|
API shape mirrors the tomlib gem.
|
|
@@ -39,6 +39,7 @@ files:
|
|
|
39
39
|
- ext/teptris_ext/engine/src/teptris/common/simd.h
|
|
40
40
|
- ext/teptris_ext/engine/src/teptris/dom/dom.c
|
|
41
41
|
- ext/teptris_ext/engine/src/teptris/dom/dom.h
|
|
42
|
+
- ext/teptris_ext/engine/src/teptris/edit/edit.c
|
|
42
43
|
- ext/teptris_ext/engine/src/teptris/emit/emit_shared.h
|
|
43
44
|
- ext/teptris_ext/engine/src/teptris/emit/emitter.c
|
|
44
45
|
- ext/teptris_ext/engine/src/teptris/emit/emitter.h
|