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,174 @@
1
+ /* cbor.h — the CBOR (RFC 8949) public surface (TODO.cbor).
2
+ *
3
+ * CBOR is the JSON data model in binary: decode builds the same DOM
4
+ * yeptris_parse_json builds, so every query, emit, and binding API
5
+ * applies unchanged. The surface compiles only when the library was
6
+ * built with YEPTRIS_WITH_CBOR (the default). */
7
+ #ifndef YEPTRIS_CBOR_H
8
+ #define YEPTRIS_CBOR_H
9
+
10
+ #include <stddef.h>
11
+
12
+ #include <yeptris/api.h>
13
+ #include <yeptris/error.h>
14
+ #include <yeptris/types.h>
15
+
16
+ #ifdef __cplusplus
17
+ extern "C" {
18
+ #endif
19
+
20
+ /* Flags. */
21
+ #define YEPTRIS_CBOR_STRICT \
22
+ 0x1u /* decode: reject non-minimal length \
23
+ arguments and non-text-string map keys \
24
+ (the deterministic profile's input side) */
25
+ #define YEPTRIS_CBOR_CANONICAL \
26
+ 0x2u /* encode: RFC 8949 s4.2.1 core \
27
+ deterministic profile — minimal lengths, \
28
+ definite lengths, preferred floats, map \
29
+ keys sorted bytewise on their encoded \
30
+ forms (the length-first variant of \
31
+ s4.2.3 is NOT selected) */
32
+
33
+ /* Decodes ONE CBOR data item (RFC 8949). buf must remain valid for the
34
+ * lifetime of the returned document (string values are borrowed
35
+ * zero-copy views; indefinite-length chunks concatenate in the
36
+ * document's arena). Trailing bytes after the item are an error —
37
+ * CBOR Sequences (RFC 8742) get their own entry point.
38
+ *
39
+ * Representation notes (full ledger in src/yeptris/cbor/decode.c):
40
+ * integers beyond int64 materialize as shortest-double text; bignums
41
+ * (tags 2/3) stay tag+bytes; byte and text strings are tag-str
42
+ * scalars; undefined and unassigned simple values are diagnostic text
43
+ * ("undefined", "simple(N)"); tag chains ride the node's tag field as
44
+ * a space-separated decimal chain, outermost first.
45
+ *
46
+ * On failure returns NULL; *status (may be NULL) receives the code
47
+ * (YEPTRIS_ERROR_PARSE well-formedness, YEPTRIS_ERROR_ENCODING UTF-8,
48
+ * YEPTRIS_ERROR_DEPTH nesting, YEPTRIS_ERROR_MEMORY) and
49
+ * yeptris_last_error() carries the message with the byte offset.
50
+ *
51
+ * Memory: the caller owns the document; yeptris_document_free releases
52
+ * everything in one call. */
53
+ YEPTRIS_API YeptrisDocument yeptris_cbor_decode(const void* buf, size_t len, uint32_t opts,
54
+ YeptrisStatus* status);
55
+
56
+ /* The SAX decode face (#742): yeptris_cbor_decode's grammar driving
57
+ * consumer callbacks — items land as they parse, no document, no
58
+ * nodes. Measured (perf ledger 2026-10-29): the scan-only route reads
59
+ * ~2.1x the DOM entry on the same corpus (DOM construction is over
60
+ * half the decode lane), so validation, counting, and streaming
61
+ * transforms belong here. Items arrive in encoding order; map items
62
+ * set is_key on the key half. Strings with borrowed=1 point INTO buf —
63
+ * keep it valid while you hold them; borrowed=0 is decoder scratch.
64
+ * tag ("N N N", outermost first; NULL when none) and tag_len are
65
+ * callback-call-local. open's cap is the expected item count (maps
66
+ * count pairs*2; UINT64_MAX = indefinite); close fires for both the
67
+ * definite-complete and the break path, after the last child. The
68
+ * rendered text forms match the DOM ledger exactly (numbers-as-text,
69
+ * false/true/null/undefined, simple(N)).
70
+ *
71
+ * Every callback returns 0 on sink failure — the decode then reports
72
+ * YEPTRIS_ERROR_MEMORY — and may raise through host languages; the
73
+ * decoder owns no host state across them except the indefinite buffer,
74
+ * which its own exit paths free. All seven callbacks and sax itself
75
+ * must be non-NULL (YEPTRIS_ERROR_ARG otherwise): the loop dispatches
76
+ * unconditionally.
77
+ *
78
+ * consumed == NULL: trailing bytes after the one data item fail
79
+ * YEPTRIS_ERROR_PARSE. consumed != NULL: on success it receives the
80
+ * byte count of the items decoded — walk a CBOR Sequence (RFC 8742)
81
+ * by advancing buf by it. On failure *status (may be NULL) carries the
82
+ * code and yeptris_last_error() the message with the byte offset.
83
+ *
84
+ * Memory: none — the decoder allocates only its indefinite-chunk
85
+ * scratch and frees it on every exit. */
86
+ typedef struct yeptris_cbor_sax {
87
+ void* ctx;
88
+ int (*text)(void* ctx, const char* s, uint32_t n, uint8_t tag_id, int is_key, const char* tag,
89
+ uint32_t tag_len);
90
+ int (*int_val)(void* ctx, int negative, uint64_t mag, int is_key, const char* tag,
91
+ uint32_t tag_len);
92
+ int (*float_val)(void* ctx, double dv, int is_key, const char* tag, uint32_t tag_len);
93
+ int (*str_val)(void* ctx, const unsigned char* p, uint32_t n, int borrowed, int is_key,
94
+ const char* tag, uint32_t tag_len);
95
+ int (*bytes_val)(void* ctx, const unsigned char* p, uint32_t n, int borrowed, int is_key,
96
+ const char* tag, uint32_t tag_len);
97
+ int (*open)(void* ctx, int is_map, uint64_t cap, const char* tag, uint32_t tag_len);
98
+ int (*close)(void* ctx, int is_map);
99
+ } yeptris_cbor_sax;
100
+
101
+ YEPTRIS_API YeptrisStatus yeptris_cbor_decode_sax(const void* buf, size_t len, uint32_t opts,
102
+ const yeptris_cbor_sax* sax, size_t* consumed,
103
+ YeptrisStatus* status);
104
+
105
+ /* CBOR Sequences (RFC 8742): top-level data items, concatenated —
106
+ * no framing bytes. Iterates the buffer, one document per item; the
107
+ * callback OWNS each item (free it with yeptris_document_free) and
108
+ * its nonzero return aborts the iteration. Returns the item count
109
+ * delivered so far. An empty sequence is valid (0 items). A truncated
110
+ * or malformed trailing item fails YEPTRIS_ERROR_PARSE with the item
111
+ * index and byte offset on the error channel. opts: decode flags. */
112
+ typedef int (*yeptris_cbor_item_cb)(void* ctx, YeptrisDocument item, size_t index);
113
+ YEPTRIS_API size_t yeptris_cbor_decode_sequence(const void* buf, size_t len, uint32_t opts,
114
+ yeptris_cbor_item_cb cb, void* ctx,
115
+ YeptrisStatus* status);
116
+
117
+ /* Encodes n documents as a CBOR Sequence: the concatenation of the
118
+ * items (opts as yeptris_cbor_encode_into). buf == NULL: the exact
119
+ * byte count. Otherwise writes at most cap and returns the count; a
120
+ * too-small cap writes nothing and returns the need. Returns 0 on a
121
+ * NULL items entry or an unencodable document. */
122
+ YEPTRIS_API size_t yeptris_cbor_encode_sequence_into(YeptrisDocument* items, size_t n,
123
+ uint32_t opts, void* buf, size_t cap);
124
+
125
+ /* Convenience: the sequence in a malloc'd buffer — caller frees. */
126
+ YEPTRIS_API void* yeptris_cbor_encode_sequence(YeptrisDocument* items, size_t n, uint32_t opts,
127
+ size_t* len);
128
+
129
+ /* Encodes the document's first root as ONE data item (sequences are a
130
+ * separate surface). buf == NULL: returns the exact byte count needed.
131
+ * Otherwise writes at most cap bytes and returns the count written; a
132
+ * too-small cap writes nothing and returns the needed size. Returns 0
133
+ * on a NULL document or an unencodable one (aliases, non-decimal tag
134
+ * text, non-numeric INT/FLOAT text) — yeptris_last_error() says why.
135
+ *
136
+ * Canonical opts sort map keys (s4.2.1); without it, insertion order.
137
+ * encode(decode(x)) is byte-stable across repeated calls. */
138
+ YEPTRIS_API size_t yeptris_cbor_encode_into(YeptrisDocument doc, uint32_t opts, void* buf,
139
+ size_t cap);
140
+
141
+ /* Convenience: encodes into a malloc'd buffer — caller frees with
142
+ * free(). Returns NULL on failure; *len (may be NULL) receives the
143
+ * byte count. */
144
+ YEPTRIS_API void* yeptris_cbor_encode(YeptrisDocument doc, uint32_t opts, size_t* len);
145
+
146
+ /* The binding's dump face (yeptris-ruby#322): Ruby Marshal 4.8 bytes
147
+ * IN, ONE CBOR data item OUT, one C call — the CBOR twin of
148
+ * yeptris_json_from_marshal (marshal.h), walked in C with no Document
149
+ * and no per-node host crossings. opts: YEPTRIS_CBOR_CANONICAL sorts
150
+ * each map's pairs by encoded-key bytes; 0 keeps insertion order.
151
+ *
152
+ * Covers the host subset the per-node route spells: nil/bool/int/
153
+ * float/string/array/hash, symbols (as ":name" text), 'I' wrappers,
154
+ * shared-object links (duplicated bytes), bignums up to four 16-bit
155
+ * words (inside int64 as integers, past either end as preferred
156
+ * floats), and the per-node route's map-key spellings (strings,
157
+ * symbols, integers, floats, booleans). Anything else — objects,
158
+ * structs, user marshal, invalid-UTF-8 strings, non-finite float text,
159
+ * wider bignums, nil/array/hash map keys, cycles — returns
160
+ * YEPTRIS_ERROR_UNSUPPORTED and the binding keeps its per-node walk.
161
+ *
162
+ * The bytes are byte-identical to yeptris_cbor_encode over the
163
+ * document the per-node walk builds (pinned by test_cbor_marshal.cpp).
164
+ * *out is malloc'd, free with yeptris_marshal_free (or free) exactly
165
+ * once; on failure nothing is allocated. Trailing bytes after the
166
+ * root are UNSUPPORTED (the stream is exactly one value). */
167
+ YEPTRIS_API YeptrisStatus yeptris_cbor_from_marshal(const char* m, size_t m_len, uint32_t opts,
168
+ char** out, size_t* out_len);
169
+
170
+ #ifdef __cplusplus
171
+ }
172
+ #endif
173
+
174
+ #endif /* YEPTRIS_CBOR_H */
@@ -0,0 +1,196 @@
1
+ /* document.h / node.h surface — DOM accessors (TODO.impl/11).
2
+ * Pinned enums: bindings hard-code these values (test_abi). */
3
+
4
+ #ifndef YEPTRIS_DOM_PUBLIC_H
5
+ #define YEPTRIS_DOM_PUBLIC_H
6
+
7
+ #include <stddef.h>
8
+ #include <stdint.h>
9
+
10
+ #include <yeptris/api.h>
11
+ #include <yeptris/error.h>
12
+ #include <yeptris/resolve.h> /* YeptrisSchema */
13
+ #include <yeptris/types.h>
14
+
15
+ #ifdef __cplusplus
16
+ extern "C" {
17
+ #endif
18
+
19
+ typedef enum {
20
+ YEPTRIS_NODE_SCALAR = 0,
21
+ YEPTRIS_NODE_SEQUENCE = 1,
22
+ YEPTRIS_NODE_MAPPING = 2,
23
+ YEPTRIS_NODE_ALIAS = 3,
24
+ } YeptrisNodeKind;
25
+
26
+ typedef enum {
27
+ YEPTRIS_STYLE_ANY = 0,
28
+ YEPTRIS_STYLE_PLAIN = 1,
29
+ YEPTRIS_STYLE_SINGLE_QUOTED = 2,
30
+ YEPTRIS_STYLE_DOUBLE_QUOTED = 3,
31
+ YEPTRIS_STYLE_LITERAL = 4,
32
+ YEPTRIS_STYLE_FOLDED = 5,
33
+ } YeptrisScalarStyle;
34
+
35
+ /* Releases the document and everything reachable from it (one call).
36
+ * Handles are invalid afterwards. NULL is accepted. */
37
+ YEPTRIS_API void yeptris_document_free(YeptrisDocument doc);
38
+
39
+ /* Number of documents in the parsed stream. */
40
+ YEPTRIS_API size_t yeptris_document_count(YeptrisDocument doc);
41
+
42
+ /* Root node of document i (0-based); NULL when out of range. */
43
+ YEPTRIS_API YeptrisNode yeptris_document_root(YeptrisDocument doc, size_t index);
44
+
45
+ YEPTRIS_API YeptrisNodeKind yeptris_node_kind(YeptrisNode node);
46
+
47
+ /* Stable identity of the node within its document (bindings key
48
+ * wrapper caches on it; query handles are transient, ids are not).
49
+ * Only for equality — not an index into any public structure. */
50
+ YEPTRIS_API uint32_t yeptris_node_id(YeptrisNode node);
51
+
52
+ /* Scalar content / alias name. Returns NULL for collections.
53
+ * Memory: borrowed from the input (or document-owned when the value was
54
+ * folded/escaped) — valid until yeptris_document_free. */
55
+ YEPTRIS_API const char* yeptris_node_value(YeptrisNode node, size_t* len);
56
+
57
+ YEPTRIS_API YeptrisScalarStyle yeptris_node_style(YeptrisNode node);
58
+
59
+ /* Node properties; empty (NULL, 0) when absent. */
60
+ YEPTRIS_API const char* yeptris_node_tag(YeptrisNode node, size_t* len);
61
+ YEPTRIS_API const char* yeptris_node_anchor(YeptrisNode node, size_t* len);
62
+
63
+ /* Alias target node; NULL for non-aliases. */
64
+ YEPTRIS_API YeptrisNode yeptris_node_alias_target(YeptrisNode node);
65
+
66
+ /* Sequence entry count / entry i. */
67
+ YEPTRIS_API size_t yeptris_node_seq_count(YeptrisNode node);
68
+ YEPTRIS_API YeptrisNode yeptris_node_seq_at(YeptrisNode node, size_t index);
69
+
70
+ /* Mapping pair count / value for a key (linear; interning lands with the
71
+ * full DOM item). The first matching key wins. */
72
+ YEPTRIS_API size_t yeptris_node_map_count(YeptrisNode node);
73
+ YEPTRIS_API YeptrisNode yeptris_node_map_get(YeptrisNode node, const char* key, size_t key_len);
74
+
75
+ /* Ordered pair access: key and value of pair i (0-based). Returns 0
76
+ * and sets the out-params when the index is in range, -1 otherwise. */
77
+ YEPTRIS_API int yeptris_node_map_at(YeptrisNode node, size_t index, YeptrisNode* key,
78
+ YeptrisNode* value);
79
+
80
+ /* Bulk children drain — the O(n) iteration primitive (ruby #168: the
81
+ * per-index seq_at/map_at walks make an 80k-row sequence O(n^2)). One
82
+ * call walks the child list once and fills out[0..cap) with handles:
83
+ * sequence elements in order; mapping KEY,VALUE pairs interleaved.
84
+ * Returns the total child count (mapping pairs count twice); out==NULL
85
+ * or cap==0 returns the count without allocating handles. Handles come
86
+ * from the document's pool — document_free reclaims them. */
87
+ YEPTRIS_API size_t yeptris_node_children(YeptrisNode node, YeptrisNode* out, size_t cap);
88
+
89
+ /* ---- Construction (TODO.impl/11 phase 3) ----
90
+ *
91
+ * Build documents from scratch and mutate them; the emitter and every
92
+ * query API above work on synthesized documents unchanged. All values
93
+ * are COPIED into the document — nothing is borrowed from the caller.
94
+ * Nodes belong to exactly one parent (or one document root); a node
95
+ * already attached, a duplicate map key (add), cross-document links,
96
+ * and trees deeper than the nesting cap (YEPTRIS_ERROR_DEPTH) are
97
+ * rejected. Deletion unlinks but keeps arena lifetime: handles stay
98
+ * valid until yeptris_document_free. */
99
+
100
+ /* An empty document with no input; build nodes and set the root. */
101
+ YEPTRIS_API YeptrisDocument yeptris_document_new(void);
102
+
103
+ /* The same, with the schema resolver plain scalars type through
104
+ * (YEPTRIS_SCHEMA_12_CORE is yeptris_document_new's default). Additive
105
+ * ABI. */
106
+ YEPTRIS_API YeptrisDocument yeptris_document_new_schema(YeptrisSchema schema);
107
+
108
+ /* Records a detached node as document i's root. */
109
+ YEPTRIS_API int yeptris_document_set_root(YeptrisDocument doc, YeptrisNode root);
110
+
111
+ YEPTRIS_API YeptrisNode yeptris_node_new_mapping(YeptrisDocument doc);
112
+ YEPTRIS_API YeptrisNode yeptris_node_new_sequence(YeptrisDocument doc);
113
+
114
+ /* Memory: value copied (document lifetime). Plain style types the copy
115
+ * through the schema resolver exactly like parse; quoted/block styles
116
+ * force string. */
117
+ YEPTRIS_API YeptrisNode yeptris_node_new_scalar(YeptrisDocument doc, const char* value, size_t len,
118
+ YeptrisScalarStyle style);
119
+
120
+ /* YEPTRIS_OK, or ERROR_ARG (cross-document/detached misuse),
121
+ * ERROR_MEMORY, ERROR_DEPTH, ERROR_PARSE (duplicate key). */
122
+ YEPTRIS_API int yeptris_node_map_add(YeptrisNode map, const char* key, size_t key_len,
123
+ YeptrisNode value);
124
+
125
+ /* Replace-or-add: an existing key keeps its position and swaps the
126
+ * value; a new key appends. */
127
+ YEPTRIS_API int yeptris_node_map_set(YeptrisNode map, const char* key, size_t key_len,
128
+ YeptrisNode value);
129
+
130
+ YEPTRIS_API int yeptris_node_seq_add(YeptrisNode seq, YeptrisNode value);
131
+ YEPTRIS_API int yeptris_node_seq_del(YeptrisNode seq, size_t index);
132
+
133
+ /* Replace the entry at index (same position kept). */
134
+ YEPTRIS_API int yeptris_node_seq_set(YeptrisNode seq, size_t index, YeptrisNode value);
135
+ YEPTRIS_API int yeptris_node_map_del(YeptrisNode map, const char* key, size_t key_len);
136
+
137
+ /* ---- bulk build (TODO.impl/15 phase D: the dump-side mirror of the
138
+ * recorder's bulk drain — ONE call builds a whole document, so
139
+ * bindings never pay per-node FFI) ------------------------------------- */
140
+
141
+ typedef enum {
142
+ YEPTRIS_BUILD_SCALAR = 1, /* push a scalar (value bytes in the blob) */
143
+ YEPTRIS_BUILD_SEQ = 2, /* open a sequence */
144
+ YEPTRIS_BUILD_MAP = 3, /* open a mapping */
145
+ YEPTRIS_BUILD_END = 4, /* close the innermost open container */
146
+ YEPTRIS_BUILD_TAG = 5, /* tag the last-placed node (tag bytes in
147
+ * the blob) — #300: nil mapping keys need
148
+ * Psych's explicit `!` tag */
149
+ } YeptrisBuildOp;
150
+
151
+ /* 12 bytes, ABI-pinned: op, style (scalar: YeptrisScalarStyle;
152
+ * ignored for containers), reserved, then the value slice. */
153
+ typedef struct {
154
+ uint8_t op;
155
+ uint8_t style;
156
+ uint16_t reserved;
157
+ uint32_t off;
158
+ uint32_t len;
159
+ } YeptrisBuildEntry;
160
+ #if defined(__cplusplus)
161
+ static_assert(sizeof(YeptrisBuildEntry) == 12, "build entry layout pinned");
162
+ #else
163
+ _Static_assert(sizeof(YeptrisBuildEntry) == 12, "build entry layout pinned");
164
+ #endif
165
+
166
+ /* Walks the entries in order — the same document-order grammar as the
167
+ * event stream: scalars link into the innermost open container (in a
168
+ * mapping, entries alternate key/value), SEQ/MAP open a child
169
+ * container, END closes it; after the last entry exactly one root
170
+ * must remain open-free and becomes the document root. Scalars copy
171
+ * their bytes from the blob (nothing is borrowed). Duplicate keys
172
+ * keep the LAST value, exactly as the parser accepts them (host
173
+ * mappings cannot produce one; the check would cost O(n^2) on wide
174
+ * maps). Returns YEPTRIS_OK, ERROR_ARG (NULL inputs),
175
+ * ERROR_PARSE (imbalanced walk: END on an empty stack, entries after
176
+ * the root closed, an unclosed container, a dangling key, a bad op
177
+ * or out-of-range slice), ERROR_DEPTH, or ERROR_MEMORY. */
178
+ YEPTRIS_API YeptrisStatus yeptris_document_build(YeptrisDocument doc,
179
+ const YeptrisBuildEntry* entries, size_t count,
180
+ const char* blob, size_t blob_len);
181
+
182
+ /* Appends a pre-built key node (duplicate rejected). */
183
+ YEPTRIS_API int yeptris_node_map_add_node(YeptrisNode map, YeptrisNode key, YeptrisNode value);
184
+
185
+ /* Props on synthesized nodes (copied in). An alias node carries its
186
+ * display name and resolves to `target` for queries/serialization. */
187
+ YEPTRIS_API int yeptris_node_set_anchor(YeptrisNode node, const char* name, size_t len);
188
+ YEPTRIS_API int yeptris_node_set_tag(YeptrisNode node, const char* tag, size_t len);
189
+ YEPTRIS_API YeptrisNode yeptris_node_new_alias(YeptrisDocument doc, YeptrisNode target,
190
+ const char* name, size_t len);
191
+
192
+ #ifdef __cplusplus
193
+ }
194
+ #endif
195
+
196
+ #endif /* YEPTRIS_DOM_PUBLIC_H */
@@ -0,0 +1,128 @@
1
+ /* emit.h — serialization (TODO.impl/13).
2
+ *
3
+ * One writer engine serves DOM walks and (with 13C) event streams;
4
+ * sizing runs the SAME engine dry, so the size query and the write
5
+ * agree by construction — zero reallocations after the reserve.
6
+ *
7
+ * Roundtrip fidelity: re-serializing a parsed document re-emits its
8
+ * recorded scalar styles (a plain stays plain where safe, quoted stays
9
+ * quoted, block scalars stay block). Byte stability:
10
+ * serialize(parse(serialize(x))) == serialize(x) — gated by the
11
+ * corpus roundtrip test.
12
+ */
13
+ #ifndef YEPTRIS_EMIT_H
14
+ #define YEPTRIS_EMIT_H
15
+
16
+ #include <stddef.h>
17
+ #include <stdint.h>
18
+
19
+ #include <yeptris/api.h>
20
+ #include <yeptris/types.h>
21
+
22
+ #ifdef __cplusplus
23
+ extern "C" {
24
+ #endif
25
+
26
+ /* Emission options (13B). Versioned by size: initialize with
27
+ * {sizeof(yeptris_emit_options)} so future fields stay optional.
28
+ *
29
+ * Deliberately omitted: a flowLevel knob (libyaml's best_width +
30
+ * default_flow_style interplay). The engine's style chooser is
31
+ * recorded-style driven — flow is whatever the document recorded
32
+ * (plus the fixed canonical/JSON forms) — so there is no "switch to
33
+ * flow past level N" decision to expose; revisit only if a binding
34
+ * face actually needs PyYAML's default_flow_style mapping. */
35
+ typedef struct yeptris_emit_options {
36
+ uint32_t size; /* sizeof(yeptris_emit_options) */
37
+ int canonical; /* fixed form: flow collections, quoted strings,
38
+ * typed words, shortest floats; a parse of the
39
+ * output re-serializes byte-identically */
40
+ int best_width; /* (#1257) the fold/wrap column, clamped the
41
+ * way libyaml's emitter init does:
42
+ * `best_width < 0` NEVER wraps (Psych's
43
+ * `line_width: -1` unwrap); `0 <= width <=
44
+ * best_indent*2` snaps to 80; 0 or absent =
45
+ * the library default 80. Drives the flow
46
+ * wrap (13B) and — with folding on (the
47
+ * default, #1257) — the block scalar fold
48
+ * column (#903). Only read when the
49
+ * caller's struct is large enough. */
50
+ int explicit_doc_start; /* nonzero: every document carries the
51
+ * leading --- marker (Psych/libyaml's
52
+ * implicit=false parity). Default 0: a
53
+ * single document is emitted bare. Only
54
+ * read when the caller's struct is large
55
+ * enough (size-versioned). */
56
+ int best_indent; /* (#903) block indentation per level: the
57
+ * content column of a nested block mapping
58
+ * and the "- " item level. Out of range
59
+ * (< 2 or > 9, libyaml's clamp) or 0 = the
60
+ * library default 2. Only read when the
61
+ * caller's struct is large enough. */
62
+ int block_fold; /* (#903, the #1257 default flip) nonzero:
63
+ * plain and single-quoted scalars in block
64
+ * context fold at best_width the way
65
+ * libyaml/Psych/PyYAML do — at an interior
66
+ * single space past the width the break
67
+ * replaces the space and the continuation
68
+ * re-indents to parent_col + best_indent.
69
+ * DEFAULT ON (a fold default matches
70
+ * Psych's stored-file bytes; an explicit 0
71
+ * unwraps, as does best_width < 0). Keys
72
+ * and flow members never fold;
73
+ * canonical/JSON keep their fixed forms.
74
+ * Only read when the caller's struct is
75
+ * large enough. */
76
+ } yeptris_emit_options;
77
+
78
+ /* Options-aware entries; opts == NULL selects the fidelity mode
79
+ * (recorded styles re-emitted). Same contracts as below. */
80
+ YEPTRIS_API size_t yeptris_serialize_into_ex(YeptrisDocument doc, const yeptris_emit_options* opts,
81
+ char* buf, size_t cap);
82
+ YEPTRIS_API char* yeptris_serialize_ex(YeptrisDocument doc, const yeptris_emit_options* opts,
83
+ size_t* len);
84
+
85
+ /* Serializes the document set. buf == NULL: returns the exact byte
86
+ * count needed and writes nothing. Otherwise writes at most cap bytes
87
+ * (NUL-terminated when cap allows) and returns the count written;
88
+ * when cap is too small nothing is written and the needed size is
89
+ * returned. Returns 0 on a NULL document. */
90
+ YEPTRIS_API size_t yeptris_serialize_into(YeptrisDocument doc, char* buf, size_t cap);
91
+
92
+ /* Trusted-cap emission (#352): ONE write pass into the caller's
93
+ * fixed buffer — no sizing pass, no per-call allocation. Returns the
94
+ * byte count written when ret < cap (the document is complete and
95
+ * NUL-terminated at buf[ret]); when ret >= cap the output did not
96
+ * fit — buf holds a partial document and ret is the exact total the
97
+ * document needs (re-call with cap >= ret + 1; the retry writes
98
+ * identical bytes). opts == NULL selects the fidelity mode. Returns 0
99
+ * on a NULL document or buffer (use yeptris_serialize_into for the
100
+ * measure-only form). */
101
+ YEPTRIS_API size_t yeptris_serialize_into_trusted(YeptrisDocument doc,
102
+ const yeptris_emit_options* opts, char* buf,
103
+ size_t cap);
104
+
105
+ /* Streaming emission (13C): bytes are delivered in chunks to sink as
106
+ * the walk proceeds — memory bounded by the largest scalar, never the
107
+ * document. Returns the total byte count, or 0 on a NULL argument or
108
+ * when the sink aborts (nonzero return aborts the walk). */
109
+ typedef int (*yeptris_emit_sink)(void* ctx, const char* bytes, size_t len);
110
+ YEPTRIS_API size_t yeptris_serialize_stream(YeptrisDocument doc, const yeptris_emit_options* opts,
111
+ yeptris_emit_sink sink, void* ctx);
112
+
113
+ /* Convenience: serializes into a malloc'd buffer (caller frees).
114
+ * Returns NULL on allocation failure or a NULL document; *len (may be
115
+ * NULL) receives the byte count. The buffer is NUL-terminated. */
116
+ YEPTRIS_API char* yeptris_serialize(YeptrisDocument doc, size_t* len);
117
+
118
+ /* Frees a buffer the library returned (the serialize* family's
119
+ * "caller frees" contract). The buffer was allocated by THIS
120
+ * library's allocator — freeing it with the host's free is
121
+ * wrong-CRT on Windows (the #318 mingw lesson). NULL is a no-op. */
122
+ YEPTRIS_API void yeptris_free(void* p);
123
+
124
+ #ifdef __cplusplus
125
+ }
126
+ #endif
127
+
128
+ #endif /* YEPTRIS_EMIT_H */
@@ -0,0 +1,42 @@
1
+ /* error.h — public status codes.
2
+ *
3
+ * Public entry points write only these codes (the internal error channel —
4
+ * thread-local + per-document messages with line/column — lands with
5
+ * TODO.impl/02). Enum values are ABI: bindings hard-code them and the ABI
6
+ * pinning test (test/unit/test_abi.cpp) fails if one shifts without a major
7
+ * version bump.
8
+ */
9
+ #include <stdint.h>
10
+
11
+ #ifndef YEPTRIS_ERROR_H
12
+ #define YEPTRIS_ERROR_H
13
+
14
+ #ifdef __cplusplus
15
+ extern "C" {
16
+ #endif
17
+
18
+ typedef enum {
19
+ YEPTRIS_OK = 0, /* success */
20
+ YEPTRIS_ERROR_PARSE = 1, /* malformed YAML (details + line/col via the error channel) */
21
+ YEPTRIS_ERROR_MEMORY = 2, /* allocation failure; document remains freeable */
22
+ YEPTRIS_ERROR_DEPTH = 3, /* nesting exceeds max_depth (default 1000) */
23
+ YEPTRIS_ERROR_ENCODING = 4, /* invalid input encoding / ill-formed UTF-8 */
24
+ YEPTRIS_ERROR_IO = 5, /* caller-supplied I/O failure */
25
+ YEPTRIS_ERROR_ARG = 6, /* invalid argument (NULL handle, bad option) */
26
+ YEPTRIS_ERROR_UNSUPPORTED = 7, /* requested feature not built in */
27
+ YEPTRIS_ERROR_INTERNAL = 8, /* invariant violation — a bug, please report */
28
+ YEPTRIS_ERROR_SCHEMA = 9, /* validation: the report carries diagnostics (#882);
29
+ * descriptor materialization: REQUIRED missing (#238) */
30
+ } YeptrisStatus;
31
+
32
+ /* Message of the most recent failure on the calling thread, with its
33
+ * 1-based line/column (0 = unknown). Returns "" when the last operation
34
+ * succeeded. Memory: thread-local static storage; valid until the next
35
+ * library call on this thread. */
36
+ YEPTRIS_API const char* yeptris_last_error(uint32_t* line, uint32_t* col);
37
+
38
+ #ifdef __cplusplus
39
+ }
40
+ #endif
41
+
42
+ #endif /* YEPTRIS_ERROR_H */