teptris 0.3.0.0 → 0.3.0.2

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: cf5a1fa223f1c0433fe701c5e6c4f6e7c668ef7ac5cc791558c47d617cb9fab6
4
- data.tar.gz: 643f2114b3db3dd901104276625fb72da8ec9c4198b8c31ce9a241cf987094e7
3
+ metadata.gz: 16869d7dc17dada9785490a4cc1268a02c36a4926a198b31f692021af453835a
4
+ data.tar.gz: 53a738130ff1d160c40f6e40fef79d41d4920f5188372ba626a1bf5090a83d74
5
5
  SHA512:
6
- metadata.gz: 5b1d16d9325a9f6829f451b26896e5a737259dbe18992c8bc26a37be761f08cce0552d0810792382af94cf5ff81eb5b95732732cb0a3b188eed3c82cd16c2a67
7
- data.tar.gz: d1984ec5fc728957ac20e0dc62b5a440690699d06487ae5c8937f67ab57a289177dcaac6af96edb10460b3089608c9b00f5a3be8a3cd0130ae858f743c96dc00
6
+ metadata.gz: 6c1fde58fa36cce4e57af73453ace01e0ddcb82c08f83d9e1d0be3d95038fe2046d5a686f539ab41f451cc7289c10d2376bf5b29452dd2208a877cbd85598cbf
7
+ data.tar.gz: 45b1747790ff1a16b5d26f688c15b2dd3a9b31d2c9772af0a2f82564ee42548a5647a525383e768295e90fa4a13b6adc90be5701c69c88c253efad575f85094d
@@ -1,4 +1,4 @@
1
- # libteptris 0.1.27 — vendored source
1
+ # libteptris 0.3.0 — 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
@@ -142,6 +142,16 @@ TEPTRIS_API teptris_status teptris_document_emit(const teptris_document *doc,
142
142
  TEPTRIS_API teptris_status teptris_document_emit_json(const teptris_document *doc,
143
143
  char **buf, size_t *len);
144
144
 
145
+ /* Natural-JSON emit: host-shaped values - real numbers, JSON
146
+ * booleans, datetimes as RFC 3339 strings (offset form carries its
147
+ * offset; the four TOML datetime shapes render date, time,
148
+ * date-time, and offset date-time). Two deliberate, lossy mappings:
149
+ * non-finite floats (TOML allows nan/inf) become null, and a
150
+ * datetime is indistinguishable from a same-shaped JSON string.
151
+ * Memory: *buf is malloc'd; caller frees with free(). */
152
+ TEPTRIS_API teptris_status teptris_document_emit_json_natural(
153
+ const teptris_document *doc, char **buf, size_t *len);
154
+
145
155
  /* Bulk drain for FFI/ctypes bindings: the whole tree in ONE crossing as
146
156
  * a self-describing flat buffer (explicit little-endian):
147
157
  * table 0x01 u32 n *(u32 klen key node)
@@ -2,8 +2,8 @@
2
2
  #define TEPTRIS_VERSION_H
3
3
 
4
4
  #define TEPTRIS_VERSION_MAJOR 0
5
- #define TEPTRIS_VERSION_MINOR 1
6
- #define TEPTRIS_VERSION_PATCH 27
7
- #define TEPTRIS_VERSION_STRING "0.1.27"
5
+ #define TEPTRIS_VERSION_MINOR 3
6
+ #define TEPTRIS_VERSION_PATCH 0
7
+ #define TEPTRIS_VERSION_STRING "0.3.0"
8
8
 
9
9
  #endif /* TEPTRIS_VERSION_H */
@@ -218,6 +218,12 @@ teptris_status teptris_document_emit_json(const teptris_document *doc,
218
218
  return teptris_emit_document_json(doc, buf, len);
219
219
  }
220
220
 
221
+ teptris_status teptris_document_emit_json_natural(
222
+ const teptris_document *doc, char **buf, size_t *len)
223
+ {
224
+ return teptris_emit_document_json_natural(doc, buf, len);
225
+ }
226
+
221
227
  /* --------------------------------------------------- bulk flatten ----- */
222
228
 
223
229
  typedef struct {
@@ -699,6 +699,78 @@ static void emit_json_value(ebuf *b, const teptris_node *n)
699
699
  }
700
700
  }
701
701
 
702
+ /* Natural-JSON emit (#101 v1): host-shaped values instead of the
703
+ * toml-test dialect - real numbers, booleans as JSON booleans,
704
+ * datetimes as RFC 3339 strings (offset form carries its offset).
705
+ * The two lossy spots are deliberate and documented in the header:
706
+ * non-finite floats become null (JSON has no nan/inf), and the
707
+ * datetime KIND is not distinguishable from a same-shaped string. */
708
+ static void emit_json_nat_value(ebuf *b, const teptris_node *n)
709
+ {
710
+ switch (n->kind) {
711
+ case TEPTRIS_TABLE:
712
+ eb_c(b, '{');
713
+ for (size_t i = 0; i < n->as.table.len; i++) {
714
+ if (i > 0) {
715
+ eb_c(b, ',');
716
+ }
717
+ json_string(b, n->as.table.entries[i].key);
718
+ eb_c(b, ':');
719
+ emit_json_nat_value(b, n->as.table.entries[i].value);
720
+ }
721
+ eb_c(b, '}');
722
+ break;
723
+ case TEPTRIS_ARRAY:
724
+ eb_c(b, '[');
725
+ for (size_t i = 0; i < n->as.array.len; i++) {
726
+ if (i > 0) {
727
+ eb_c(b, ',');
728
+ }
729
+ emit_json_nat_value(b, n->as.array.items[i]);
730
+ }
731
+ eb_c(b, ']');
732
+ break;
733
+ case TEPTRIS_STRING:
734
+ json_string(b, n->as.str);
735
+ break;
736
+ case TEPTRIS_INTEGER:
737
+ emit_i64(b, n->as.i);
738
+ break;
739
+ case TEPTRIS_FLOAT:
740
+ if (isnan(n->as.f) || isinf(n->as.f)) {
741
+ eb_str(b, "null");
742
+ } else {
743
+ emit_float(b, n->as.f);
744
+ }
745
+ break;
746
+ case TEPTRIS_BOOLEAN:
747
+ eb_str(b, n->as.b ? "true" : "false");
748
+ break;
749
+ default:
750
+ eb_c(b, '"');
751
+ emit_dt(b, &n->as.dt, (teptris_kind)n->kind);
752
+ eb_c(b, '"');
753
+ }
754
+ }
755
+
756
+ teptris_status teptris_emit_document_json_natural(
757
+ const teptris_document *doc, char **buf, size_t *len)
758
+ {
759
+ if (doc == NULL || doc->root == NULL) {
760
+ return TEPTRIS_ERR_ARG;
761
+ }
762
+ ebuf b = {0, 0, 0, TEPTRIS_OK};
763
+ eb_reserve(&b, 256);
764
+ emit_json_nat_value(&b, doc->root);
765
+ if (b.st != TEPTRIS_OK) {
766
+ return b.st;
767
+ }
768
+ eb_c(&b, '\0');
769
+ *buf = b.p;
770
+ *len = b.len - 1;
771
+ return TEPTRIS_OK;
772
+ }
773
+
702
774
  teptris_status teptris_emit_document_json(const teptris_document *doc,
703
775
  char **buf, size_t *len)
704
776
  {
@@ -8,4 +8,7 @@ teptris_status teptris_emit_document(const teptris_document *doc, char **buf,
8
8
  teptris_status teptris_emit_document_json(const teptris_document *doc,
9
9
  char **buf, size_t *len);
10
10
 
11
+ teptris_status teptris_emit_document_json_natural(
12
+ const teptris_document *doc, char **buf, size_t *len);
13
+
11
14
  #endif /* TEPTRIS_EMITTER_H */
@@ -438,7 +438,9 @@ static void build_value(teptris_builder *b, VALUE v) {
438
438
  }
439
439
  }
440
440
 
441
- static VALUE ext_dump(VALUE self, VALUE obj) {
441
+ static VALUE dump_with(VALUE obj,
442
+ teptris_status (*emit)(const teptris_document *,
443
+ char **, size_t *)) {
442
444
  if (!RB_TYPE_P(obj, T_HASH))
443
445
  rb_raise(rb_eArgError, "cannot dump %s (root must be a Hash)",
444
446
  rb_obj_classname(obj));
@@ -454,7 +456,7 @@ static VALUE ext_dump(VALUE self, VALUE obj) {
454
456
  }
455
457
  char *buf = NULL;
456
458
  size_t len = 0;
457
- st = teptris_document_emit(doc, &buf, &len);
459
+ st = emit(doc, &buf, &len);
458
460
  teptris_document_free(doc);
459
461
  teptris_builder_free(b); /* doc already transferred/freed */
460
462
  if (st != TEPTRIS_OK)
@@ -464,6 +466,17 @@ static VALUE ext_dump(VALUE self, VALUE obj) {
464
466
  return out;
465
467
  }
466
468
 
469
+ static VALUE ext_dump(VALUE self, VALUE obj) {
470
+ return dump_with(obj, teptris_document_emit);
471
+ }
472
+
473
+ /* Natural JSON (engine 0.3.0): real numbers, booleans, RFC 3339
474
+ * datetime strings — the mappings Teptris.dump_json_natural
475
+ * documents. Non-finite floats become null. */
476
+ static VALUE ext_dump_json_natural(VALUE self, VALUE obj) {
477
+ return dump_with(obj, teptris_document_emit_json_natural);
478
+ }
479
+
467
480
  /* ------------------------------------------------- plan-walk (teptris#46) */
468
481
 
469
482
  static void plan_free(void *p) { teptris_plan_free((teptris_plan *)p); }
@@ -1213,6 +1226,8 @@ void Init_teptris_ext(void) {
1213
1226
  rb_define_method(cLazyValue, "to_a", lazy_to, 0);
1214
1227
  rb_define_method(cLazyValue, "value", lazy_to, 0);
1215
1228
  rb_define_module_function(m, "dump", ext_dump, 1);
1229
+ rb_define_module_function(m, "dump_json_natural", ext_dump_json_natural,
1230
+ 1);
1216
1231
  rb_define_module_function(m, "engine_version", ext_version, 0);
1217
1232
  rb_define_module_function(m, "plan_build", ext_plan_build, 2);
1218
1233
  rb_define_module_function(m, "plan_emit", ext_plan_emit, 2);
data/lib/teptris/toml.rb CHANGED
@@ -150,6 +150,13 @@ module Teptris::TOML
150
150
  TeptrisExt.dump(obj)
151
151
  end
152
152
 
153
+ # Natural JSON (engine 0.3.0): real numbers, booleans, RFC 3339
154
+ # datetime strings. Non-finite floats become null — the same
155
+ # documented lossy mapping as teptris.h's natural-JSON contract.
156
+ def dump_json_natural(obj)
157
+ TeptrisExt.dump_json_natural(obj)
158
+ end
159
+
153
160
  private
154
161
 
155
162
  def _validate_batch!(input, safe_load, datetime_policy, kind: :strings)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Teptris
4
- VERSION = "0.3.0.0"
4
+ VERSION = "0.3.0.2"
5
5
  end
data/sig/teptris.rbs CHANGED
@@ -49,6 +49,8 @@ module Teptris
49
49
 
50
50
  def self.dump: (untyped obj) -> String
51
51
 
52
+ def self.dump_json_natural: (untyped obj) -> String
53
+
52
54
  def self.engine_version: () -> String
53
55
 
54
56
  def self._validate_batch!: (untyped input, untyped safe_load,
@@ -122,6 +124,8 @@ module TeptrisExt
122
124
 
123
125
  def self.dump: (untyped obj) -> String
124
126
 
127
+ def self.dump_json_natural: (untyped obj) -> String
128
+
125
129
  def self.engine_version: () -> String
126
130
 
127
131
  def self.plan_build: (Array[[String, Integer, Integer]] rows,
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.0.0
4
+ version: 0.3.0.2
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-07 00:00:00.000000000 Z
11
+ date: 2026-10-08 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.