teptris 0.3.15.0-powerpc64le-linux → 0.3.17.0-powerpc64le-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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 936692a95b1c6e7ec70bbd90b32961f78c291a825b35dfcb9808e93dc2f92332
4
- data.tar.gz: cf70bbda9096fdddf2123921ed64bda63232d9a43778d96e0809d1be1bc54dd1
3
+ metadata.gz: 18a9839827b9e0a6173c0a127be80e56a4f327f2e4272316f79805b8fb7d00a3
4
+ data.tar.gz: 204acfc8740f72c05a9a5f3bd35c18cbf46c430dc9f35ccadce6474ae543d715
5
5
  SHA512:
6
- metadata.gz: '09cd7810f19ce69342c6a17aef51745feba8be0f62e4dd3e1e54269d8865b11e1bbdbad54a66aed11278dcd3bf3926907da4610828baf558fc714f45af2fa678'
7
- data.tar.gz: f8da9a59684dbdbee1439513e934335fcf958898b943d8df6a9eeceda034ca00c28dc27148e9cdf5b1a7304a3a356b33517a5e10bf1622b0ecb1d6f3f54280fc
6
+ metadata.gz: 50a5ff65deac4c28c8395bf2ab8ecbfc9f5aa9d52511b09d266eefd6816d364ae65d875cb38e64ba7e37f3f71f589bb3261877673154f6dc565764a038da2125
7
+ data.tar.gz: 01d235458b37d3ae7a86ff100c53ccd2357127b3acb9618c4b1b71b869bc4288aff978b6556ce42da53bc40c46cf47e94c7bca5d21edf76dd12bd33c604ce8ec
@@ -1,4 +1,4 @@
1
- # libteptris 0.3.15 — vendored source
1
+ # libteptris 0.3.17 — vendored source
2
2
 
3
3
  This directory carries the COMPLETE C source of the engine this
4
4
  gem's extension was built from (the packaging doctrine: compiled
@@ -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 v1): rewrite exactly the
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). 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. */
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,
@@ -4,6 +4,6 @@
4
4
  #define TEPTRIS_VERSION_MAJOR 0
5
5
  #define TEPTRIS_VERSION_MINOR 3
6
6
  #define TEPTRIS_VERSION_PATCH 0
7
- #define TEPTRIS_VERSION_STRING "0.3.15"
7
+ #define TEPTRIS_VERSION_STRING "0.3.17"
8
8
 
9
9
  #endif /* TEPTRIS_VERSION_H */
@@ -1,4 +1,4 @@
1
- /* Format-preserving scalar edit (v1): rewrite exactly the value bytes
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
- * 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. */
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
- /* 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. */
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
- if (*p == '\'') {
182
- p++;
183
- while (p < end && *p != '\'') {
184
- if (*p == '\n') {
185
- return -1;
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
- } 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;
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 (*p == '\\' && p + 1 < end) {
203
- p += 2;
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 (p >= end) {
209
- return -1;
254
+ if (ve == NULL) {
255
+ return -1; /* unbalanced inline collection */
210
256
  }
211
- p++;
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 = p;
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 > 4096) {
372
+ if (rlen == 0 || rlen > 16384) {
297
373
  return TEPTRIS_ERR_ARG;
298
374
  }
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;
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, &probe_doc);
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
- if (edit_value_span(eq + 1, le, &vs, &ve) != 0) {
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Teptris
4
- VERSION = "0.3.15.0"
4
+ VERSION = "0.3.17.0"
5
5
  end
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.15.0
4
+ version: 0.3.17.0
5
5
  platform: powerpc64le-linux
6
6
  authors:
7
7
  - teptris contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-10-31 00:00:00.000000000 Z
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.