teptris 0.3.14.0-x86_64-linux → 0.3.16.0-x86_64-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 +115 -48
- data/ext/teptris_ext/engine/src/teptris/parse/datetime.c +1 -1
- 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 +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 179da302fa03ca5979df7d7adce650df78029225000e5168571f9c33fe568b5a
|
|
4
|
+
data.tar.gz: 6a751a0eef95826163c676ee83896f69a6cb529c3d0a3ba65cd16fb9c66daf06
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c4ae4f72f52e72dbcfe31ce55d07a4066dedd498e4df91920d3a122da73ebe4172a36ce867f7350bf36fbef5c4bc47bd8b0aa5e16b9b7c6418b4db5393bc9074
|
|
7
|
+
data.tar.gz: b2d4437bb468806f71220dfcd58ac2a632b0fc24b8aeb036c919d799758faf4388133e997d31704601de6278f79a9b4b3181f13964ca45772101e5ef0bfaf0e8
|
|
@@ -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
|
|
|
@@ -290,22 +336,23 @@ teptris_status teptris_edit_scalar(const char *src, size_t len,
|
|
|
290
336
|
}
|
|
291
337
|
const char *end = src + len;
|
|
292
338
|
|
|
293
|
-
/* validate the replacement by parsing it as a keyval
|
|
339
|
+
/* validate the replacement by parsing it as a keyval; multiline
|
|
340
|
+
* replacements (multiline-string values) are fine - the probe
|
|
341
|
+
* parse is the only gate */
|
|
294
342
|
{
|
|
295
343
|
size_t rlen = strlen(replacement);
|
|
296
|
-
if (rlen == 0 || rlen >
|
|
344
|
+
if (rlen == 0 || rlen > 16384) {
|
|
297
345
|
return TEPTRIS_ERR_ARG;
|
|
298
346
|
}
|
|
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;
|
|
347
|
+
char *probe = malloc(rlen + 16);
|
|
348
|
+
if (probe == NULL) {
|
|
349
|
+
return TEPTRIS_ERR_ALLOC;
|
|
306
350
|
}
|
|
351
|
+
int n = snprintf(probe, rlen + 16, "k = %s\n", replacement);
|
|
307
352
|
teptris_document *probe_doc = NULL;
|
|
308
|
-
teptris_status st = teptris_parse(probe, (size_t)n, NULL,
|
|
353
|
+
teptris_status st = teptris_parse(probe, (size_t)n, NULL,
|
|
354
|
+
&probe_doc);
|
|
355
|
+
free(probe);
|
|
309
356
|
if (st != TEPTRIS_OK) {
|
|
310
357
|
if (probe_doc != NULL) {
|
|
311
358
|
teptris_document_free(probe_doc);
|
|
@@ -355,7 +402,11 @@ teptris_status teptris_edit_scalar(const char *src, size_t len,
|
|
|
355
402
|
if (eq < le && *eq == '=') {
|
|
356
403
|
const char *vs;
|
|
357
404
|
const char *ve;
|
|
358
|
-
|
|
405
|
+
int verified = 0;
|
|
406
|
+
/* the span scan bounds at the whole source:
|
|
407
|
+
* multiline and inline values cross lines */
|
|
408
|
+
if (edit_value_span(eq + 1, end, &vs, &ve,
|
|
409
|
+
&verified) != 0) {
|
|
359
410
|
return TEPTRIS_ERR_ARG;
|
|
360
411
|
}
|
|
361
412
|
size_t rlen = strlen(replacement);
|
|
@@ -368,6 +419,22 @@ teptris_status teptris_edit_scalar(const char *src, size_t len,
|
|
|
368
419
|
memcpy(out, src, pre);
|
|
369
420
|
memcpy(out + pre, replacement, rlen);
|
|
370
421
|
memcpy(out + pre + rlen, ve, post);
|
|
422
|
+
if (verified) {
|
|
423
|
+
/* v2 spans are parse-verified: a
|
|
424
|
+
* mis-scanned span rejects instead of
|
|
425
|
+
* corrupting */
|
|
426
|
+
teptris_document *vd = NULL;
|
|
427
|
+
teptris_status vst = teptris_parse(out,
|
|
428
|
+
pre + rlen + post, NULL, &vd);
|
|
429
|
+
if (vst != TEPTRIS_OK) {
|
|
430
|
+
if (vd != NULL) {
|
|
431
|
+
teptris_document_free(vd);
|
|
432
|
+
}
|
|
433
|
+
free(out);
|
|
434
|
+
return TEPTRIS_ERR_ARG;
|
|
435
|
+
}
|
|
436
|
+
teptris_document_free(vd);
|
|
437
|
+
}
|
|
371
438
|
*buf = out;
|
|
372
439
|
*out_len = pre + rlen + post;
|
|
373
440
|
return TEPTRIS_OK;
|
|
@@ -105,7 +105,7 @@ teptris_status teptris_parse_datetime(teptris_parser *ps, teptris_node **out)
|
|
|
105
105
|
int mi = d2(p + 3);
|
|
106
106
|
int s = 0; /* TOML 1.1: seconds optional */
|
|
107
107
|
size_t consumed = 5;
|
|
108
|
-
if (p[5] == ':') {
|
|
108
|
+
if ((size_t)(end - p) >= 6 && p[5] == ':') {
|
|
109
109
|
if ((size_t)(end - p) < 8 || !is_dig(p + 6) || !is_dig(p + 7)) {
|
|
110
110
|
return tep_fail_at(ps, NULL, TEPTRIS_ERR_SYNTAX,
|
|
111
111
|
"invalid second");
|
|
@@ -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
|
|