yeptris 0.6.64.0-riscv64-linux-gnu

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 (164) hide show
  1. checksums.yaml +7 -0
  2. data/README.adoc +150 -0
  3. data/ext/build_windows_native.rb +60 -0
  4. data/ext/libyeptris/extconf.rb +57 -0
  5. data/ext/yeptris_native/cbor_ruby.c +198 -0
  6. data/ext/yeptris_native/extconf.rb +99 -0
  7. data/ext/yeptris_native/json_ruby.c +414 -0
  8. data/ext/yeptris_native/version.h +29 -0
  9. data/ext/yeptris_native/yeptris_native.c +507 -0
  10. data/lib/yeptris/3.3/native.so +0 -0
  11. data/lib/yeptris/cbor.rb +169 -0
  12. data/lib/yeptris/document.rb +319 -0
  13. data/lib/yeptris/ffi.rb +572 -0
  14. data/lib/yeptris/json/descriptor.rb +266 -0
  15. data/lib/yeptris/json.rb +502 -0
  16. data/lib/yeptris/materializer.rb +389 -0
  17. data/lib/yeptris/node.rb +482 -0
  18. data/lib/yeptris/psych/class_loader.rb +24 -0
  19. data/lib/yeptris/psych/coder_shim.rb +55 -0
  20. data/lib/yeptris/psych/drop_in.rb +63 -0
  21. data/lib/yeptris/psych/encodable.rb +14 -0
  22. data/lib/yeptris/psych/handler.rb +95 -0
  23. data/lib/yeptris/psych/parser.rb +114 -0
  24. data/lib/yeptris/psych/scalar_scanner.rb +149 -0
  25. data/lib/yeptris/psych/tree_builder.rb +119 -0
  26. data/lib/yeptris/psych/visitors.rb +670 -0
  27. data/lib/yeptris/psych.rb +796 -0
  28. data/lib/yeptris/schema.rb +253 -0
  29. data/lib/yeptris/validation.rb +320 -0
  30. data/lib/yeptris/valueml.rb +477 -0
  31. data/lib/yeptris/yaml/descriptor.rb +56 -0
  32. data/lib/yeptris/yaml.rb +668 -0
  33. data/lib/yeptris.rb +130 -0
  34. data/libyeptris.so +0 -0
  35. data/vendor/libyeptris/CMakeLists.txt +280 -0
  36. data/vendor/libyeptris/cmake/yeptris-config.cmake.in +5 -0
  37. data/vendor/libyeptris/cmake/yeptris.pc.in +11 -0
  38. data/vendor/libyeptris/src/CMakeLists.txt +183 -0
  39. data/vendor/libyeptris/src/include/yeptris/api.h +32 -0
  40. data/vendor/libyeptris/src/include/yeptris/cbor.h +174 -0
  41. data/vendor/libyeptris/src/include/yeptris/dom.h +196 -0
  42. data/vendor/libyeptris/src/include/yeptris/emit.h +128 -0
  43. data/vendor/libyeptris/src/include/yeptris/error.h +42 -0
  44. data/vendor/libyeptris/src/include/yeptris/events.h +171 -0
  45. data/vendor/libyeptris/src/include/yeptris/json.h +57 -0
  46. data/vendor/libyeptris/src/include/yeptris/json.hpp +258 -0
  47. data/vendor/libyeptris/src/include/yeptris/jsonc_compat.h +115 -0
  48. data/vendor/libyeptris/src/include/yeptris/marshal.h +75 -0
  49. data/vendor/libyeptris/src/include/yeptris/parse.h +121 -0
  50. data/vendor/libyeptris/src/include/yeptris/plan.h +100 -0
  51. data/vendor/libyeptris/src/include/yeptris/resolve.h +81 -0
  52. data/vendor/libyeptris/src/include/yeptris/schema.h +121 -0
  53. data/vendor/libyeptris/src/include/yeptris/tape.h +128 -0
  54. data/vendor/libyeptris/src/include/yeptris/types.h +38 -0
  55. data/vendor/libyeptris/src/include/yeptris/validate.h +401 -0
  56. data/vendor/libyeptris/src/include/yeptris/values.h +108 -0
  57. data/vendor/libyeptris/src/include/yeptris/version.h.in +29 -0
  58. data/vendor/libyeptris/src/include/yeptris/visit.h +77 -0
  59. data/vendor/libyeptris/src/include/yeptris/yajl_compat.h +135 -0
  60. data/vendor/libyeptris/src/include/yeptris.h +24 -0
  61. data/vendor/libyeptris/src/yeptris/build.c +393 -0
  62. data/vendor/libyeptris/src/yeptris/cbor/cbor.h +35 -0
  63. data/vendor/libyeptris/src/yeptris/cbor/decode.c +1054 -0
  64. data/vendor/libyeptris/src/yeptris/cbor/encode.c +836 -0
  65. data/vendor/libyeptris/src/yeptris/cbor/encode_priv.h +32 -0
  66. data/vendor/libyeptris/src/yeptris/cbor/from_marshal.c +982 -0
  67. data/vendor/libyeptris/src/yeptris/cbor/sink.h +36 -0
  68. data/vendor/libyeptris/src/yeptris/common/chartype.c +41 -0
  69. data/vendor/libyeptris/src/yeptris/common/chartype.h +77 -0
  70. data/vendor/libyeptris/src/yeptris/common/cpu.c +81 -0
  71. data/vendor/libyeptris/src/yeptris/common/cpu.h +40 -0
  72. data/vendor/libyeptris/src/yeptris/common/error.c +65 -0
  73. data/vendor/libyeptris/src/yeptris/common/error.h +81 -0
  74. data/vendor/libyeptris/src/yeptris/common/mutex.h +45 -0
  75. data/vendor/libyeptris/src/yeptris/common/nametab.c +275 -0
  76. data/vendor/libyeptris/src/yeptris/common/nametab.h +68 -0
  77. data/vendor/libyeptris/src/yeptris/common/port.h +74 -0
  78. data/vendor/libyeptris/src/yeptris/common/simd_text.c +49 -0
  79. data/vendor/libyeptris/src/yeptris/common/simd_text.h +342 -0
  80. data/vendor/libyeptris/src/yeptris/common/simd_text_avx2.c +672 -0
  81. data/vendor/libyeptris/src/yeptris/common/simd_text_neon.c +793 -0
  82. data/vendor/libyeptris/src/yeptris/common/simd_text_scalar.c +324 -0
  83. data/vendor/libyeptris/src/yeptris/common/string_view.c +34 -0
  84. data/vendor/libyeptris/src/yeptris/common/string_view.h +93 -0
  85. data/vendor/libyeptris/src/yeptris/doc.h +86 -0
  86. data/vendor/libyeptris/src/yeptris/dom/dom.c +1312 -0
  87. data/vendor/libyeptris/src/yeptris/dom/dom.h +332 -0
  88. data/vendor/libyeptris/src/yeptris/dom/hpool.c +107 -0
  89. data/vendor/libyeptris/src/yeptris/dom/mapindex.c +173 -0
  90. data/vendor/libyeptris/src/yeptris/dom/mapindex.h +61 -0
  91. data/vendor/libyeptris/src/yeptris/dom/mutate.c +431 -0
  92. data/vendor/libyeptris/src/yeptris/dom/ytape.c +2323 -0
  93. data/vendor/libyeptris/src/yeptris/dom/ytape.h +96 -0
  94. data/vendor/libyeptris/src/yeptris/emit/emit.c +670 -0
  95. data/vendor/libyeptris/src/yeptris/emit/float/api.h +43 -0
  96. data/vendor/libyeptris/src/yeptris/emit/float/dragon.c +405 -0
  97. data/vendor/libyeptris/src/yeptris/emit/float/floatint.h +231 -0
  98. data/vendor/libyeptris/src/yeptris/emit/float/fpconv.c +428 -0
  99. data/vendor/libyeptris/src/yeptris/emit/float/print.c +396 -0
  100. data/vendor/libyeptris/src/yeptris/emit/style.c +21 -0
  101. data/vendor/libyeptris/src/yeptris/emit/style.h +32 -0
  102. data/vendor/libyeptris/src/yeptris/emit/writer.c +1951 -0
  103. data/vendor/libyeptris/src/yeptris/emit/writer.h +111 -0
  104. data/vendor/libyeptris/src/yeptris/encoding/bom.c +31 -0
  105. data/vendor/libyeptris/src/yeptris/encoding/encoding.h +63 -0
  106. data/vendor/libyeptris/src/yeptris/encoding/transcode.c +157 -0
  107. data/vendor/libyeptris/src/yeptris/encoding/utf8_validate.c +178 -0
  108. data/vendor/libyeptris/src/yeptris/events/capture.c +166 -0
  109. data/vendor/libyeptris/src/yeptris/events/capture.h +39 -0
  110. data/vendor/libyeptris/src/yeptris/events/iterparse.c +298 -0
  111. data/vendor/libyeptris/src/yeptris/events/pull.c +117 -0
  112. data/vendor/libyeptris/src/yeptris/events/push.c +151 -0
  113. data/vendor/libyeptris/src/yeptris/events/recorder.c +144 -0
  114. data/vendor/libyeptris/src/yeptris/events/values.c +630 -0
  115. data/vendor/libyeptris/src/yeptris/events/values_priv.h +53 -0
  116. data/vendor/libyeptris/src/yeptris/events/yaml_compat.c +86 -0
  117. data/vendor/libyeptris/src/yeptris/events/yaml_compat.h +90 -0
  118. data/vendor/libyeptris/src/yeptris/jsonapi/jsonc_compat.c +687 -0
  119. data/vendor/libyeptris/src/yeptris/jsonapi/yajl_compat.c +728 -0
  120. data/vendor/libyeptris/src/yeptris/marshal/to_json.c +650 -0
  121. data/vendor/libyeptris/src/yeptris/marshal.c +988 -0
  122. data/vendor/libyeptris/src/yeptris/memory/allocator.c +20 -0
  123. data/vendor/libyeptris/src/yeptris/memory/allocator.h +43 -0
  124. data/vendor/libyeptris/src/yeptris/memory/arena.c +150 -0
  125. data/vendor/libyeptris/src/yeptris/memory/arena.h +52 -0
  126. data/vendor/libyeptris/src/yeptris/memory/pool.c +133 -0
  127. data/vendor/libyeptris/src/yeptris/memory/pool.h +36 -0
  128. data/vendor/libyeptris/src/yeptris/parse/engine.c +6528 -0
  129. data/vendor/libyeptris/src/yeptris/parse/engine.h +96 -0
  130. data/vendor/libyeptris/src/yeptris/parse/events.h +137 -0
  131. data/vendor/libyeptris/src/yeptris/parse/numbers.c +374 -0
  132. data/vendor/libyeptris/src/yeptris/parse/numbers.h +33 -0
  133. data/vendor/libyeptris/src/yeptris/parse/scalars.c +435 -0
  134. data/vendor/libyeptris/src/yeptris/parse/scalars.h +87 -0
  135. data/vendor/libyeptris/src/yeptris/parse/stream_iter.c +358 -0
  136. data/vendor/libyeptris/src/yeptris/parse.c +1074 -0
  137. data/vendor/libyeptris/src/yeptris/plan.c +824 -0
  138. data/vendor/libyeptris/src/yeptris/resolve/compat11.c +339 -0
  139. data/vendor/libyeptris/src/yeptris/resolve/core12.c +153 -0
  140. data/vendor/libyeptris/src/yeptris/resolve/full12.c +201 -0
  141. data/vendor/libyeptris/src/yeptris/resolve/json12.c +109 -0
  142. data/vendor/libyeptris/src/yeptris/resolve/resolver.h +103 -0
  143. data/vendor/libyeptris/src/yeptris/resolve/tags.c +250 -0
  144. data/vendor/libyeptris/src/yeptris/scan/json.c +839 -0
  145. data/vendor/libyeptris/src/yeptris/scan/json.h +116 -0
  146. data/vendor/libyeptris/src/yeptris/scan/scan.c +862 -0
  147. data/vendor/libyeptris/src/yeptris/scan/scan.h +177 -0
  148. data/vendor/libyeptris/src/yeptris/schema.c +309 -0
  149. data/vendor/libyeptris/src/yeptris/tape.c +2375 -0
  150. data/vendor/libyeptris/src/yeptris/tape_in.h +39 -0
  151. data/vendor/libyeptris/src/yeptris/validate/compile.c +306 -0
  152. data/vendor/libyeptris/src/yeptris/validate/internal.h +347 -0
  153. data/vendor/libyeptris/src/yeptris/validate/jsonschema.c +1922 -0
  154. data/vendor/libyeptris/src/yeptris/validate/output.c +246 -0
  155. data/vendor/libyeptris/src/yeptris/validate/regexp.c +1600 -0
  156. data/vendor/libyeptris/src/yeptris/validate/registry.c +118 -0
  157. data/vendor/libyeptris/src/yeptris/validate/resources.c +601 -0
  158. data/vendor/libyeptris/src/yeptris/validate/stream.c +1155 -0
  159. data/vendor/libyeptris/src/yeptris/validate/validate.c +1043 -0
  160. data/vendor/libyeptris/src/yeptris/version.c +7 -0
  161. data/vendor/libyeptris/src/yeptris/visit/dom_visit.c +115 -0
  162. data/vendor/libyeptris/src/yeptris/visit/json_visit.c +293 -0
  163. data/vendor/libyeptris/src/yeptris/visit/yaml_visit.c +127 -0
  164. metadata +221 -0
@@ -0,0 +1,135 @@
1
+ /* yajl_compat.h — the yajl generator migration layer (TODO.impl/21).
2
+ *
3
+ * REAL yajl_gen symbol names over the yeptris core: users link
4
+ * -lyeptris-yajl instead of -lyajl and change nothing else. The
5
+ * generator validates call order (yajl's own state machine) and
6
+ * builds a Yeptris document; get_buf serializes JSON (beautify
7
+ * selects the pretty writer, default compact).
8
+ *
9
+ * v2 scope: the generator (yajl_gen_*) and the SAX parser
10
+ * (yajl_alloc/yajl_parse/...). The parser accumulates yajl_parse
11
+ * feeds and delivers all callbacks at yajl_complete_parse (the core
12
+ * parses whole documents; timing is batched, order and content are
13
+ * yajl's). Strict RFC 8259 always; yajl_allow_comments masks
14
+ * JavaScript comments (block star-slash, line double-slash) outside
15
+ * strings before the strict parse — offsets preserved, yajl's exact
16
+ * semantics. Unsupported options (trailing garbage / multiple
17
+ * values / partial values) are rejected at yajl_config time: zero,
18
+ * per yajl's own error contract.
19
+ */
20
+ #ifndef YEPTRIS_YAJL_COMPAT_H
21
+ #define YEPTRIS_YAJL_COMPAT_H
22
+
23
+ #include <stddef.h>
24
+
25
+ #ifdef __cplusplus
26
+ extern "C" {
27
+ #endif
28
+
29
+ typedef enum {
30
+ yajl_gen_status_ok = 0,
31
+ yajl_gen_keys_must_be_strings, /* 1 */
32
+ yajl_max_depth_exceeded, /* unused: depth-guarded builder */
33
+ yajl_gen_in_error_state = 3,
34
+ yajl_gen_generation_complete, /* 4: gen after get_buf without clear */
35
+ yajl_gen_invalid_string = 5 /* NULL bytes with len 0 handled; reserved */
36
+ } yajl_gen_status;
37
+
38
+ typedef enum {
39
+ yajl_gen_beautify = 1, /* int: pretty output */
40
+ yajl_gen_indent_string = 2, /* const char*: reserved (fixed 2-space) */
41
+ yajl_gen_validate_utf8 = 3 /* int: always on (the front-end validates) */
42
+ } yajl_gen_option;
43
+
44
+ typedef struct yajl_gen_t* yajl_gen;
45
+ typedef struct yajl_alloc_funcs_t yajl_alloc_funcs;
46
+
47
+ /* NULL alloc (the yajl default) uses the system allocator. */
48
+ yajl_gen yajl_gen_alloc(const yajl_alloc_funcs* afs);
49
+ void yajl_gen_free(yajl_gen g);
50
+ void yajl_gen_reset(yajl_gen g, const char* sep_ignored);
51
+
52
+ /* var-args: (yajl_gen_beautify, int). Returns 1 on success. */
53
+ int yajl_gen_config(yajl_gen g, yajl_gen_option opt, ...);
54
+
55
+ yajl_gen_status yajl_gen_map_open(yajl_gen g);
56
+ yajl_gen_status yajl_gen_map_close(yajl_gen g);
57
+ yajl_gen_status yajl_gen_array_open(yajl_gen g);
58
+ yajl_gen_status yajl_gen_array_close(yajl_gen g);
59
+
60
+ /* In a map, the first call per entry is the KEY: it must be a
61
+ * string (yajl accepts raw bytes; keys serialize JSON-quoted). */
62
+ yajl_gen_status yajl_gen_string(yajl_gen g, const unsigned char* str, size_t len);
63
+ yajl_gen_status yajl_gen_integer(yajl_gen g, long long n);
64
+ yajl_gen_status yajl_gen_double(yajl_gen g, double d);
65
+ yajl_gen_status yajl_gen_number(yajl_gen g, const char* s, size_t len);
66
+ yajl_gen_status yajl_gen_null(yajl_gen g);
67
+ yajl_gen_status yajl_gen_bool(yajl_gen g, int b);
68
+
69
+ /* The serialized document (owned by the generator; valid until the
70
+ * next generating call or reset). Empty until the ROOT closes. */
71
+ const unsigned char* yajl_gen_get_buf(yajl_gen g, size_t* len);
72
+ void yajl_gen_clear(yajl_gen g);
73
+
74
+ /* ---- SAX parser ------------------------------------------------------- */
75
+
76
+ typedef enum { yajl_status_ok = 0, yajl_status_client_canceled, yajl_status_error } yajl_status;
77
+
78
+ const char* yajl_status_to_string(yajl_status code);
79
+
80
+ /* Zero return from a callback cancels the parse
81
+ * (yajl_status_client_canceled). When yajl_number is set it carries
82
+ * EVERY number in string form; yajl_integer/yajl_double are then
83
+ * ignored (yajl's own precedence). */
84
+ typedef struct {
85
+ int (*yajl_null)(void* ctx);
86
+ int (*yajl_boolean)(void* ctx, int boolVal);
87
+ int (*yajl_integer)(void* ctx, long long integerVal);
88
+ int (*yajl_double)(void* ctx, double doubleVal);
89
+ int (*yajl_number)(void* ctx, const char* numberVal, size_t numberLen);
90
+ int (*yajl_string)(void* ctx, const unsigned char* stringVal, size_t stringLen);
91
+ int (*yajl_start_map)(void* ctx);
92
+ int (*yajl_map_key)(void* ctx, const unsigned char* key, size_t stringLen);
93
+ int (*yajl_end_map)(void* ctx);
94
+ int (*yajl_start_array)(void* ctx);
95
+ int (*yajl_end_array)(void* ctx);
96
+ } yajl_callbacks;
97
+
98
+ typedef enum {
99
+ yajl_allow_comments = 0x01, /* JS comments masked, offsets kept */
100
+ yajl_dont_validate_strings = 0x02, /* accepted no-op: always on */
101
+ yajl_allow_trailing_garbage = 0x04,
102
+ yajl_allow_multiple_values = 0x08,
103
+ yajl_allow_partial_values = 0x10
104
+ } yajl_option;
105
+
106
+ typedef struct yajl_handle_t* yajl_handle;
107
+
108
+ /* callbacks may be NULL (pure validation). afs accepted, ignored. */
109
+ yajl_handle yajl_alloc(const yajl_callbacks* callbacks, yajl_alloc_funcs* afs, void* ctx);
110
+ void yajl_free(yajl_handle handle);
111
+
112
+ /* var-args int option: 1 on, 0 off. Returns 0 on unknown/unsupported
113
+ * options (trailing garbage / multiple values / partial values). */
114
+ int yajl_config(yajl_handle h, yajl_option opt, ...);
115
+
116
+ /* Accumulates feeds; callbacks fire at complete_parse. After an
117
+ * error or cancel the handle stays in that state. */
118
+ yajl_status yajl_parse(yajl_handle hand, const unsigned char* jsonText, size_t jsonTextLength);
119
+ yajl_status yajl_complete_parse(yajl_handle hand);
120
+
121
+ /* Malloc'd message (free with yajl_free_error); NULL when no error.
122
+ * verbose adds the offending line and a caret. */
123
+ unsigned char* yajl_get_error(yajl_handle hand, int verbose, const unsigned char* jsonText,
124
+ size_t jsonTextLength);
125
+ void yajl_free_error(yajl_handle hand, unsigned char* str);
126
+
127
+ /* Bytes consumed: the whole input once complete; on error, the
128
+ * offset of the violation. */
129
+ size_t yajl_get_bytes_consumed(yajl_handle hand);
130
+
131
+ #ifdef __cplusplus
132
+ }
133
+ #endif
134
+
135
+ #endif /* YEPTRIS_YAJL_COMPAT_H */
@@ -0,0 +1,24 @@
1
+ /* yeptris.h — umbrella header for libyeptris.
2
+ *
3
+ * Ultra-fast YAML 1.2 parser, emitter and streamer in C; the YAML
4
+ * counterpart of libleptris. Subsystem headers grow with their items
5
+ * (TODO.impl/01-20); this file only includes the public surface.
6
+ */
7
+ #ifndef YEPTRIS_H
8
+ #define YEPTRIS_H
9
+
10
+ #include <yeptris/api.h>
11
+ #include <yeptris/dom.h>
12
+ #include <yeptris/emit.h>
13
+ #include <yeptris/error.h>
14
+ #ifdef YEPTRIS_WITH_CBOR
15
+ #include <yeptris/cbor.h>
16
+ #endif
17
+ #include <yeptris/events.h>
18
+ #include <yeptris/parse.h>
19
+ #include <yeptris/resolve.h>
20
+ #include <yeptris/types.h>
21
+ #include <yeptris/validate.h>
22
+ #include <yeptris/version.h>
23
+
24
+ #endif /* YEPTRIS_H */
@@ -0,0 +1,393 @@
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
+ #include "resolve/resolver.h"
15
+
16
+ static yeptris_document* doc_of(YeptrisDocument handle) {
17
+ return (yeptris_document*)handle;
18
+ }
19
+
20
+ static yeptris_node* node_of(YeptrisNode handle) {
21
+ return (yeptris_node*)handle;
22
+ }
23
+
24
+ YEPTRIS_API YeptrisDocument yeptris_document_new(void) {
25
+ const yep_allocator* sys = yep_system_allocator();
26
+ yep_dom* dom = yep_dom_create(sys);
27
+ if (dom == NULL) {
28
+ return NULL;
29
+ }
30
+ yeptris_document* doc = yep_alloc(sys, sizeof(yeptris_document));
31
+ if (doc == NULL) {
32
+ yep_dom_destroy(dom);
33
+ return NULL;
34
+ }
35
+ yep_mutex_init(&doc->lazy_mu);
36
+ memset(doc, 0, sizeof(*doc));
37
+ doc->dom = dom;
38
+ doc->sys = sys;
39
+ return (YeptrisDocument)doc;
40
+ }
41
+
42
+ /* An empty document whose plain scalars type through the given
43
+ * schema's resolver (yeptris_document_new rides the core-12 default).
44
+ * The CBOR/dump faces create compat-11 documents so a host String the
45
+ * tree builder kept plain ("1e0" — Psych's dot-required float law)
46
+ * stays a text string instead of resolving as a float (#293's shape). */
47
+ YEPTRIS_API YeptrisDocument yeptris_document_new_schema(YeptrisSchema schema) {
48
+ YeptrisDocument doc = yeptris_document_new();
49
+ if (doc != NULL) {
50
+ yeptris_document* d = (yeptris_document*)doc;
51
+ d->dom->resolver =
52
+ schema == YEPTRIS_SCHEMA_11_COMPAT ? yep_resolver_compat11() : yep_resolver_core12();
53
+ }
54
+ return doc;
55
+ }
56
+
57
+ YEPTRIS_API int yeptris_document_set_root(YeptrisDocument handle, YeptrisNode root) {
58
+ yeptris_document* doc = doc_of(handle);
59
+ yeptris_node* n = node_of(root);
60
+ if (doc == NULL || n == NULL || n->doc != doc) {
61
+ return YEPTRIS_ERROR_PARSE;
62
+ }
63
+ int rc = yep_mut_add_root(doc->dom, n->id);
64
+ return rc == 0 ? YEPTRIS_OK
65
+ : (rc == -1 ? YEPTRIS_ERROR_MEMORY
66
+ : (rc == -3 ? YEPTRIS_ERROR_DEPTH : YEPTRIS_ERROR_ARG));
67
+ }
68
+
69
+ YEPTRIS_API YeptrisNode yeptris_node_new_mapping(YeptrisDocument handle) {
70
+ yeptris_document* doc = doc_of(handle);
71
+ if (doc == NULL) {
72
+ return NULL;
73
+ }
74
+ uint32_t id = yep_mut_map(doc->dom, 0);
75
+ return id == UINT32_MAX ? NULL : (YeptrisNode)yep_handle_new(doc, id);
76
+ }
77
+
78
+ YEPTRIS_API YeptrisNode yeptris_node_new_sequence(YeptrisDocument handle) {
79
+ yeptris_document* doc = doc_of(handle);
80
+ if (doc == NULL) {
81
+ return NULL;
82
+ }
83
+ uint32_t id = yep_mut_seq(doc->dom, 0);
84
+ return id == UINT32_MAX ? NULL : (YeptrisNode)yep_handle_new(doc, id);
85
+ }
86
+
87
+ /* Memory: the value is copied into the document (nothing is borrowed
88
+ * from the caller). Plain style types the copy through the resolver,
89
+ * quoted styles force string — identical to parse-time typing. */
90
+ YEPTRIS_API YeptrisNode yeptris_node_new_scalar(YeptrisDocument handle, const char* value,
91
+ size_t len, YeptrisScalarStyle style) {
92
+ yeptris_document* doc = doc_of(handle);
93
+ if (doc == NULL || (value == NULL && len > 0) || style < YEPTRIS_STYLE_PLAIN ||
94
+ style > YEPTRIS_STYLE_FOLDED) {
95
+ return NULL;
96
+ }
97
+ uint32_t id = yep_mut_scalar(doc->dom, value, len, (uint8_t)style);
98
+ return id == UINT32_MAX ? NULL : (YeptrisNode)yep_handle_new(doc, id);
99
+ }
100
+
101
+ static int mut_status(int rc) {
102
+ switch (rc) {
103
+ case 0:
104
+ case 1: /* map_set replaced — success for the caller */
105
+ return YEPTRIS_OK;
106
+ case -1:
107
+ return YEPTRIS_ERROR_MEMORY;
108
+ case -3:
109
+ return YEPTRIS_ERROR_DEPTH;
110
+ default: /* -2 duplicate key, -4 double-attach */
111
+ return YEPTRIS_ERROR_PARSE;
112
+ }
113
+ }
114
+
115
+ static int same_doc(YeptrisNode parent, YeptrisNode child) {
116
+ yeptris_node* p = node_of(parent);
117
+ yeptris_node* c = node_of(child);
118
+ return p != NULL && c != NULL && p->doc == c->doc;
119
+ }
120
+
121
+ YEPTRIS_API int yeptris_node_map_add(YeptrisNode handle, const char* key, size_t key_len,
122
+ YeptrisNode value) {
123
+ yeptris_node* m = node_of(handle);
124
+ if (m == NULL || key == NULL || !same_doc(handle, value)) {
125
+ return YEPTRIS_ERROR_ARG;
126
+ }
127
+ return mut_status(yep_mut_map_add(m->doc->dom, m->id, key, key_len, node_of(value)->id));
128
+ }
129
+
130
+ /* Replace-or-add (json-c semantics): an existing key keeps its
131
+ * position and swaps the value; a new key appends. */
132
+ YEPTRIS_API int yeptris_node_map_set(YeptrisNode handle, const char* key, size_t key_len,
133
+ YeptrisNode value) {
134
+ yeptris_node* m = node_of(handle);
135
+ if (m == NULL || key == NULL || !same_doc(handle, value)) {
136
+ return YEPTRIS_ERROR_ARG;
137
+ }
138
+ return mut_status(yep_mut_map_set(m->doc->dom, m->id, key, key_len, node_of(value)->id));
139
+ }
140
+
141
+ YEPTRIS_API int yeptris_node_seq_add(YeptrisNode handle, YeptrisNode value) {
142
+ yeptris_node* s = node_of(handle);
143
+ if (s == NULL || !same_doc(handle, value)) {
144
+ return YEPTRIS_ERROR_ARG;
145
+ }
146
+ return mut_status(yep_mut_seq_add(s->doc->dom, s->id, node_of(value)->id));
147
+ }
148
+
149
+ YEPTRIS_API int yeptris_node_seq_set(YeptrisNode handle, size_t index, YeptrisNode value) {
150
+ yeptris_node* s = node_of(handle);
151
+ if (s == NULL || !same_doc(handle, value)) {
152
+ return YEPTRIS_ERROR_ARG;
153
+ }
154
+ return mut_status(yep_mut_seq_set(s->doc->dom, s->id, (uint32_t)index, node_of(value)->id));
155
+ }
156
+
157
+ YEPTRIS_API int yeptris_node_seq_del(YeptrisNode handle, size_t index) {
158
+ yeptris_node* s = node_of(handle);
159
+ if (s == NULL) {
160
+ return YEPTRIS_ERROR_ARG;
161
+ }
162
+ return yep_mut_seq_del(s->doc->dom, s->id, (uint32_t)index) == 0 ? YEPTRIS_OK
163
+ : YEPTRIS_ERROR_PARSE;
164
+ }
165
+
166
+ /* The removed subtree stays document-owned (arena lifetime); its
167
+ * handle remains valid but unreachable from the root. */
168
+ YEPTRIS_API int yeptris_node_set_anchor(YeptrisNode handle, const char* name, size_t len) {
169
+ yeptris_node* n = node_of(handle);
170
+ if (n == NULL || name == NULL) {
171
+ return YEPTRIS_ERROR_ARG;
172
+ }
173
+ return yep_mut_set_anchor(n->doc->dom, n->id, name, len) == 0 ? YEPTRIS_OK : YEPTRIS_ERROR_ARG;
174
+ }
175
+
176
+ YEPTRIS_API int yeptris_node_set_tag(YeptrisNode handle, const char* tag, size_t len) {
177
+ yeptris_node* n = node_of(handle);
178
+ if (n == NULL || tag == NULL) {
179
+ return YEPTRIS_ERROR_ARG;
180
+ }
181
+ return yep_mut_set_tag(n->doc->dom, n->id, tag, len) == 0 ? YEPTRIS_OK : YEPTRIS_ERROR_ARG;
182
+ }
183
+
184
+ YEPTRIS_API YeptrisNode yeptris_node_new_alias(YeptrisDocument handle, YeptrisNode target,
185
+ const char* name, size_t len) {
186
+ yeptris_document* doc = doc_of(handle);
187
+ yeptris_node* t = node_of(target);
188
+ if (doc == NULL || t == NULL || t->doc != doc || name == NULL) {
189
+ return NULL;
190
+ }
191
+ uint32_t id = yep_mut_new_alias(doc->dom, t->id, name, len);
192
+ return id == UINT32_MAX ? NULL : (YeptrisNode)yep_handle_new(doc, id);
193
+ }
194
+
195
+ YEPTRIS_API int yeptris_node_map_add_node(YeptrisNode handle, YeptrisNode key, YeptrisNode value) {
196
+ yeptris_node* m = node_of(handle);
197
+ if (m == NULL || !same_doc(handle, key) || !same_doc(handle, value)) {
198
+ return YEPTRIS_ERROR_ARG;
199
+ }
200
+ return mut_status(
201
+ yep_mut_map_add_node(m->doc->dom, m->id, node_of(key)->id, node_of(value)->id));
202
+ }
203
+
204
+ YEPTRIS_API int yeptris_node_map_del(YeptrisNode handle, const char* key, size_t key_len) {
205
+ yeptris_node* m = node_of(handle);
206
+ if (m == NULL || key == NULL) {
207
+ return YEPTRIS_ERROR_ARG;
208
+ }
209
+ return yep_mut_map_del(m->doc->dom, m->id, key, key_len) == 0 ? YEPTRIS_OK
210
+ : YEPTRIS_ERROR_PARSE;
211
+ }
212
+
213
+ /* ---- bulk build --------------------------------------------------------
214
+ *
215
+ * One call, one tree: entries walk in document order (the same shape
216
+ * as the event stream), pairing and linking ride the mutation
217
+ * primitives unchanged — dup checks, depth caps, and per-link depth
218
+ * fixups all come along for free (DRY with the public builder). */
219
+ YEPTRIS_API YeptrisStatus yeptris_document_build(YeptrisDocument handle,
220
+ const YeptrisBuildEntry* entries, size_t count,
221
+ const char* blob, size_t blob_len) {
222
+ yeptris_document* doc = doc_of(handle);
223
+ if (doc == NULL || (entries == NULL && count != 0) || (blob == NULL && blob_len != 0)) {
224
+ return YEPTRIS_ERROR_ARG;
225
+ }
226
+ struct frame {
227
+ uint32_t id;
228
+ uint8_t is_map;
229
+ uint8_t key_pending;
230
+ };
231
+ if (count > (SIZE_MAX / 2) / sizeof(struct frame)) {
232
+ return YEPTRIS_ERROR_ARG;
233
+ }
234
+ struct frame* st = yep_alloc(doc->dom->sys, (count + 1) * sizeof(*st));
235
+ if (st == NULL) {
236
+ return YEPTRIS_ERROR_MEMORY;
237
+ }
238
+ int depth = 0;
239
+ uint32_t root = UINT32_MAX;
240
+ uint32_t root_closed = 0;
241
+ uint32_t root_tagged = 0; /* one trailing TAG on the closed root (#168) */
242
+ uint32_t pending_key = UINT32_MAX; /* map frame's buffered key */
243
+ uint32_t last_id = UINT32_MAX; /* TAG applies here (#300) */
244
+ YeptrisStatus rc = YEPTRIS_OK;
245
+ for (size_t i = 0; i < count && rc == YEPTRIS_OK; i++) {
246
+ const YeptrisBuildEntry* e = &entries[i];
247
+ /* A closed SCALAR root admits exactly one trailing TAG —
248
+ * psych's binary root is `--- !binary |-` (#168); everything
249
+ * after (more ops, a second tag) still rejects */
250
+ if (root_closed && !(e->op == YEPTRIS_BUILD_TAG && !root_tagged && last_id == root)) {
251
+ rc = YEPTRIS_ERROR_PARSE; /* the document ended; more entries */
252
+ break;
253
+ }
254
+ if (e->off > blob_len || e->len > blob_len - e->off) {
255
+ rc = YEPTRIS_ERROR_PARSE; /* slice out of range */
256
+ break;
257
+ }
258
+ uint32_t id = UINT32_MAX; /* set by every arm that reaches the place; MSVC wants the init */
259
+ switch (e->op) {
260
+ case YEPTRIS_BUILD_SCALAR: {
261
+ id = yep_mut_scalar(doc->dom, blob + e->off, e->len, e->style);
262
+ if (id == UINT32_MAX) {
263
+ rc = YEPTRIS_ERROR_MEMORY;
264
+ break;
265
+ }
266
+ break;
267
+ }
268
+ case YEPTRIS_BUILD_SEQ:
269
+ id = yep_mut_seq(doc->dom, 0);
270
+ if (id == UINT32_MAX) {
271
+ rc = YEPTRIS_ERROR_MEMORY;
272
+ break;
273
+ }
274
+ break;
275
+ case YEPTRIS_BUILD_MAP:
276
+ id = yep_mut_map(doc->dom, 0);
277
+ if (id == UINT32_MAX) {
278
+ rc = YEPTRIS_ERROR_MEMORY;
279
+ break;
280
+ }
281
+ break;
282
+ case YEPTRIS_BUILD_END:
283
+ if (depth == 0) {
284
+ rc = YEPTRIS_ERROR_PARSE; /* END with nothing open */
285
+ break;
286
+ }
287
+ depth--;
288
+ if (depth == 0) {
289
+ root_closed = 1; /* the root just completed */
290
+ }
291
+ if (st[depth].is_map && st[depth].key_pending) {
292
+ st[depth].key_pending = 0; /* a closed container was the value */
293
+ }
294
+ continue;
295
+ case YEPTRIS_BUILD_TAG:
296
+ /* #300: apply an explicit tag to the last-placed node —
297
+ * the bulk ABI otherwise cannot express tags. Placed
298
+ * immediately after the entry it tags. */
299
+ if (last_id == UINT32_MAX) {
300
+ rc = YEPTRIS_ERROR_PARSE; /* TAG with nothing placed */
301
+ break;
302
+ }
303
+ if (yep_mut_set_tag(doc->dom, last_id, blob + e->off, e->len) != 0) {
304
+ rc = YEPTRIS_ERROR_MEMORY;
305
+ break;
306
+ }
307
+ root_tagged = root_closed;
308
+ continue;
309
+ default:
310
+ rc = YEPTRIS_ERROR_PARSE; /* unknown op */
311
+ break;
312
+ }
313
+ if (rc != YEPTRIS_OK) {
314
+ break;
315
+ }
316
+ last_id = id; /* TAG entries target this (#300) */
317
+ /* place the fresh node */
318
+ if (depth == 0) {
319
+ if (root != UINT32_MAX) {
320
+ rc = YEPTRIS_ERROR_PARSE; /* two roots */
321
+ break;
322
+ }
323
+ root = id; /* a single scalar root needs no END */
324
+ root_closed = (e->op != YEPTRIS_BUILD_SEQ && e->op != YEPTRIS_BUILD_MAP) ? 1 : 0;
325
+ if (!root_closed) {
326
+ st[depth].id = id;
327
+ st[depth].is_map = (e->op == YEPTRIS_BUILD_MAP);
328
+ st[depth].key_pending = 0;
329
+ depth = 1;
330
+ }
331
+ continue;
332
+ }
333
+ struct frame* top = &st[depth - 1];
334
+ if (top->is_map) {
335
+ if (!top->key_pending) {
336
+ top->key_pending = 1;
337
+ pending_key = id;
338
+ continue;
339
+ }
340
+ /* the check-free pairing twin: document-order entries
341
+ * from a host mapping cannot duplicate, and map_add's
342
+ * linear dup scan is O(n^2) on wide maps */
343
+ int mrc = yep_mut_map_append(doc->dom, top->id, pending_key, id);
344
+ if (mrc == 0) {
345
+ top->key_pending = 0;
346
+ pending_key = UINT32_MAX;
347
+ } else {
348
+ rc = (mrc == -3) ? YEPTRIS_ERROR_DEPTH
349
+ : (mrc == -1 ? YEPTRIS_ERROR_ARG : YEPTRIS_ERROR_MEMORY);
350
+ }
351
+ } else {
352
+ int src_ = yep_mut_seq_add(doc->dom, top->id, id);
353
+ if (src_ != 0) {
354
+ rc = (src_ == -3) ? YEPTRIS_ERROR_DEPTH
355
+ : (src_ == -1 ? YEPTRIS_ERROR_ARG : YEPTRIS_ERROR_MEMORY);
356
+ }
357
+ }
358
+ if (rc == YEPTRIS_OK && (e->op == YEPTRIS_BUILD_SEQ || e->op == YEPTRIS_BUILD_MAP)) {
359
+ if ((size_t)depth >= (size_t)YEP_DOM_MAX_DEPTH) {
360
+ rc = YEPTRIS_ERROR_DEPTH;
361
+ break;
362
+ }
363
+ st[depth].id = id;
364
+ st[depth].is_map = (e->op == YEPTRIS_BUILD_MAP);
365
+ st[depth].key_pending = 0;
366
+ depth++;
367
+ }
368
+ }
369
+ if (rc == YEPTRIS_OK) {
370
+ if (depth > 1 || (depth == 1)) {
371
+ rc = YEPTRIS_ERROR_PARSE; /* an unclosed container */
372
+ } else if (root == UINT32_MAX) {
373
+ rc = YEPTRIS_ERROR_PARSE; /* no root */
374
+ } else if (pending_key != UINT32_MAX) {
375
+ rc = YEPTRIS_ERROR_PARSE; /* a key without its value */
376
+ } else {
377
+ int arc = yep_mut_add_root(doc->dom, root);
378
+ if (arc == 0) {
379
+ rc = YEPTRIS_OK;
380
+ } else if (arc == -4) {
381
+ rc = YEPTRIS_ERROR_PARSE;
382
+ } else if (arc == -3) {
383
+ rc = YEPTRIS_ERROR_DEPTH;
384
+ } else if (arc == -1) {
385
+ rc = YEPTRIS_ERROR_MEMORY;
386
+ } else {
387
+ rc = YEPTRIS_ERROR_ARG;
388
+ }
389
+ }
390
+ }
391
+ yep_free(doc->dom->sys, st);
392
+ return rc;
393
+ }
@@ -0,0 +1,35 @@
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
+ /* The semantic-tag chain law: decode renders the chain into a stack
15
+ * buffer; encode splits that text back into tag heads. ONE pair of
16
+ * constants governs both ends — the nightly's 23-nested-tags artifact
17
+ * (23 links decoded fine, encode-side tags[16] refused) was the two
18
+ * ends disagreeing. 64 links is already pathological (RFC 8949's
19
+ * registry is <20); a link renders up to 20 digits + separator, so
20
+ * the buffer holds a full 64-link chain. */
21
+ #define YEP_CBOR_TAGBUF 1408
22
+ #define YEP_CBOR_TAG_MAX_LINKS 64
23
+
24
+ /* one data item: bytes -> the shared DOM (the plan's item 01) */
25
+ /* One data item. consumed (may be NULL): when given, returns the
26
+ * item's byte extent and TRAILING BYTES ARE NOT an error (the
27
+ * sequence loop steps on them); NULL keeps the one-item contract. */
28
+ int yep_cbor_decode_dom(yep_dom* d, const unsigned char* p, size_t len, int strict,
29
+ size_t* consumed);
30
+
31
+ #ifdef __cplusplus
32
+ }
33
+ #endif
34
+
35
+ #endif /* YEP_CBOR_H */