yeptris 0.6.18.2-arm-linux-eabihf

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.
Files changed (142) hide show
  1. checksums.yaml +7 -0
  2. data/README.adoc +141 -0
  3. data/ext/build_windows_native.rb +41 -0
  4. data/ext/libyeptris/extconf.rb +57 -0
  5. data/ext/yeptris_native/cbor_ruby.c +193 -0
  6. data/ext/yeptris_native/extconf.rb +47 -0
  7. data/ext/yeptris_native/json_ruby.c +354 -0
  8. data/ext/yeptris_native/yeptris_native.c +497 -0
  9. data/lib/yeptris/cbor.rb +130 -0
  10. data/lib/yeptris/document.rb +255 -0
  11. data/lib/yeptris/ffi.rb +426 -0
  12. data/lib/yeptris/json/descriptor.rb +266 -0
  13. data/lib/yeptris/json.rb +394 -0
  14. data/lib/yeptris/materializer.rb +354 -0
  15. data/lib/yeptris/native-3.4.so +0 -0
  16. data/lib/yeptris/node.rb +453 -0
  17. data/lib/yeptris/psych/class_loader.rb +24 -0
  18. data/lib/yeptris/psych/coder_shim.rb +55 -0
  19. data/lib/yeptris/psych/drop_in.rb +63 -0
  20. data/lib/yeptris/psych/encodable.rb +14 -0
  21. data/lib/yeptris/psych/handler.rb +90 -0
  22. data/lib/yeptris/psych/parser.rb +105 -0
  23. data/lib/yeptris/psych/scalar_scanner.rb +149 -0
  24. data/lib/yeptris/psych/visitors.rb +545 -0
  25. data/lib/yeptris/psych.rb +622 -0
  26. data/lib/yeptris/schema.rb +253 -0
  27. data/lib/yeptris/valueml.rb +455 -0
  28. data/lib/yeptris/yaml/descriptor.rb +56 -0
  29. data/lib/yeptris/yaml.rb +422 -0
  30. data/lib/yeptris.rb +113 -0
  31. data/libyeptris.so +0 -0
  32. data/vendor/libyeptris/CMakeLists.txt +254 -0
  33. data/vendor/libyeptris/cmake/yeptris-config.cmake.in +5 -0
  34. data/vendor/libyeptris/cmake/yeptris.pc.in +11 -0
  35. data/vendor/libyeptris/src/CMakeLists.txt +167 -0
  36. data/vendor/libyeptris/src/include/yeptris/api.h +32 -0
  37. data/vendor/libyeptris/src/include/yeptris/cbor.h +101 -0
  38. data/vendor/libyeptris/src/include/yeptris/dom.h +190 -0
  39. data/vendor/libyeptris/src/include/yeptris/emit.h +81 -0
  40. data/vendor/libyeptris/src/include/yeptris/error.h +41 -0
  41. data/vendor/libyeptris/src/include/yeptris/events.h +157 -0
  42. data/vendor/libyeptris/src/include/yeptris/json.h +45 -0
  43. data/vendor/libyeptris/src/include/yeptris/json.hpp +258 -0
  44. data/vendor/libyeptris/src/include/yeptris/jsonc_compat.h +115 -0
  45. data/vendor/libyeptris/src/include/yeptris/marshal.h +52 -0
  46. data/vendor/libyeptris/src/include/yeptris/parse.h +48 -0
  47. data/vendor/libyeptris/src/include/yeptris/plan.h +100 -0
  48. data/vendor/libyeptris/src/include/yeptris/resolve.h +71 -0
  49. data/vendor/libyeptris/src/include/yeptris/schema.h +121 -0
  50. data/vendor/libyeptris/src/include/yeptris/tape.h +123 -0
  51. data/vendor/libyeptris/src/include/yeptris/types.h +38 -0
  52. data/vendor/libyeptris/src/include/yeptris/values.h +102 -0
  53. data/vendor/libyeptris/src/include/yeptris/version.h.in +29 -0
  54. data/vendor/libyeptris/src/include/yeptris/visit.h +77 -0
  55. data/vendor/libyeptris/src/include/yeptris/yajl_compat.h +135 -0
  56. data/vendor/libyeptris/src/include/yeptris.h +23 -0
  57. data/vendor/libyeptris/src/yeptris/build.c +376 -0
  58. data/vendor/libyeptris/src/yeptris/cbor/cbor.h +25 -0
  59. data/vendor/libyeptris/src/yeptris/cbor/decode.c +981 -0
  60. data/vendor/libyeptris/src/yeptris/cbor/encode.c +835 -0
  61. data/vendor/libyeptris/src/yeptris/cbor/sink.h +58 -0
  62. data/vendor/libyeptris/src/yeptris/common/chartype.c +41 -0
  63. data/vendor/libyeptris/src/yeptris/common/chartype.h +77 -0
  64. data/vendor/libyeptris/src/yeptris/common/cpu.c +81 -0
  65. data/vendor/libyeptris/src/yeptris/common/cpu.h +40 -0
  66. data/vendor/libyeptris/src/yeptris/common/error.c +65 -0
  67. data/vendor/libyeptris/src/yeptris/common/error.h +79 -0
  68. data/vendor/libyeptris/src/yeptris/common/mutex.h +45 -0
  69. data/vendor/libyeptris/src/yeptris/common/nametab.c +275 -0
  70. data/vendor/libyeptris/src/yeptris/common/nametab.h +68 -0
  71. data/vendor/libyeptris/src/yeptris/common/port.h +74 -0
  72. data/vendor/libyeptris/src/yeptris/common/simd_text.c +49 -0
  73. data/vendor/libyeptris/src/yeptris/common/simd_text.h +295 -0
  74. data/vendor/libyeptris/src/yeptris/common/simd_text_avx2.c +534 -0
  75. data/vendor/libyeptris/src/yeptris/common/simd_text_neon.c +662 -0
  76. data/vendor/libyeptris/src/yeptris/common/simd_text_scalar.c +298 -0
  77. data/vendor/libyeptris/src/yeptris/common/string_view.c +34 -0
  78. data/vendor/libyeptris/src/yeptris/common/string_view.h +93 -0
  79. data/vendor/libyeptris/src/yeptris/doc.h +56 -0
  80. data/vendor/libyeptris/src/yeptris/dom/dom.c +1192 -0
  81. data/vendor/libyeptris/src/yeptris/dom/dom.h +312 -0
  82. data/vendor/libyeptris/src/yeptris/dom/hpool.c +107 -0
  83. data/vendor/libyeptris/src/yeptris/dom/mapindex.c +173 -0
  84. data/vendor/libyeptris/src/yeptris/dom/mapindex.h +61 -0
  85. data/vendor/libyeptris/src/yeptris/dom/mutate.c +431 -0
  86. data/vendor/libyeptris/src/yeptris/emit/emit.c +434 -0
  87. data/vendor/libyeptris/src/yeptris/emit/float/api.h +38 -0
  88. data/vendor/libyeptris/src/yeptris/emit/float/dragon.c +405 -0
  89. data/vendor/libyeptris/src/yeptris/emit/float/floatint.h +231 -0
  90. data/vendor/libyeptris/src/yeptris/emit/float/print.c +396 -0
  91. data/vendor/libyeptris/src/yeptris/emit/style.c +81 -0
  92. data/vendor/libyeptris/src/yeptris/emit/style.h +24 -0
  93. data/vendor/libyeptris/src/yeptris/emit/writer.c +816 -0
  94. data/vendor/libyeptris/src/yeptris/emit/writer.h +76 -0
  95. data/vendor/libyeptris/src/yeptris/encoding/bom.c +31 -0
  96. data/vendor/libyeptris/src/yeptris/encoding/encoding.h +63 -0
  97. data/vendor/libyeptris/src/yeptris/encoding/transcode.c +148 -0
  98. data/vendor/libyeptris/src/yeptris/encoding/utf8_validate.c +178 -0
  99. data/vendor/libyeptris/src/yeptris/events/capture.c +150 -0
  100. data/vendor/libyeptris/src/yeptris/events/capture.h +39 -0
  101. data/vendor/libyeptris/src/yeptris/events/iterparse.c +208 -0
  102. data/vendor/libyeptris/src/yeptris/events/pull.c +97 -0
  103. data/vendor/libyeptris/src/yeptris/events/push.c +104 -0
  104. data/vendor/libyeptris/src/yeptris/events/recorder.c +107 -0
  105. data/vendor/libyeptris/src/yeptris/events/values.c +527 -0
  106. data/vendor/libyeptris/src/yeptris/events/values_priv.h +51 -0
  107. data/vendor/libyeptris/src/yeptris/events/yaml_compat.c +86 -0
  108. data/vendor/libyeptris/src/yeptris/events/yaml_compat.h +90 -0
  109. data/vendor/libyeptris/src/yeptris/jsonapi/jsonc_compat.c +687 -0
  110. data/vendor/libyeptris/src/yeptris/jsonapi/yajl_compat.c +728 -0
  111. data/vendor/libyeptris/src/yeptris/marshal.c +782 -0
  112. data/vendor/libyeptris/src/yeptris/memory/allocator.c +20 -0
  113. data/vendor/libyeptris/src/yeptris/memory/allocator.h +43 -0
  114. data/vendor/libyeptris/src/yeptris/memory/arena.c +134 -0
  115. data/vendor/libyeptris/src/yeptris/memory/arena.h +52 -0
  116. data/vendor/libyeptris/src/yeptris/memory/pool.c +122 -0
  117. data/vendor/libyeptris/src/yeptris/memory/pool.h +36 -0
  118. data/vendor/libyeptris/src/yeptris/parse/engine.c +3698 -0
  119. data/vendor/libyeptris/src/yeptris/parse/engine.h +65 -0
  120. data/vendor/libyeptris/src/yeptris/parse/events.h +124 -0
  121. data/vendor/libyeptris/src/yeptris/parse/numbers.c +349 -0
  122. data/vendor/libyeptris/src/yeptris/parse/numbers.h +33 -0
  123. data/vendor/libyeptris/src/yeptris/parse/scalars.c +416 -0
  124. data/vendor/libyeptris/src/yeptris/parse/scalars.h +75 -0
  125. data/vendor/libyeptris/src/yeptris/parse.c +737 -0
  126. data/vendor/libyeptris/src/yeptris/plan.c +824 -0
  127. data/vendor/libyeptris/src/yeptris/resolve/compat11.c +334 -0
  128. data/vendor/libyeptris/src/yeptris/resolve/core12.c +143 -0
  129. data/vendor/libyeptris/src/yeptris/resolve/resolver.h +56 -0
  130. data/vendor/libyeptris/src/yeptris/resolve/tags.c +58 -0
  131. data/vendor/libyeptris/src/yeptris/scan/json.c +792 -0
  132. data/vendor/libyeptris/src/yeptris/scan/json.h +109 -0
  133. data/vendor/libyeptris/src/yeptris/scan/scan.c +463 -0
  134. data/vendor/libyeptris/src/yeptris/scan/scan.h +150 -0
  135. data/vendor/libyeptris/src/yeptris/schema.c +308 -0
  136. data/vendor/libyeptris/src/yeptris/tape.c +1308 -0
  137. data/vendor/libyeptris/src/yeptris/tape_in.h +19 -0
  138. data/vendor/libyeptris/src/yeptris/version.c +7 -0
  139. data/vendor/libyeptris/src/yeptris/visit/dom_visit.c +115 -0
  140. data/vendor/libyeptris/src/yeptris/visit/json_visit.c +293 -0
  141. data/vendor/libyeptris/src/yeptris/visit/yaml_visit.c +127 -0
  142. metadata +199 -0
@@ -0,0 +1,376 @@
1
+ /* build.c — the public from-scratch construction API (TODO.impl/11
2
+ * phase 3). Thin: argument checking + handle wrapping over the dom
3
+ * mutation primitives. The emitter and every query API work on
4
+ * synthesized documents unchanged — same nodes, same invariants. */
5
+
6
+ #include <stdio.h>
7
+ #include <string.h>
8
+
9
+ #include <yeptris.h>
10
+
11
+ #include "doc.h"
12
+ #include "dom/dom.h"
13
+ #include "memory/allocator.h"
14
+
15
+ static yeptris_document* doc_of(YeptrisDocument handle) {
16
+ return (yeptris_document*)handle;
17
+ }
18
+
19
+ static yeptris_node* node_of(YeptrisNode handle) {
20
+ return (yeptris_node*)handle;
21
+ }
22
+
23
+ YEPTRIS_API YeptrisDocument yeptris_document_new(void) {
24
+ const yep_allocator* sys = yep_system_allocator();
25
+ yep_dom* dom = yep_dom_create(sys);
26
+ if (dom == NULL) {
27
+ return NULL;
28
+ }
29
+ yeptris_document* doc = yep_alloc(sys, sizeof(yeptris_document));
30
+ if (doc == NULL) {
31
+ yep_dom_destroy(dom);
32
+ return NULL;
33
+ }
34
+ memset(doc, 0, sizeof(*doc));
35
+ doc->dom = dom;
36
+ doc->sys = sys;
37
+ return (YeptrisDocument)doc;
38
+ }
39
+
40
+ YEPTRIS_API int yeptris_document_set_root(YeptrisDocument handle, YeptrisNode root) {
41
+ yeptris_document* doc = doc_of(handle);
42
+ yeptris_node* n = node_of(root);
43
+ if (doc == NULL || n == NULL || n->doc != doc) {
44
+ return YEPTRIS_ERROR_PARSE;
45
+ }
46
+ int rc = yep_mut_add_root(doc->dom, n->id);
47
+ return rc == 0 ? YEPTRIS_OK
48
+ : (rc == -1 ? YEPTRIS_ERROR_MEMORY
49
+ : (rc == -3 ? YEPTRIS_ERROR_DEPTH : YEPTRIS_ERROR_ARG));
50
+ }
51
+
52
+ YEPTRIS_API YeptrisNode yeptris_node_new_mapping(YeptrisDocument handle) {
53
+ yeptris_document* doc = doc_of(handle);
54
+ if (doc == NULL) {
55
+ return NULL;
56
+ }
57
+ uint32_t id = yep_mut_map(doc->dom, 0);
58
+ return id == UINT32_MAX ? NULL : (YeptrisNode)yep_handle_new(doc, id);
59
+ }
60
+
61
+ YEPTRIS_API YeptrisNode yeptris_node_new_sequence(YeptrisDocument handle) {
62
+ yeptris_document* doc = doc_of(handle);
63
+ if (doc == NULL) {
64
+ return NULL;
65
+ }
66
+ uint32_t id = yep_mut_seq(doc->dom, 0);
67
+ return id == UINT32_MAX ? NULL : (YeptrisNode)yep_handle_new(doc, id);
68
+ }
69
+
70
+ /* Memory: the value is copied into the document (nothing is borrowed
71
+ * from the caller). Plain style types the copy through the resolver,
72
+ * quoted styles force string — identical to parse-time typing. */
73
+ YEPTRIS_API YeptrisNode yeptris_node_new_scalar(YeptrisDocument handle, const char* value,
74
+ size_t len, YeptrisScalarStyle style) {
75
+ yeptris_document* doc = doc_of(handle);
76
+ if (doc == NULL || (value == NULL && len > 0) || style < YEPTRIS_STYLE_PLAIN ||
77
+ style > YEPTRIS_STYLE_FOLDED) {
78
+ return NULL;
79
+ }
80
+ uint32_t id = yep_mut_scalar(doc->dom, value, len, (uint8_t)style);
81
+ return id == UINT32_MAX ? NULL : (YeptrisNode)yep_handle_new(doc, id);
82
+ }
83
+
84
+ static int mut_status(int rc) {
85
+ switch (rc) {
86
+ case 0:
87
+ case 1: /* map_set replaced — success for the caller */
88
+ return YEPTRIS_OK;
89
+ case -1:
90
+ return YEPTRIS_ERROR_MEMORY;
91
+ case -3:
92
+ return YEPTRIS_ERROR_DEPTH;
93
+ default: /* -2 duplicate key, -4 double-attach */
94
+ return YEPTRIS_ERROR_PARSE;
95
+ }
96
+ }
97
+
98
+ static int same_doc(YeptrisNode parent, YeptrisNode child) {
99
+ yeptris_node* p = node_of(parent);
100
+ yeptris_node* c = node_of(child);
101
+ return p != NULL && c != NULL && p->doc == c->doc;
102
+ }
103
+
104
+ YEPTRIS_API int yeptris_node_map_add(YeptrisNode handle, const char* key, size_t key_len,
105
+ YeptrisNode value) {
106
+ yeptris_node* m = node_of(handle);
107
+ if (m == NULL || key == NULL || !same_doc(handle, value)) {
108
+ return YEPTRIS_ERROR_ARG;
109
+ }
110
+ return mut_status(yep_mut_map_add(m->doc->dom, m->id, key, key_len, node_of(value)->id));
111
+ }
112
+
113
+ /* Replace-or-add (json-c semantics): an existing key keeps its
114
+ * position and swaps the value; a new key appends. */
115
+ YEPTRIS_API int yeptris_node_map_set(YeptrisNode handle, const char* key, size_t key_len,
116
+ YeptrisNode value) {
117
+ yeptris_node* m = node_of(handle);
118
+ if (m == NULL || key == NULL || !same_doc(handle, value)) {
119
+ return YEPTRIS_ERROR_ARG;
120
+ }
121
+ return mut_status(yep_mut_map_set(m->doc->dom, m->id, key, key_len, node_of(value)->id));
122
+ }
123
+
124
+ YEPTRIS_API int yeptris_node_seq_add(YeptrisNode handle, YeptrisNode value) {
125
+ yeptris_node* s = node_of(handle);
126
+ if (s == NULL || !same_doc(handle, value)) {
127
+ return YEPTRIS_ERROR_ARG;
128
+ }
129
+ return mut_status(yep_mut_seq_add(s->doc->dom, s->id, node_of(value)->id));
130
+ }
131
+
132
+ YEPTRIS_API int yeptris_node_seq_set(YeptrisNode handle, size_t index, YeptrisNode value) {
133
+ yeptris_node* s = node_of(handle);
134
+ if (s == NULL || !same_doc(handle, value)) {
135
+ return YEPTRIS_ERROR_ARG;
136
+ }
137
+ return mut_status(yep_mut_seq_set(s->doc->dom, s->id, (uint32_t)index, node_of(value)->id));
138
+ }
139
+
140
+ YEPTRIS_API int yeptris_node_seq_del(YeptrisNode handle, size_t index) {
141
+ yeptris_node* s = node_of(handle);
142
+ if (s == NULL) {
143
+ return YEPTRIS_ERROR_ARG;
144
+ }
145
+ return yep_mut_seq_del(s->doc->dom, s->id, (uint32_t)index) == 0 ? YEPTRIS_OK
146
+ : YEPTRIS_ERROR_PARSE;
147
+ }
148
+
149
+ /* The removed subtree stays document-owned (arena lifetime); its
150
+ * handle remains valid but unreachable from the root. */
151
+ YEPTRIS_API int yeptris_node_set_anchor(YeptrisNode handle, const char* name, size_t len) {
152
+ yeptris_node* n = node_of(handle);
153
+ if (n == NULL || name == NULL) {
154
+ return YEPTRIS_ERROR_ARG;
155
+ }
156
+ return yep_mut_set_anchor(n->doc->dom, n->id, name, len) == 0 ? YEPTRIS_OK : YEPTRIS_ERROR_ARG;
157
+ }
158
+
159
+ YEPTRIS_API int yeptris_node_set_tag(YeptrisNode handle, const char* tag, size_t len) {
160
+ yeptris_node* n = node_of(handle);
161
+ if (n == NULL || tag == NULL) {
162
+ return YEPTRIS_ERROR_ARG;
163
+ }
164
+ return yep_mut_set_tag(n->doc->dom, n->id, tag, len) == 0 ? YEPTRIS_OK : YEPTRIS_ERROR_ARG;
165
+ }
166
+
167
+ YEPTRIS_API YeptrisNode yeptris_node_new_alias(YeptrisDocument handle, YeptrisNode target,
168
+ const char* name, size_t len) {
169
+ yeptris_document* doc = doc_of(handle);
170
+ yeptris_node* t = node_of(target);
171
+ if (doc == NULL || t == NULL || t->doc != doc || name == NULL) {
172
+ return NULL;
173
+ }
174
+ uint32_t id = yep_mut_new_alias(doc->dom, t->id, name, len);
175
+ return id == UINT32_MAX ? NULL : (YeptrisNode)yep_handle_new(doc, id);
176
+ }
177
+
178
+ YEPTRIS_API int yeptris_node_map_add_node(YeptrisNode handle, YeptrisNode key, YeptrisNode value) {
179
+ yeptris_node* m = node_of(handle);
180
+ if (m == NULL || !same_doc(handle, key) || !same_doc(handle, value)) {
181
+ return YEPTRIS_ERROR_ARG;
182
+ }
183
+ return mut_status(
184
+ yep_mut_map_add_node(m->doc->dom, m->id, node_of(key)->id, node_of(value)->id));
185
+ }
186
+
187
+ YEPTRIS_API int yeptris_node_map_del(YeptrisNode handle, const char* key, size_t key_len) {
188
+ yeptris_node* m = node_of(handle);
189
+ if (m == NULL || key == NULL) {
190
+ return YEPTRIS_ERROR_ARG;
191
+ }
192
+ return yep_mut_map_del(m->doc->dom, m->id, key, key_len) == 0 ? YEPTRIS_OK
193
+ : YEPTRIS_ERROR_PARSE;
194
+ }
195
+
196
+ /* ---- bulk build --------------------------------------------------------
197
+ *
198
+ * One call, one tree: entries walk in document order (the same shape
199
+ * as the event stream), pairing and linking ride the mutation
200
+ * primitives unchanged — dup checks, depth caps, and per-link depth
201
+ * fixups all come along for free (DRY with the public builder). */
202
+ YEPTRIS_API YeptrisStatus yeptris_document_build(YeptrisDocument handle,
203
+ const YeptrisBuildEntry* entries, size_t count,
204
+ const char* blob, size_t blob_len) {
205
+ yeptris_document* doc = doc_of(handle);
206
+ if (doc == NULL || (entries == NULL && count != 0) || (blob == NULL && blob_len != 0)) {
207
+ return YEPTRIS_ERROR_ARG;
208
+ }
209
+ struct frame {
210
+ uint32_t id;
211
+ uint8_t is_map;
212
+ uint8_t key_pending;
213
+ };
214
+ if (count > (SIZE_MAX / 2) / sizeof(struct frame)) {
215
+ return YEPTRIS_ERROR_ARG;
216
+ }
217
+ struct frame* st = yep_alloc(doc->dom->sys, (count + 1) * sizeof(*st));
218
+ if (st == NULL) {
219
+ return YEPTRIS_ERROR_MEMORY;
220
+ }
221
+ int depth = 0;
222
+ uint32_t root = UINT32_MAX;
223
+ uint32_t root_closed = 0;
224
+ uint32_t root_tagged = 0; /* one trailing TAG on the closed root (#168) */
225
+ uint32_t pending_key = UINT32_MAX; /* map frame's buffered key */
226
+ uint32_t last_id = UINT32_MAX; /* TAG applies here (#300) */
227
+ YeptrisStatus rc = YEPTRIS_OK;
228
+ for (size_t i = 0; i < count && rc == YEPTRIS_OK; i++) {
229
+ const YeptrisBuildEntry* e = &entries[i];
230
+ /* A closed SCALAR root admits exactly one trailing TAG —
231
+ * psych's binary root is `--- !binary |-` (#168); everything
232
+ * after (more ops, a second tag) still rejects */
233
+ if (root_closed && !(e->op == YEPTRIS_BUILD_TAG && !root_tagged && last_id == root)) {
234
+ rc = YEPTRIS_ERROR_PARSE; /* the document ended; more entries */
235
+ break;
236
+ }
237
+ if (e->off > blob_len || e->len > blob_len - e->off) {
238
+ rc = YEPTRIS_ERROR_PARSE; /* slice out of range */
239
+ break;
240
+ }
241
+ uint32_t id = UINT32_MAX; /* set by every arm that reaches the place; MSVC wants the init */
242
+ switch (e->op) {
243
+ case YEPTRIS_BUILD_SCALAR: {
244
+ id = yep_mut_scalar(doc->dom, blob + e->off, e->len, e->style);
245
+ if (id == UINT32_MAX) {
246
+ rc = YEPTRIS_ERROR_MEMORY;
247
+ break;
248
+ }
249
+ break;
250
+ }
251
+ case YEPTRIS_BUILD_SEQ:
252
+ id = yep_mut_seq(doc->dom, 0);
253
+ if (id == UINT32_MAX) {
254
+ rc = YEPTRIS_ERROR_MEMORY;
255
+ break;
256
+ }
257
+ break;
258
+ case YEPTRIS_BUILD_MAP:
259
+ id = yep_mut_map(doc->dom, 0);
260
+ if (id == UINT32_MAX) {
261
+ rc = YEPTRIS_ERROR_MEMORY;
262
+ break;
263
+ }
264
+ break;
265
+ case YEPTRIS_BUILD_END:
266
+ if (depth == 0) {
267
+ rc = YEPTRIS_ERROR_PARSE; /* END with nothing open */
268
+ break;
269
+ }
270
+ depth--;
271
+ if (depth == 0) {
272
+ root_closed = 1; /* the root just completed */
273
+ }
274
+ if (st[depth].is_map && st[depth].key_pending) {
275
+ st[depth].key_pending = 0; /* a closed container was the value */
276
+ }
277
+ continue;
278
+ case YEPTRIS_BUILD_TAG:
279
+ /* #300: apply an explicit tag to the last-placed node —
280
+ * the bulk ABI otherwise cannot express tags. Placed
281
+ * immediately after the entry it tags. */
282
+ if (last_id == UINT32_MAX) {
283
+ rc = YEPTRIS_ERROR_PARSE; /* TAG with nothing placed */
284
+ break;
285
+ }
286
+ if (yep_mut_set_tag(doc->dom, last_id, blob + e->off, e->len) != 0) {
287
+ rc = YEPTRIS_ERROR_MEMORY;
288
+ break;
289
+ }
290
+ root_tagged = root_closed;
291
+ continue;
292
+ default:
293
+ rc = YEPTRIS_ERROR_PARSE; /* unknown op */
294
+ break;
295
+ }
296
+ if (rc != YEPTRIS_OK) {
297
+ break;
298
+ }
299
+ last_id = id; /* TAG entries target this (#300) */
300
+ /* place the fresh node */
301
+ if (depth == 0) {
302
+ if (root != UINT32_MAX) {
303
+ rc = YEPTRIS_ERROR_PARSE; /* two roots */
304
+ break;
305
+ }
306
+ root = id; /* a single scalar root needs no END */
307
+ root_closed = (e->op != YEPTRIS_BUILD_SEQ && e->op != YEPTRIS_BUILD_MAP) ? 1 : 0;
308
+ if (!root_closed) {
309
+ st[depth].id = id;
310
+ st[depth].is_map = (e->op == YEPTRIS_BUILD_MAP);
311
+ st[depth].key_pending = 0;
312
+ depth = 1;
313
+ }
314
+ continue;
315
+ }
316
+ struct frame* top = &st[depth - 1];
317
+ if (top->is_map) {
318
+ if (!top->key_pending) {
319
+ top->key_pending = 1;
320
+ pending_key = id;
321
+ continue;
322
+ }
323
+ /* the check-free pairing twin: document-order entries
324
+ * from a host mapping cannot duplicate, and map_add's
325
+ * linear dup scan is O(n^2) on wide maps */
326
+ int mrc = yep_mut_map_append(doc->dom, top->id, pending_key, id);
327
+ if (mrc == 0) {
328
+ top->key_pending = 0;
329
+ pending_key = UINT32_MAX;
330
+ } else {
331
+ rc = (mrc == -3) ? YEPTRIS_ERROR_DEPTH
332
+ : (mrc == -1 ? YEPTRIS_ERROR_ARG : YEPTRIS_ERROR_MEMORY);
333
+ }
334
+ } else {
335
+ int src_ = yep_mut_seq_add(doc->dom, top->id, id);
336
+ if (src_ != 0) {
337
+ rc = (src_ == -3) ? YEPTRIS_ERROR_DEPTH
338
+ : (src_ == -1 ? YEPTRIS_ERROR_ARG : YEPTRIS_ERROR_MEMORY);
339
+ }
340
+ }
341
+ if (rc == YEPTRIS_OK && (e->op == YEPTRIS_BUILD_SEQ || e->op == YEPTRIS_BUILD_MAP)) {
342
+ if ((size_t)depth >= (size_t)YEP_DOM_MAX_DEPTH) {
343
+ rc = YEPTRIS_ERROR_DEPTH;
344
+ break;
345
+ }
346
+ st[depth].id = id;
347
+ st[depth].is_map = (e->op == YEPTRIS_BUILD_MAP);
348
+ st[depth].key_pending = 0;
349
+ depth++;
350
+ }
351
+ }
352
+ if (rc == YEPTRIS_OK) {
353
+ if (depth > 1 || (depth == 1)) {
354
+ rc = YEPTRIS_ERROR_PARSE; /* an unclosed container */
355
+ } else if (root == UINT32_MAX) {
356
+ rc = YEPTRIS_ERROR_PARSE; /* no root */
357
+ } else if (pending_key != UINT32_MAX) {
358
+ rc = YEPTRIS_ERROR_PARSE; /* a key without its value */
359
+ } else {
360
+ int arc = yep_mut_add_root(doc->dom, root);
361
+ if (arc == 0) {
362
+ rc = YEPTRIS_OK;
363
+ } else if (arc == -4) {
364
+ rc = YEPTRIS_ERROR_PARSE;
365
+ } else if (arc == -3) {
366
+ rc = YEPTRIS_ERROR_DEPTH;
367
+ } else if (arc == -1) {
368
+ rc = YEPTRIS_ERROR_MEMORY;
369
+ } else {
370
+ rc = YEPTRIS_ERROR_ARG;
371
+ }
372
+ }
373
+ }
374
+ yep_free(doc->dom->sys, st);
375
+ return rc;
376
+ }
@@ -0,0 +1,25 @@
1
+ /* cbor.h — the CBOR (RFC 8949) codec's internal interface
2
+ * (TODO.cbor/01). The public surface is <yeptris/cbor.h>. */
3
+ #ifndef YEP_CBOR_H
4
+ #define YEP_CBOR_H
5
+
6
+ #include <stdint.h>
7
+
8
+ #include "../dom/dom.h"
9
+
10
+ #ifdef __cplusplus
11
+ extern "C" {
12
+ #endif
13
+
14
+ /* one data item: bytes -> the shared DOM (the plan's item 01) */
15
+ /* One data item. consumed (may be NULL): when given, returns the
16
+ * item's byte extent and TRAILING BYTES ARE NOT an error (the
17
+ * sequence loop steps on them); NULL keeps the one-item contract. */
18
+ int yep_cbor_decode_dom(yep_dom* d, const unsigned char* p, size_t len, int strict,
19
+ size_t* consumed);
20
+
21
+ #ifdef __cplusplus
22
+ }
23
+ #endif
24
+
25
+ #endif /* YEP_CBOR_H */