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,190 @@
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/types.h>
13
+
14
+ #ifdef __cplusplus
15
+ extern "C" {
16
+ #endif
17
+
18
+ typedef enum {
19
+ YEPTRIS_NODE_SCALAR = 0,
20
+ YEPTRIS_NODE_SEQUENCE = 1,
21
+ YEPTRIS_NODE_MAPPING = 2,
22
+ YEPTRIS_NODE_ALIAS = 3,
23
+ } YeptrisNodeKind;
24
+
25
+ typedef enum {
26
+ YEPTRIS_STYLE_ANY = 0,
27
+ YEPTRIS_STYLE_PLAIN = 1,
28
+ YEPTRIS_STYLE_SINGLE_QUOTED = 2,
29
+ YEPTRIS_STYLE_DOUBLE_QUOTED = 3,
30
+ YEPTRIS_STYLE_LITERAL = 4,
31
+ YEPTRIS_STYLE_FOLDED = 5,
32
+ } YeptrisScalarStyle;
33
+
34
+ /* Releases the document and everything reachable from it (one call).
35
+ * Handles are invalid afterwards. NULL is accepted. */
36
+ YEPTRIS_API void yeptris_document_free(YeptrisDocument doc);
37
+
38
+ /* Number of documents in the parsed stream. */
39
+ YEPTRIS_API size_t yeptris_document_count(YeptrisDocument doc);
40
+
41
+ /* Root node of document i (0-based); NULL when out of range. */
42
+ YEPTRIS_API YeptrisNode yeptris_document_root(YeptrisDocument doc, size_t index);
43
+
44
+ YEPTRIS_API YeptrisNodeKind yeptris_node_kind(YeptrisNode node);
45
+
46
+ /* Stable identity of the node within its document (bindings key
47
+ * wrapper caches on it; query handles are transient, ids are not).
48
+ * Only for equality — not an index into any public structure. */
49
+ YEPTRIS_API uint32_t yeptris_node_id(YeptrisNode node);
50
+
51
+ /* Scalar content / alias name. Returns NULL for collections.
52
+ * Memory: borrowed from the input (or document-owned when the value was
53
+ * folded/escaped) — valid until yeptris_document_free. */
54
+ YEPTRIS_API const char* yeptris_node_value(YeptrisNode node, size_t* len);
55
+
56
+ YEPTRIS_API YeptrisScalarStyle yeptris_node_style(YeptrisNode node);
57
+
58
+ /* Node properties; empty (NULL, 0) when absent. */
59
+ YEPTRIS_API const char* yeptris_node_tag(YeptrisNode node, size_t* len);
60
+ YEPTRIS_API const char* yeptris_node_anchor(YeptrisNode node, size_t* len);
61
+
62
+ /* Alias target node; NULL for non-aliases. */
63
+ YEPTRIS_API YeptrisNode yeptris_node_alias_target(YeptrisNode node);
64
+
65
+ /* Sequence entry count / entry i. */
66
+ YEPTRIS_API size_t yeptris_node_seq_count(YeptrisNode node);
67
+ YEPTRIS_API YeptrisNode yeptris_node_seq_at(YeptrisNode node, size_t index);
68
+
69
+ /* Mapping pair count / value for a key (linear; interning lands with the
70
+ * full DOM item). The first matching key wins. */
71
+ YEPTRIS_API size_t yeptris_node_map_count(YeptrisNode node);
72
+ YEPTRIS_API YeptrisNode yeptris_node_map_get(YeptrisNode node, const char* key, size_t key_len);
73
+
74
+ /* Ordered pair access: key and value of pair i (0-based). Returns 0
75
+ * and sets the out-params when the index is in range, -1 otherwise. */
76
+ YEPTRIS_API int yeptris_node_map_at(YeptrisNode node, size_t index, YeptrisNode* key,
77
+ YeptrisNode* value);
78
+
79
+ /* Bulk children drain — the O(n) iteration primitive (ruby #168: the
80
+ * per-index seq_at/map_at walks make an 80k-row sequence O(n^2)). One
81
+ * call walks the child list once and fills out[0..cap) with handles:
82
+ * sequence elements in order; mapping KEY,VALUE pairs interleaved.
83
+ * Returns the total child count (mapping pairs count twice); out==NULL
84
+ * or cap==0 returns the count without allocating handles. Handles come
85
+ * from the document's pool — document_free reclaims them. */
86
+ YEPTRIS_API size_t yeptris_node_children(YeptrisNode node, YeptrisNode* out, size_t cap);
87
+
88
+ /* ---- Construction (TODO.impl/11 phase 3) ----
89
+ *
90
+ * Build documents from scratch and mutate them; the emitter and every
91
+ * query API above work on synthesized documents unchanged. All values
92
+ * are COPIED into the document — nothing is borrowed from the caller.
93
+ * Nodes belong to exactly one parent (or one document root); a node
94
+ * already attached, a duplicate map key (add), cross-document links,
95
+ * and trees deeper than the nesting cap (YEPTRIS_ERROR_DEPTH) are
96
+ * rejected. Deletion unlinks but keeps arena lifetime: handles stay
97
+ * valid until yeptris_document_free. */
98
+
99
+ /* An empty document with no input; build nodes and set the root. */
100
+ YEPTRIS_API YeptrisDocument yeptris_document_new(void);
101
+
102
+ /* Records a detached node as document i's root. */
103
+ YEPTRIS_API int yeptris_document_set_root(YeptrisDocument doc, YeptrisNode root);
104
+
105
+ YEPTRIS_API YeptrisNode yeptris_node_new_mapping(YeptrisDocument doc);
106
+ YEPTRIS_API YeptrisNode yeptris_node_new_sequence(YeptrisDocument doc);
107
+
108
+ /* Memory: value copied (document lifetime). Plain style types the copy
109
+ * through the schema resolver exactly like parse; quoted/block styles
110
+ * force string. */
111
+ YEPTRIS_API YeptrisNode yeptris_node_new_scalar(YeptrisDocument doc, const char* value, size_t len,
112
+ YeptrisScalarStyle style);
113
+
114
+ /* YEPTRIS_OK, or ERROR_ARG (cross-document/detached misuse),
115
+ * ERROR_MEMORY, ERROR_DEPTH, ERROR_PARSE (duplicate key). */
116
+ YEPTRIS_API int yeptris_node_map_add(YeptrisNode map, const char* key, size_t key_len,
117
+ YeptrisNode value);
118
+
119
+ /* Replace-or-add: an existing key keeps its position and swaps the
120
+ * value; a new key appends. */
121
+ YEPTRIS_API int yeptris_node_map_set(YeptrisNode map, const char* key, size_t key_len,
122
+ YeptrisNode value);
123
+
124
+ YEPTRIS_API int yeptris_node_seq_add(YeptrisNode seq, YeptrisNode value);
125
+ YEPTRIS_API int yeptris_node_seq_del(YeptrisNode seq, size_t index);
126
+
127
+ /* Replace the entry at index (same position kept). */
128
+ YEPTRIS_API int yeptris_node_seq_set(YeptrisNode seq, size_t index, YeptrisNode value);
129
+ YEPTRIS_API int yeptris_node_map_del(YeptrisNode map, const char* key, size_t key_len);
130
+
131
+ /* ---- bulk build (TODO.impl/15 phase D: the dump-side mirror of the
132
+ * recorder's bulk drain — ONE call builds a whole document, so
133
+ * bindings never pay per-node FFI) ------------------------------------- */
134
+
135
+ typedef enum {
136
+ YEPTRIS_BUILD_SCALAR = 1, /* push a scalar (value bytes in the blob) */
137
+ YEPTRIS_BUILD_SEQ = 2, /* open a sequence */
138
+ YEPTRIS_BUILD_MAP = 3, /* open a mapping */
139
+ YEPTRIS_BUILD_END = 4, /* close the innermost open container */
140
+ YEPTRIS_BUILD_TAG = 5, /* tag the last-placed node (tag bytes in
141
+ * the blob) — #300: nil mapping keys need
142
+ * Psych's explicit `!` tag */
143
+ } YeptrisBuildOp;
144
+
145
+ /* 12 bytes, ABI-pinned: op, style (scalar: YeptrisScalarStyle;
146
+ * ignored for containers), reserved, then the value slice. */
147
+ typedef struct {
148
+ uint8_t op;
149
+ uint8_t style;
150
+ uint16_t reserved;
151
+ uint32_t off;
152
+ uint32_t len;
153
+ } YeptrisBuildEntry;
154
+ #if defined(__cplusplus)
155
+ static_assert(sizeof(YeptrisBuildEntry) == 12, "build entry layout pinned");
156
+ #else
157
+ _Static_assert(sizeof(YeptrisBuildEntry) == 12, "build entry layout pinned");
158
+ #endif
159
+
160
+ /* Walks the entries in order — the same document-order grammar as the
161
+ * event stream: scalars link into the innermost open container (in a
162
+ * mapping, entries alternate key/value), SEQ/MAP open a child
163
+ * container, END closes it; after the last entry exactly one root
164
+ * must remain open-free and becomes the document root. Scalars copy
165
+ * their bytes from the blob (nothing is borrowed). Duplicate keys
166
+ * keep the LAST value, exactly as the parser accepts them (host
167
+ * mappings cannot produce one; the check would cost O(n^2) on wide
168
+ * maps). Returns YEPTRIS_OK, ERROR_ARG (NULL inputs),
169
+ * ERROR_PARSE (imbalanced walk: END on an empty stack, entries after
170
+ * the root closed, an unclosed container, a dangling key, a bad op
171
+ * or out-of-range slice), ERROR_DEPTH, or ERROR_MEMORY. */
172
+ YEPTRIS_API YeptrisStatus yeptris_document_build(YeptrisDocument doc,
173
+ const YeptrisBuildEntry* entries, size_t count,
174
+ const char* blob, size_t blob_len);
175
+
176
+ /* Appends a pre-built key node (duplicate rejected). */
177
+ YEPTRIS_API int yeptris_node_map_add_node(YeptrisNode map, YeptrisNode key, YeptrisNode value);
178
+
179
+ /* Props on synthesized nodes (copied in). An alias node carries its
180
+ * display name and resolves to `target` for queries/serialization. */
181
+ YEPTRIS_API int yeptris_node_set_anchor(YeptrisNode node, const char* name, size_t len);
182
+ YEPTRIS_API int yeptris_node_set_tag(YeptrisNode node, const char* tag, size_t len);
183
+ YEPTRIS_API YeptrisNode yeptris_node_new_alias(YeptrisDocument doc, YeptrisNode target,
184
+ const char* name, size_t len);
185
+
186
+ #ifdef __cplusplus
187
+ }
188
+ #endif
189
+
190
+ #endif /* YEPTRIS_DOM_PUBLIC_H */
@@ -0,0 +1,81 @@
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
+ typedef struct yeptris_emit_options {
29
+ uint32_t size; /* sizeof(yeptris_emit_options) */
30
+ int canonical; /* fixed form: flow collections, quoted strings,
31
+ * typed words, shortest floats; a parse of the
32
+ * output re-serializes byte-identically */
33
+ int best_width; /* 0 = library default (80): flow collections
34
+ * wrap after a value when the current line
35
+ * exceeds the width (13B) */
36
+ int explicit_doc_start; /* nonzero: every document carries the
37
+ * leading --- marker (Psych/libyaml's
38
+ * implicit=false parity). Default 0: a
39
+ * single document is emitted bare. Only
40
+ * read when the caller's struct is large
41
+ * enough (size-versioned). */
42
+ } yeptris_emit_options;
43
+
44
+ /* Options-aware entries; opts == NULL selects the fidelity mode
45
+ * (recorded styles re-emitted). Same contracts as below. */
46
+ YEPTRIS_API size_t yeptris_serialize_into_ex(YeptrisDocument doc, const yeptris_emit_options* opts,
47
+ char* buf, size_t cap);
48
+ YEPTRIS_API char* yeptris_serialize_ex(YeptrisDocument doc, const yeptris_emit_options* opts,
49
+ size_t* len);
50
+
51
+ /* Serializes the document set. buf == NULL: returns the exact byte
52
+ * count needed and writes nothing. Otherwise writes at most cap bytes
53
+ * (NUL-terminated when cap allows) and returns the count written;
54
+ * when cap is too small nothing is written and the needed size is
55
+ * returned. Returns 0 on a NULL document. */
56
+ YEPTRIS_API size_t yeptris_serialize_into(YeptrisDocument doc, char* buf, size_t cap);
57
+
58
+ /* Streaming emission (13C): bytes are delivered in chunks to sink as
59
+ * the walk proceeds — memory bounded by the largest scalar, never the
60
+ * document. Returns the total byte count, or 0 on a NULL argument or
61
+ * when the sink aborts (nonzero return aborts the walk). */
62
+ typedef int (*yeptris_emit_sink)(void* ctx, const char* bytes, size_t len);
63
+ YEPTRIS_API size_t yeptris_serialize_stream(YeptrisDocument doc, const yeptris_emit_options* opts,
64
+ yeptris_emit_sink sink, void* ctx);
65
+
66
+ /* Convenience: serializes into a malloc'd buffer (caller frees).
67
+ * Returns NULL on allocation failure or a NULL document; *len (may be
68
+ * NULL) receives the byte count. The buffer is NUL-terminated. */
69
+ YEPTRIS_API char* yeptris_serialize(YeptrisDocument doc, size_t* len);
70
+
71
+ /* Frees a buffer the library returned (the serialize* family's
72
+ * "caller frees" contract). The buffer was allocated by THIS
73
+ * library's allocator — freeing it with the host's free is
74
+ * wrong-CRT on Windows (the #318 mingw lesson). NULL is a no-op. */
75
+ YEPTRIS_API void yeptris_free(void* p);
76
+
77
+ #ifdef __cplusplus
78
+ }
79
+ #endif
80
+
81
+ #endif /* YEPTRIS_EMIT_H */
@@ -0,0 +1,41 @@
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, /* descriptor materialization: a REQUIRED node missing (issue #238) */
29
+ } YeptrisStatus;
30
+
31
+ /* Message of the most recent failure on the calling thread, with its
32
+ * 1-based line/column (0 = unknown). Returns "" when the last operation
33
+ * succeeded. Memory: thread-local static storage; valid until the next
34
+ * library call on this thread. */
35
+ YEPTRIS_API const char* yeptris_last_error(uint32_t* line, uint32_t* col);
36
+
37
+ #ifdef __cplusplus
38
+ }
39
+ #endif
40
+
41
+ #endif /* YEPTRIS_ERROR_H */
@@ -0,0 +1,157 @@
1
+ /* events.h — the four consumption models over one engine (TODO.impl/12).
2
+ *
3
+ * push: one callback per event (C users; ~1 µs/event through FFI —
4
+ * bindings prefer the recorder's bulk drain).
5
+ * pull: StAX-style cursor; zero C->host dispatch; event strings are
6
+ * owned by the puller and valid UNTIL THE NEXT CALL.
7
+ * recorder: fixed-size records + one string arena; bulk drain, O(chunks)
8
+ * host crossings. v1 buffers input until the final chunk; the
9
+ * streaming feed (mid-document resumption) lands with
10
+ * parse/feed.c and keeps this shape.
11
+ * iterparse: document-at-a-time over multi-document streams; one
12
+ * document's events per call, memory bounded by the largest
13
+ * document. Events valid UNTIL THE NEXT CALL.
14
+ *
15
+ * All four are sinks over the single parse engine: identical event
16
+ * streams, proven by the cross-model corpus check (test_events_cross).
17
+ */
18
+ #ifndef YEPTRIS_EVENTS_H
19
+ #define YEPTRIS_EVENTS_H
20
+
21
+ #include <stddef.h>
22
+ #include <stdint.h>
23
+
24
+ #include <yeptris/api.h>
25
+ #include <yeptris/error.h> /* YeptrisStatus */
26
+ #include <yeptris/resolve.h> /* YeptrisSchema */
27
+ #include <yeptris/types.h>
28
+
29
+ #ifdef __cplusplus
30
+ extern "C" {
31
+ #endif
32
+
33
+ /* Event types (ABI-pinned order; mirrors the internal engine 1:1). */
34
+ typedef enum {
35
+ YEPTRIS_EV_STREAM_START = 1,
36
+ YEPTRIS_EV_STREAM_END,
37
+ YEPTRIS_EV_DOCUMENT_START,
38
+ YEPTRIS_EV_DOCUMENT_END,
39
+ YEPTRIS_EV_SEQUENCE_START,
40
+ YEPTRIS_EV_SEQUENCE_END,
41
+ YEPTRIS_EV_MAPPING_START,
42
+ YEPTRIS_EV_MAPPING_END,
43
+ YEPTRIS_EV_SCALAR,
44
+ YEPTRIS_EV_ALIAS,
45
+ } YeptrisEventType;
46
+
47
+ /* Flag bits in YeptrisEventRecord.flags. */
48
+ enum {
49
+ YEPTRIS_EF_FLOW = 1u << 0, /* collection in flow style */
50
+ YEPTRIS_EF_EXPLICIT = 1u << 1, /* document with --- / ... marker */
51
+ YEPTRIS_EF_IMPLICIT = 1u << 2, /* plain scalar, no tag */
52
+ };
53
+
54
+ /* One event, string fields pointing into the owning model's storage. */
55
+ typedef struct {
56
+ YeptrisEventType type;
57
+ int style; /* YeptrisScalarStyle (dom.h) for scalars */
58
+ int flow; /* collection: flow style */
59
+ int explicit_marker; /* document: --- / ... seen */
60
+ int implicit; /* scalar: plain and untagged */
61
+ const char* value; /* scalar content or alias name; NULL if empty */
62
+ size_t value_len;
63
+ const char* anchor; /* node property; NULL when absent */
64
+ size_t anchor_len;
65
+ const char* tag; /* resolved tag; NULL when absent */
66
+ size_t tag_len;
67
+ uint32_t line; /* 1-based node start */
68
+ uint32_t col;
69
+ } YeptrisEvent;
70
+
71
+ /* ---- push ------------------------------------------------------------- */
72
+
73
+ /* Returns nonzero from the callback to abort the parse (surfaced as
74
+ * YEPTRIS_ERROR_PARSE with the last-error channel set). Event strings
75
+ * are valid only during the call. */
76
+ typedef int (*yeptris_event_fn)(void* ctx, const YeptrisEvent* ev);
77
+
78
+ YEPTRIS_API YeptrisStatus yeptris_push_parse(const char* buf, size_t len, yeptris_event_fn on_event,
79
+ void* ctx);
80
+
81
+ /* ---- pull ------------------------------------------------------------- */
82
+
83
+ YEPTRIS_API YeptrisPullParser yeptris_pull_new(const char* buf, size_t len);
84
+
85
+ /* Next event (owned by the puller, valid until the next call), or
86
+ * NULL at stream end or on error — distinguish with yeptris_pull_status. */
87
+ YEPTRIS_API const YeptrisEvent* yeptris_pull_next(YeptrisPullParser pull);
88
+
89
+ /* Bulk cursor (the FFI shape): up to max events per call, strings in
90
+ * the puller's arena valid until the next pull call. Returns count. */
91
+ YEPTRIS_API size_t yeptris_pull_next_batch(YeptrisPullParser pull, YeptrisEvent* out, size_t max);
92
+
93
+ YEPTRIS_API YeptrisStatus yeptris_pull_status(const YeptrisPullParser pull, uint32_t* line,
94
+ uint32_t* col);
95
+ YEPTRIS_API void yeptris_pull_free(YeptrisPullParser pull);
96
+
97
+ /* ---- recorder --------------------------------------------------------- */
98
+
99
+ /* Fixed-size record; strings slice the arena by offset+length. */
100
+ typedef struct {
101
+ uint8_t type; /* YeptrisEventType */
102
+ uint8_t style;
103
+ uint8_t flags; /* YEPTRIS_EF_* */
104
+ uint8_t tag_id; /* resolved implicit tag (YeptrisTagId, resolve.h) —
105
+ * the typing SSOT, so hosts never re-scan. Uses the
106
+ * struct's pad byte: sizeof stays 36 (ABI-pinned) */
107
+ uint32_t line;
108
+ uint32_t col;
109
+ uint32_t value_off;
110
+ uint32_t value_len;
111
+ uint32_t anchor_off;
112
+ uint32_t anchor_len;
113
+ uint32_t tag_off;
114
+ uint32_t tag_len;
115
+ } YeptrisEventRecord;
116
+
117
+ YEPTRIS_API YeptrisRecorder yeptris_recorder_new(void);
118
+
119
+ /* Same, with the implicit-typing schema for the parse (bindings pass
120
+ * compat_11 to reproduce Psych's typing). */
121
+ YEPTRIS_API YeptrisRecorder yeptris_recorder_new_ex(YeptrisSchema schema);
122
+
123
+ /* Accumulates input; the parse advances whenever a complete document
124
+ * has arrived (its closing --- / ... marker line), and final != 0
125
+ * flushes the trailing document. Each feed's records — fixed-size
126
+ * array plus the arena — hold the documents closed by that chunk and
127
+ * are valid until the next feed: drain per chunk. Returns
128
+ * YEPTRIS_OK, YEPTRIS_ERROR_PARSE (terminal; drain what this feed
129
+ * recorded) or YEPTRIS_ERROR_ARG. */
130
+ YEPTRIS_API YeptrisStatus yeptris_recorder_feed(YeptrisRecorder rec, const char* chunk, size_t len,
131
+ int final);
132
+
133
+ /* Bulk accessors: the record array and the string arena. Valid until
134
+ * the next feed; reset at every feed entry (drain per chunk). */
135
+ YEPTRIS_API const YeptrisEventRecord* yeptris_recorder_records(YeptrisRecorder rec, size_t* count);
136
+ YEPTRIS_API const char* yeptris_recorder_arena(YeptrisRecorder rec, size_t* len);
137
+ YEPTRIS_API void yeptris_recorder_free(YeptrisRecorder rec);
138
+
139
+ /* ---- iterparse -------------------------------------------------------- */
140
+
141
+ YEPTRIS_API YeptrisIterparse yeptris_iterparse_new(const char* buf, size_t len);
142
+
143
+ /* The next document's events (owned by the iterator, valid until the
144
+ * next call): *count events, or NULL when the stream is exhausted.
145
+ * STREAM_START / STREAM_END frame the stream exactly once each; the
146
+ * DOCUMENT_* pair frames each yielded slice. */
147
+ YEPTRIS_API const YeptrisEvent* yeptris_iterparse_next(YeptrisIterparse it, size_t* count);
148
+
149
+ YEPTRIS_API YeptrisStatus yeptris_iterparse_status(const YeptrisIterparse it, uint32_t* line,
150
+ uint32_t* col);
151
+ YEPTRIS_API void yeptris_iterparse_free(YeptrisIterparse it);
152
+
153
+ #ifdef __cplusplus
154
+ }
155
+ #endif
156
+
157
+ #endif /* YEPTRIS_EVENTS_H */
@@ -0,0 +1,45 @@
1
+ /* json.h — strict JSON mode (TODO.impl/08C/21).
2
+ *
3
+ * YAML 1.2 strictly contains JSON, but users of json-c-shaped APIs
4
+ * want RFC 8259 semantics exactly: this entry validates the whole
5
+ * input against the strict grammar (scan/json.c is the one truth)
6
+ * before the engine runs, so an accepted input is guaranteed to be
7
+ * pure JSON and every invalid one fails with the violation offset.
8
+ * Charset note: JSON strings allow DEL and forbid raw C0 — the
9
+ * opposite corner of YAML c-printable — so this path validates
10
+ * UTF-8 well-formedness only, never the printable set.
11
+ */
12
+ #ifndef YEPTRIS_JSON_H
13
+ #define YEPTRIS_JSON_H
14
+
15
+ #include <stddef.h>
16
+
17
+ #include <yeptris/api.h>
18
+ #include <yeptris/parse.h>
19
+ #include <yeptris/types.h>
20
+
21
+ #ifdef __cplusplus
22
+ extern "C" {
23
+ #endif
24
+
25
+ /* Parses one strict-JSON document. Same contract as yeptris_parse:
26
+ * a YeptrisDocument handle (queries via the DOM API) or NULL with
27
+ * *st set; violations carry the byte offset via yeptris_last_error. */
28
+ YEPTRIS_API YeptrisDocument yeptris_parse_json(const char* data, size_t len, YeptrisStatus* st);
29
+
30
+ /* Serializes the document's FIRST document as strict JSON (flow
31
+ * collections, JSON escapes, shortest floats, null/true/false words).
32
+ * Returns a malloc'd NUL-terminated buffer (caller frees) with *len
33
+ * (may be NULL) set, or NULL on a NULL document / allocation
34
+ * failure / zero documents. */
35
+ YEPTRIS_API char* yeptris_serialize_json(YeptrisDocument doc, size_t* len);
36
+
37
+ /* The compact variant: no padding spaces (JSON.generate's shape);
38
+ * compact == 0 is byte-identical to yeptris_serialize_json. */
39
+ YEPTRIS_API char* yeptris_serialize_json_ex(YeptrisDocument doc, size_t* len, int compact);
40
+
41
+ #ifdef __cplusplus
42
+ }
43
+ #endif
44
+
45
+ #endif /* YEPTRIS_JSON_H */