teptris 0.3.15.0-s390x-linux → 0.3.17.0-s390x-linux
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 +10 -8
- data/ext/teptris_ext/engine/src/include/teptris/version.h +1 -1
- data/ext/teptris_ext/engine/src/teptris/edit/edit.c +155 -48
- data/ext/teptris_ext/materialize.c +30 -0
- data/lib/teptris/3.3/teptris_ext.so +0 -0
- data/lib/teptris/3.4/teptris_ext.so +0 -0
- data/lib/teptris/4.0/teptris_ext.so +0 -0
- data/lib/teptris/toml.rb +11 -0
- data/lib/teptris/version.rb +1 -1
- data/sig/teptris.rbs +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 75e3a2904dd27d2407b4676498b2d9c25f8dcc9c74c6177bcd3ede32571a6f84
|
|
4
|
+
data.tar.gz: 821c864f86ec039f8c45205fabb210f97e6a87abeaf2fbe290d269217b942859
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '062387559b635f97607fe635dce5387e5ed881ca57e0c925e6da72aab9c88021fa59ff1978d116cc5b6e96f45282b33b087db0134d0e6763eb0b1c5f82ad087a'
|
|
7
|
+
data.tar.gz: 175b46bea6a79e87f18b1cb42168d0f9fb3a4ad9c8443447175855362b0eefe810f69752b5add5dae81dd1f4cfce58db4d4d84d0f42975f88010584b71eb9c58
|
|
@@ -143,15 +143,17 @@ 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
|
|
146
|
+
/* In-place scalar edit (format-preserving v2): rewrite exactly the
|
|
147
147
|
* value bytes of one key = value line; every other byte of the source
|
|
148
|
-
* is preserved (comments, blank lines, formatting).
|
|
149
|
-
* addresses the key (bare and quoted components; the
|
|
150
|
-
* [table] prefix, e.g. "t.x" for x inside [t]).
|
|
151
|
-
* value's TEXT (e.g. "42", "\"str\"", "2026-01-01"
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
148
|
+
* is preserved (comments, blank lines, formatting, CRLF endings).
|
|
149
|
+
* dotted.key.path addresses the key (bare and quoted components; the
|
|
150
|
+
* path may carry a [table] prefix, e.g. "t.x" for x inside [t]).
|
|
151
|
+
* replacement is the value's TEXT (e.g. "42", "\"str\"", "2026-01-01",
|
|
152
|
+
* or a multiline string value) and is validated by parsing
|
|
153
|
+
* "k = <text>". v2 splices multiline strings and inline collections
|
|
154
|
+
* too; those splices are parse-verified before handback (a
|
|
155
|
+
* mis-scanned span rejects with TEPTRIS_ERR_ARG instead of
|
|
156
|
+
* corrupting). Memory: *buf is malloc'd; caller frees. */
|
|
155
157
|
TEPTRIS_API teptris_status teptris_edit_scalar(const char *src, size_t len,
|
|
156
158
|
const char *keypath,
|
|
157
159
|
const char *replacement,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* Format-preserving scalar edit (
|
|
1
|
+
/* Format-preserving scalar edit (v2): rewrite exactly the value bytes
|
|
2
2
|
* of one key = value line; every other byte of the source is
|
|
3
3
|
* preserved. The target is addressed by a dotted key path that may
|
|
4
4
|
* carry a [table] prefix ("t.x" addresses x inside [t]; the LAST
|
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
* TEXT and is validated by parsing "k = <replacement>" - the editor
|
|
8
8
|
* stays value-agnostic.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
10
|
+
* v2 scope: single-line scalars, multiline strings and inline
|
|
11
|
+
* collections all splice; v2 spans are parse-verified before handback
|
|
12
|
+
* so a mis-scanned span rejects instead of corrupting. CRLF line
|
|
13
|
+
* endings are preserved (the line-tail \r is outside the span). */
|
|
14
14
|
#include <stdio.h>
|
|
15
15
|
#include <stdlib.h>
|
|
16
16
|
#include <string.h>
|
|
@@ -167,60 +167,106 @@ static int edit_section_header(const char *p, const char *end,
|
|
|
167
167
|
return 1;
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
-
/*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
170
|
+
/* Skip one string spanning from its opening quote at p; mirrors the
|
|
171
|
+
* engine's scanners: quote-run close (run >= 3 for multiline), escape
|
|
172
|
+
* tracking in basic strings. Returns the pointer past the string, or
|
|
173
|
+
* NULL when unterminated. */
|
|
174
|
+
static const char *edit_skip_string(const char *p, const char *end)
|
|
175
|
+
{
|
|
176
|
+
char q = *p;
|
|
177
|
+
int ml = (p + 2 < end && p[1] == q && p[2] == q);
|
|
178
|
+
p += ml ? 3 : 1;
|
|
179
|
+
while (p < end) {
|
|
180
|
+
char c = *p;
|
|
181
|
+
if (q == '"' && c == '\\') {
|
|
182
|
+
if (p + 1 >= end) {
|
|
183
|
+
return NULL; /* unterminated escape */
|
|
184
|
+
}
|
|
185
|
+
p += 2;
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (c == q) {
|
|
189
|
+
int run = 0;
|
|
190
|
+
while (p + run < end && p[run] == q) {
|
|
191
|
+
run++;
|
|
192
|
+
}
|
|
193
|
+
if (!ml) {
|
|
194
|
+
return p + 1; /* single-line closes at the first quote */
|
|
195
|
+
}
|
|
196
|
+
if (run >= 3) {
|
|
197
|
+
return p + run; /* multiline closes at the run */
|
|
198
|
+
}
|
|
199
|
+
p += run; /* 1-2 quotes inside multiline: content */
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
p++;
|
|
203
|
+
}
|
|
204
|
+
return NULL;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/* the value span of a keyval line: p sits past '='. Absolute [start,
|
|
208
|
+
* end) of the value bytes. Returns 0 with *verified unset for the
|
|
209
|
+
* single-line scalar fast path (v1 contract: no parse required), or 1
|
|
210
|
+
* for string/inline spans whose splice must be parse-verified, or -1
|
|
211
|
+
* for a malformed span. */
|
|
173
212
|
static int edit_value_span(const char *p, const char *end,
|
|
174
|
-
const char **vstart, const char **vend
|
|
213
|
+
const char **vstart, const char **vend,
|
|
214
|
+
int *verified)
|
|
175
215
|
{
|
|
176
216
|
p = edit_skip_ws(p, end);
|
|
177
217
|
if (p >= end) {
|
|
178
218
|
return -1;
|
|
179
219
|
}
|
|
180
220
|
const char *vs = p;
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
p++;
|
|
188
|
-
}
|
|
189
|
-
if (p >= end) {
|
|
221
|
+
const char *ve = NULL;
|
|
222
|
+
|
|
223
|
+
if (*p == '\'' || *p == '"') {
|
|
224
|
+
p = edit_skip_string(p, end);
|
|
225
|
+
if (p == NULL) {
|
|
190
226
|
return -1;
|
|
191
227
|
}
|
|
192
|
-
p
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
228
|
+
ve = p;
|
|
229
|
+
*verified = 1;
|
|
230
|
+
} else if (*p == '{' || *p == '[') {
|
|
231
|
+
int depth = 0;
|
|
232
|
+
while (p < end) {
|
|
233
|
+
char c = *p;
|
|
234
|
+
if (c == '\'' || c == '"') {
|
|
235
|
+
p = edit_skip_string(p, end);
|
|
236
|
+
if (p == NULL) {
|
|
237
|
+
return -1;
|
|
238
|
+
}
|
|
239
|
+
continue;
|
|
201
240
|
}
|
|
202
|
-
if (
|
|
203
|
-
|
|
241
|
+
if (c == '{' || c == '[') {
|
|
242
|
+
depth++;
|
|
243
|
+
} else if (c == '}' || c == ']') {
|
|
244
|
+
depth--;
|
|
245
|
+
p++;
|
|
246
|
+
if (depth == 0) {
|
|
247
|
+
ve = p;
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
204
250
|
continue;
|
|
205
251
|
}
|
|
206
252
|
p++;
|
|
207
253
|
}
|
|
208
|
-
if (
|
|
209
|
-
return -1;
|
|
254
|
+
if (ve == NULL) {
|
|
255
|
+
return -1; /* unbalanced inline collection */
|
|
210
256
|
}
|
|
211
|
-
|
|
212
|
-
} else if (*p == '{' || *p == '[') {
|
|
213
|
-
return -1; /* inline collections: v1 out of scope */
|
|
257
|
+
*verified = 1;
|
|
214
258
|
} else {
|
|
215
259
|
while (p < end && *p != '\n' && *p != '#') {
|
|
216
260
|
p++;
|
|
217
261
|
}
|
|
218
|
-
while (p > vs && edit_is_ws(p[-1])) {
|
|
219
|
-
p--;
|
|
262
|
+
while (p > vs && (edit_is_ws(p[-1]) || p[-1] == '\r')) {
|
|
263
|
+
p--; /* CRLF: the line-tail \r stays outside the span */
|
|
220
264
|
}
|
|
265
|
+
ve = p;
|
|
266
|
+
*verified = 0;
|
|
221
267
|
}
|
|
222
268
|
*vstart = vs;
|
|
223
|
-
*vend =
|
|
269
|
+
*vend = ve;
|
|
224
270
|
return 0;
|
|
225
271
|
}
|
|
226
272
|
|
|
@@ -279,6 +325,34 @@ static int edit_section_matches(const char *prefix, size_t prefix_len,
|
|
|
279
325
|
return memcmp(sec, ps, prefix_len) == 0;
|
|
280
326
|
}
|
|
281
327
|
|
|
328
|
+
/* Raw-textual check: does the target keypath, after its trimmed
|
|
329
|
+
* section prefix, CONTINUE the open section? [items] + target
|
|
330
|
+
* "items.a.b" -> the line may write "a.b" or "b"; this yields "a.b".
|
|
331
|
+
* Canonical-textual only (quoting variants do not match), consistent
|
|
332
|
+
* with edit_section_matches. */
|
|
333
|
+
static int edit_strip_section_prefix(const char *keypath, size_t klen,
|
|
334
|
+
const char *sec, size_t sec_len,
|
|
335
|
+
const char **rest, size_t *rest_len)
|
|
336
|
+
{
|
|
337
|
+
while (klen > 0 && edit_is_ws(keypath[0])) {
|
|
338
|
+
keypath++;
|
|
339
|
+
klen--;
|
|
340
|
+
}
|
|
341
|
+
while (klen > 0 && edit_is_ws(keypath[klen - 1])) {
|
|
342
|
+
klen--;
|
|
343
|
+
}
|
|
344
|
+
if (sec_len == 0 || klen <= sec_len) {
|
|
345
|
+
return 0;
|
|
346
|
+
}
|
|
347
|
+
if (keypath[sec_len] != '.' ||
|
|
348
|
+
memcmp(keypath, sec, sec_len) != 0) {
|
|
349
|
+
return 0;
|
|
350
|
+
}
|
|
351
|
+
*rest = keypath + sec_len + 1;
|
|
352
|
+
*rest_len = klen - sec_len - 1;
|
|
353
|
+
return *rest_len > 0;
|
|
354
|
+
}
|
|
355
|
+
|
|
282
356
|
teptris_status teptris_edit_scalar(const char *src, size_t len,
|
|
283
357
|
const char *keypath,
|
|
284
358
|
const char *replacement,
|
|
@@ -290,22 +364,23 @@ teptris_status teptris_edit_scalar(const char *src, size_t len,
|
|
|
290
364
|
}
|
|
291
365
|
const char *end = src + len;
|
|
292
366
|
|
|
293
|
-
/* validate the replacement by parsing it as a keyval
|
|
367
|
+
/* validate the replacement by parsing it as a keyval; multiline
|
|
368
|
+
* replacements (multiline-string values) are fine - the probe
|
|
369
|
+
* parse is the only gate */
|
|
294
370
|
{
|
|
295
371
|
size_t rlen = strlen(replacement);
|
|
296
|
-
if (rlen == 0 || rlen >
|
|
372
|
+
if (rlen == 0 || rlen > 16384) {
|
|
297
373
|
return TEPTRIS_ERR_ARG;
|
|
298
374
|
}
|
|
299
|
-
|
|
300
|
-
|
|
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;
|
|
375
|
+
char *probe = malloc(rlen + 16);
|
|
376
|
+
if (probe == NULL) {
|
|
377
|
+
return TEPTRIS_ERR_ALLOC;
|
|
306
378
|
}
|
|
379
|
+
int n = snprintf(probe, rlen + 16, "k = %s\n", replacement);
|
|
307
380
|
teptris_document *probe_doc = NULL;
|
|
308
|
-
teptris_status st = teptris_parse(probe, (size_t)n, NULL,
|
|
381
|
+
teptris_status st = teptris_parse(probe, (size_t)n, NULL,
|
|
382
|
+
&probe_doc);
|
|
383
|
+
free(probe);
|
|
309
384
|
if (st != TEPTRIS_OK) {
|
|
310
385
|
if (probe_doc != NULL) {
|
|
311
386
|
teptris_document_free(probe_doc);
|
|
@@ -349,13 +424,29 @@ teptris_status teptris_edit_scalar(const char *src, size_t len,
|
|
|
349
424
|
edit_section_matches(pfx, pfx_len, sec, sec_len)) {
|
|
350
425
|
after = edit_match_path(t, le, lastc, last_len);
|
|
351
426
|
}
|
|
427
|
+
if (after == NULL && sec_len > 0) {
|
|
428
|
+
/* the line writes a dotted path that CONTINUES
|
|
429
|
+
* the open section: "a.b = 1" under [items]
|
|
430
|
+
* with target "items.a.b" */
|
|
431
|
+
const char *rest;
|
|
432
|
+
size_t rest_len;
|
|
433
|
+
if (edit_strip_section_prefix(keypath, klen, sec,
|
|
434
|
+
sec_len, &rest,
|
|
435
|
+
&rest_len)) {
|
|
436
|
+
after = edit_match_path(t, le, rest, rest_len);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
352
439
|
}
|
|
353
440
|
if (after != NULL) {
|
|
354
441
|
const char *eq = edit_skip_ws(after, le);
|
|
355
442
|
if (eq < le && *eq == '=') {
|
|
356
443
|
const char *vs;
|
|
357
444
|
const char *ve;
|
|
358
|
-
|
|
445
|
+
int verified = 0;
|
|
446
|
+
/* the span scan bounds at the whole source:
|
|
447
|
+
* multiline and inline values cross lines */
|
|
448
|
+
if (edit_value_span(eq + 1, end, &vs, &ve,
|
|
449
|
+
&verified) != 0) {
|
|
359
450
|
return TEPTRIS_ERR_ARG;
|
|
360
451
|
}
|
|
361
452
|
size_t rlen = strlen(replacement);
|
|
@@ -368,6 +459,22 @@ teptris_status teptris_edit_scalar(const char *src, size_t len,
|
|
|
368
459
|
memcpy(out, src, pre);
|
|
369
460
|
memcpy(out + pre, replacement, rlen);
|
|
370
461
|
memcpy(out + pre + rlen, ve, post);
|
|
462
|
+
if (verified) {
|
|
463
|
+
/* v2 spans are parse-verified: a
|
|
464
|
+
* mis-scanned span rejects instead of
|
|
465
|
+
* corrupting */
|
|
466
|
+
teptris_document *vd = NULL;
|
|
467
|
+
teptris_status vst = teptris_parse(out,
|
|
468
|
+
pre + rlen + post, NULL, &vd);
|
|
469
|
+
if (vst != TEPTRIS_OK) {
|
|
470
|
+
if (vd != NULL) {
|
|
471
|
+
teptris_document_free(vd);
|
|
472
|
+
}
|
|
473
|
+
free(out);
|
|
474
|
+
return TEPTRIS_ERR_ARG;
|
|
475
|
+
}
|
|
476
|
+
teptris_document_free(vd);
|
|
477
|
+
}
|
|
371
478
|
*buf = out;
|
|
372
479
|
*out_len = pre + rlen + post;
|
|
373
480
|
return TEPTRIS_OK;
|
|
@@ -369,6 +369,35 @@ static VALUE ext_version(VALUE self) {
|
|
|
369
369
|
return rb_str_new_cstr(teptris_version_string());
|
|
370
370
|
}
|
|
371
371
|
|
|
372
|
+
/* ------------------------------------------------------------- edit */
|
|
373
|
+
|
|
374
|
+
/* Format-preserving edit: rewrite exactly the value bytes of one
|
|
375
|
+
* key = value line; every other byte of the source survives. Returns
|
|
376
|
+
* the edited document as a String. Teptris::Error on an absent key or
|
|
377
|
+
* a malformed span/replacement. */
|
|
378
|
+
static VALUE ext_edit(VALUE self, VALUE src, VALUE keypath, VALUE replacement) {
|
|
379
|
+
StringValue(src);
|
|
380
|
+
StringValue(keypath);
|
|
381
|
+
StringValue(replacement);
|
|
382
|
+
char *buf = NULL;
|
|
383
|
+
size_t out_len = 0;
|
|
384
|
+
teptris_status st = teptris_edit_scalar(
|
|
385
|
+
RSTRING_PTR(src), (size_t)RSTRING_LEN(src),
|
|
386
|
+
StringValueCStr(keypath), StringValueCStr(replacement),
|
|
387
|
+
&buf, &out_len);
|
|
388
|
+
if (st != TEPTRIS_OK) {
|
|
389
|
+
if (st == TEPTRIS_ERR_STATE)
|
|
390
|
+
raise_teptris("edit: key not found");
|
|
391
|
+
else if (st == TEPTRIS_ERR_ALLOC)
|
|
392
|
+
rb_memerror();
|
|
393
|
+
else
|
|
394
|
+
raise_teptris("edit: malformed key path or replacement");
|
|
395
|
+
}
|
|
396
|
+
VALUE out = rb_str_new(buf, (long)out_len);
|
|
397
|
+
free(buf);
|
|
398
|
+
return out;
|
|
399
|
+
}
|
|
400
|
+
|
|
372
401
|
/* ------------------------------------------------------------------ dump */
|
|
373
402
|
|
|
374
403
|
static ID id_utc_offset, id_to_s, id_to_i, id_nsec;
|
|
@@ -1341,6 +1370,7 @@ void Init_teptris_ext(void) {
|
|
|
1341
1370
|
rb_define_module_function(m, "dump_json_natural", ext_dump_json_natural,
|
|
1342
1371
|
1);
|
|
1343
1372
|
rb_define_module_function(m, "engine_version", ext_version, 0);
|
|
1373
|
+
rb_define_module_function(m, "edit", ext_edit, 3);
|
|
1344
1374
|
rb_define_module_function(m, "plan_build", ext_plan_build, 2);
|
|
1345
1375
|
rb_define_module_function(m, "plan_emit", ext_plan_emit, 2);
|
|
1346
1376
|
/* error/version load first (teptris.rb), then the ext bundle */
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/lib/teptris/toml.rb
CHANGED
|
@@ -173,6 +173,17 @@ module Teptris::TOML
|
|
|
173
173
|
TeptrisExt.engine_version
|
|
174
174
|
end
|
|
175
175
|
|
|
176
|
+
# Format-preserving edit: rewrite exactly the value bytes of one
|
|
177
|
+
# key = value line; every other byte of the source survives
|
|
178
|
+
# (comments, blank lines, formatting, CRLF endings). key_path may
|
|
179
|
+
# carry a [table] prefix ("t.x" edits x inside [t]); replacement
|
|
180
|
+
# is the value's TEXT, validated by the engine. Returns the edited
|
|
181
|
+
# document as a String. Raises Teptris::Error on an absent key or
|
|
182
|
+
# a malformed span/replacement.
|
|
183
|
+
def edit(source, key_path, replacement)
|
|
184
|
+
TeptrisExt.edit(source, key_path, replacement)
|
|
185
|
+
end
|
|
186
|
+
|
|
176
187
|
def load_file(path)
|
|
177
188
|
load(File.read(path))
|
|
178
189
|
end
|
data/lib/teptris/version.rb
CHANGED
data/sig/teptris.rbs
CHANGED
|
@@ -60,6 +60,10 @@ module Teptris
|
|
|
60
60
|
|
|
61
61
|
def self.engine_version: () -> String
|
|
62
62
|
|
|
63
|
+
# Format-preserving edit: rewrite exactly the value bytes of one
|
|
64
|
+
# key = value line; every other byte of the source survives.
|
|
65
|
+
def self.edit: (String source, String key_path, String replacement) -> String
|
|
66
|
+
|
|
63
67
|
def self._validate_batch!: (untyped input, untyped safe_load,
|
|
64
68
|
:native | :string datetime_policy,
|
|
65
69
|
?kind: Symbol) -> void
|
|
@@ -139,6 +143,8 @@ module TeptrisExt
|
|
|
139
143
|
|
|
140
144
|
def self.engine_version: () -> String
|
|
141
145
|
|
|
146
|
+
def self.edit: (String source, String key_path, String replacement) -> String
|
|
147
|
+
|
|
142
148
|
def self.plan_build: (Array[[String, Integer, Integer]] rows,
|
|
143
149
|
Array[Integer] first_row) -> untyped
|
|
144
150
|
|
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.17.0
|
|
5
5
|
platform: s390x-linux
|
|
6
6
|
authors:
|
|
7
7
|
- teptris contributors
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-11-01 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.
|