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,166 @@
1
+ /* capture.c — the shared capture sink (TODO.impl/12). */
2
+
3
+ #include "capture.h"
4
+
5
+ #include <string.h>
6
+
7
+ #include "../../include/yeptris/events.h"
8
+
9
+ /* The record IS the public ABI shape (events.h pins it). */
10
+ YEPTRIS_CT_ASSERT(sizeof(YeptrisEventRecord) == 44);
11
+
12
+ void yep_rec_init(yep_rec_store* s) {
13
+ s->recs = NULL;
14
+ s->n = 0;
15
+ s->cap = 0;
16
+ s->arena = NULL;
17
+ s->arena_len = 0;
18
+ s->arena_cap = 0;
19
+ }
20
+
21
+ void yep_rec_reset(yep_rec_store* s) {
22
+ s->n = 0;
23
+ s->arena_len = 0;
24
+ }
25
+
26
+ void yep_rec_free(yep_rec_store* s) {
27
+ free(s->recs);
28
+ free(s->arena);
29
+ yep_rec_init(s);
30
+ }
31
+
32
+ /* Returns 0 ok / -1 OOM. On OOM the record is NOT committed (the
33
+ * caller unwinds before s->n++): the old drop-the-string form left
34
+ * value_len set with offset 0, so materialize read whatever string
35
+ * lived at the arena head - or past a NULL arena on first-alloc
36
+ * failure. */
37
+ static int arena_put(yep_rec_store* s, const char* p, uint32_t len, uint32_t* off) {
38
+ if (len == 0 || p == NULL) {
39
+ *off = 0;
40
+ return 0;
41
+ }
42
+ if (s->arena_len + len > s->arena_cap) {
43
+ size_t cap = s->arena_cap ? s->arena_cap : 256;
44
+ while (s->arena_len + len > cap) {
45
+ cap *= 2;
46
+ }
47
+ char* na = realloc(s->arena, cap);
48
+ if (na == NULL) {
49
+ return -1;
50
+ }
51
+ s->arena = na;
52
+ s->arena_cap = cap;
53
+ }
54
+ memcpy(s->arena + s->arena_len, p, len);
55
+ *off = (uint32_t)s->arena_len;
56
+ s->arena_len += len;
57
+ return 0;
58
+ }
59
+
60
+ int yep_rec_on_event(void* ctx, const yep_event* ev) {
61
+ yep_rec_store* s = (yep_rec_store*)ctx;
62
+ if (s->n == s->cap) {
63
+ size_t cap = s->cap ? s->cap * 2 : 64;
64
+ YeptrisEventRecord* nr = realloc(s->recs, cap * sizeof(*nr));
65
+ if (nr == NULL) {
66
+ return -1;
67
+ }
68
+ s->recs = nr;
69
+ s->cap = cap;
70
+ }
71
+ YeptrisEventRecord* r = &s->recs[s->n];
72
+ memset(r, 0, sizeof(*r));
73
+ switch (ev->type) {
74
+ case YEP_EV_STREAM_START:
75
+ r->type = YEPTRIS_EV_STREAM_START;
76
+ break;
77
+ case YEP_EV_STREAM_END:
78
+ r->type = YEPTRIS_EV_STREAM_END;
79
+ break;
80
+ case YEP_EV_DOCUMENT_START:
81
+ r->type = YEPTRIS_EV_DOCUMENT_START;
82
+ if (ev->style == 1) {
83
+ r->flags |= YEPTRIS_EF_EXPLICIT;
84
+ }
85
+ break;
86
+ case YEP_EV_DOCUMENT_END:
87
+ r->type = YEPTRIS_EV_DOCUMENT_END;
88
+ if (ev->style == 1) {
89
+ r->flags |= YEPTRIS_EF_EXPLICIT;
90
+ }
91
+ break;
92
+ case YEP_EV_SEQ_START:
93
+ r->type = YEPTRIS_EV_SEQUENCE_START;
94
+ break;
95
+ case YEP_EV_SEQ_END:
96
+ r->type = YEPTRIS_EV_SEQUENCE_END;
97
+ break;
98
+ case YEP_EV_MAP_START:
99
+ r->type = YEPTRIS_EV_MAPPING_START;
100
+ break;
101
+ case YEP_EV_MAP_END:
102
+ r->type = YEPTRIS_EV_MAPPING_END;
103
+ break;
104
+ case YEP_EV_SCALAR:
105
+ r->type = YEPTRIS_EV_SCALAR;
106
+ r->style = ev->style;
107
+ r->tag_id = ev->tag_id; /* the resolver's verdict, once */
108
+ if (ev->implicit) {
109
+ r->flags |= YEPTRIS_EF_IMPLICIT;
110
+ }
111
+ break;
112
+ case YEP_EV_ALIAS:
113
+ r->type = YEPTRIS_EV_ALIAS;
114
+ break;
115
+ default:
116
+ return 0;
117
+ }
118
+ if (ev->flow) {
119
+ r->flags |= YEPTRIS_EF_FLOW;
120
+ }
121
+ r->line = ev->line;
122
+ r->col = ev->col;
123
+ r->end_line = ev->end_line;
124
+ r->end_col = ev->end_col;
125
+ if (arena_put(s, (const char*)ev->value.p, (uint32_t)ev->value.len, &r->value_off) != 0) {
126
+ return -1;
127
+ }
128
+ r->value_len = (uint32_t)ev->value.len;
129
+ if (arena_put(s, (const char*)ev->anchor.p, (uint32_t)ev->anchor.len, &r->anchor_off) != 0) {
130
+ return -1;
131
+ }
132
+ r->anchor_len = (uint32_t)ev->anchor.len;
133
+ if (arena_put(s, (const char*)ev->tag.p, (uint32_t)ev->tag.len, &r->tag_off) != 0) {
134
+ return -1;
135
+ }
136
+ r->tag_len = (uint32_t)ev->tag.len;
137
+ s->n++;
138
+ return 0;
139
+ }
140
+
141
+ void yep_rec_materialize(const yep_rec_store* s, size_t i, void* out) {
142
+ const YeptrisEventRecord* r = &s->recs[i];
143
+ YeptrisEvent* e = (YeptrisEvent*)out;
144
+ memset(e, 0, sizeof(*e));
145
+ e->type = (YeptrisEventType)r->type;
146
+ e->style = r->style;
147
+ e->flow = (r->flags & YEPTRIS_EF_FLOW) != 0;
148
+ e->explicit_marker = (r->flags & YEPTRIS_EF_EXPLICIT) != 0;
149
+ e->implicit = (r->flags & YEPTRIS_EF_IMPLICIT) != 0;
150
+ e->line = r->line;
151
+ e->col = r->col;
152
+ e->end_line = r->end_line;
153
+ e->end_col = r->end_col;
154
+ if (r->value_len > 0) {
155
+ e->value = s->arena + r->value_off;
156
+ e->value_len = r->value_len;
157
+ }
158
+ if (r->anchor_len > 0) {
159
+ e->anchor = s->arena + r->anchor_off;
160
+ e->anchor_len = r->anchor_len;
161
+ }
162
+ if (r->tag_len > 0) {
163
+ e->tag = s->arena + r->tag_off;
164
+ e->tag_len = r->tag_len;
165
+ }
166
+ }
@@ -0,0 +1,39 @@
1
+ /* capture.h — shared event capture (TODO.impl/12).
2
+ *
3
+ * One sink that appends fixed-size records plus copied strings into an
4
+ * arena. Pull, recorder and iterparse are storage policies over this
5
+ * machinery; push converts directly (no storage). The engine knows
6
+ * nothing about any of them (OCP).
7
+ */
8
+ #ifndef YEP_EVENTS_CAPTURE_H
9
+ #define YEP_EVENTS_CAPTURE_H
10
+
11
+ #include <stdint.h>
12
+ #include <stdlib.h>
13
+
14
+ #include "../../include/yeptris/events.h"
15
+ #include "parse/engine.h"
16
+ #include "parse/events.h"
17
+
18
+ /* Growable records array + string arena; records are the public
19
+ * YeptrisEventRecord layout (the storage SSOT for pull/recorder/
20
+ * iterparse). */
21
+ typedef struct {
22
+ YeptrisEventRecord* recs;
23
+ size_t n, cap;
24
+ char* arena;
25
+ size_t arena_len, arena_cap;
26
+ } yep_rec_store;
27
+
28
+ void yep_rec_init(yep_rec_store* s);
29
+ void yep_rec_reset(yep_rec_store* s);
30
+ void yep_rec_free(yep_rec_store* s);
31
+
32
+ /* The sink: appends one record per event, strings copied to the arena. */
33
+ int yep_rec_on_event(void* ctx, const yep_event* ev);
34
+
35
+ /* Materializes record i into the public event shape; string pointers
36
+ * reference this store's arena. */
37
+ void yep_rec_materialize(const yep_rec_store* s, size_t i, void* out /* YeptrisEvent* */);
38
+
39
+ #endif /* YEP_EVENTS_CAPTURE_H */
@@ -0,0 +1,298 @@
1
+ /* iterparse.c — document-at-a-time iteration (TODO.impl/12).
2
+ *
3
+ * Multi-document streams: each next() runs the engine from the current
4
+ * cursor and captures ONE document's events (records and arena reset
5
+ * per document — memory bounded by the largest document, not the
6
+ * stream). The sink aborts at DOCUMENT_END; the engine's position
7
+ * accessor gives the resume offset. */
8
+
9
+ #include <stdlib.h>
10
+ #include <string.h>
11
+
12
+ #include "../../include/yeptris/events.h"
13
+ #include "../common/simd_text.h"
14
+ #include "../encoding/encoding.h"
15
+ #include "../memory/allocator.h"
16
+ #include "../parse/engine.h"
17
+ #include "capture.h"
18
+
19
+ typedef struct {
20
+ yep_rec_store* store;
21
+ int doc_ends; /* DOCUMENT_END events seen this run */
22
+ int oom; /* the capture failed: yep_rec_on_event returned
23
+ * nonzero — the engine's rc (-2) is shared with the
24
+ * normal document-abort, so without this bit an OOM
25
+ * was indistinguishable from doc-complete and the
26
+ * final event vanished silently (the audit's
27
+ * finding) */
28
+ } yep_iter_sink;
29
+
30
+ static int iter_on_event(void* ctx, const yep_event* ev) {
31
+ yep_iter_sink* s = (yep_iter_sink*)ctx;
32
+ /* stream framing is synthesized by the iterator (the aborted run
33
+ * never reaches STREAM_END); documents are the slice unit */
34
+ if (ev->type == YEP_EV_STREAM_START || ev->type == YEP_EV_STREAM_END) {
35
+ return 0;
36
+ }
37
+ if (ev->type == YEP_EV_DOCUMENT_END) {
38
+ s->doc_ends++;
39
+ }
40
+ int rc = yep_rec_on_event(s->store, ev);
41
+ if (rc != 0) {
42
+ s->oom = 1;
43
+ return rc;
44
+ }
45
+ if (s->doc_ends >= 1) {
46
+ return 1; /* abort: the document is complete */
47
+ }
48
+ return 0;
49
+ }
50
+
51
+ struct yeptris_iterparse {
52
+ const char* buf;
53
+ size_t len;
54
+ size_t cursor;
55
+ int done;
56
+ int gated; /* the encoding front-end ran once: after it, buf
57
+ * indexes the space every engine run's pos lives
58
+ * in (the resume arithmetic requires it) */
59
+ unsigned char* owned; /* UTF-16/32 transcode output (buf moved) */
60
+ char* norm; /* NEL/LS/PS-normalized copy (buf moved) */
61
+ int emitted_stream_start;
62
+ int pending_stream_end; /* deliver a final lone STREAM_END slice */
63
+ YeptrisStatus status;
64
+ uint32_t err_line;
65
+ uint32_t err_col;
66
+ yep_rec_store store;
67
+ size_t next;
68
+ YeptrisEvent* mat;
69
+ size_t mat_cap;
70
+ YeptrisEvent final_end;
71
+ YeptrisEvent final_pair[2];
72
+ };
73
+
74
+ YEPTRIS_API YeptrisIterparse yeptris_iterparse_new(const char* buf, size_t len) {
75
+ if (buf == NULL && len != 0) {
76
+ return NULL;
77
+ }
78
+ struct yeptris_iterparse* it = calloc(1, sizeof(*it));
79
+ if (it == NULL) {
80
+ return NULL;
81
+ }
82
+ it->buf = buf;
83
+ it->len = len;
84
+ yep_rec_init(&it->store);
85
+ return it;
86
+ }
87
+
88
+ YEPTRIS_API const YeptrisEvent* yeptris_iterparse_next(YeptrisIterparse it, size_t* count) {
89
+ if (it == NULL) {
90
+ return NULL;
91
+ }
92
+ for (;;) {
93
+ /* the encoding front-end, ONCE (the yep_engine_run law): the
94
+ * resume arithmetic below adds the engine's pos to it->cursor,
95
+ * and pos lives in the buffer space the RUN parsed — never the
96
+ * raw bytes. The front-end's consumed prefix broke that twice:
97
+ * the BOM it strips (pos cannot see it, so a BOM'd stream
98
+ * re-parsed the previous document's tail), and the UTF-16/32
99
+ * transcode (pos counts UTF-8 bytes, cursor counts raw ones —
100
+ * slices corrupted). The NEL/LS/PS break normalizer inside the
101
+ * run shifts pos the same way, so the gate owns both: encode
102
+ * to UTF-8 and normalize here, move buf, and the spaces agree. */
103
+ if (!it->gated) {
104
+ it->gated = 1;
105
+ const yep_allocator* sys = yep_system_allocator();
106
+ yep_encoding enc = YEP_ENC_UNKNOWN;
107
+ size_t bom = yep_bom_sniff((const unsigned char*)it->buf, it->len, &enc);
108
+ if (enc == YEP_ENC_UTF16LE || enc == YEP_ENC_UTF16BE || enc == YEP_ENC_UTF32LE ||
109
+ enc == YEP_ENC_UTF32BE) {
110
+ size_t tlen = 0;
111
+ size_t terr = 0;
112
+ int rc = yep_transcode_to_utf8(sys, enc, (const unsigned char*)it->buf + bom,
113
+ it->len - bom, &it->owned, &tlen, &terr);
114
+ if (rc != 0) {
115
+ it->done = 1;
116
+ it->status = YEPTRIS_ERROR_ENCODING;
117
+ it->err_line = 1;
118
+ it->err_col = 1;
119
+ return NULL;
120
+ }
121
+ /* the copy IS the post-gate buffer: it opens at the
122
+ * first content byte (the mark never entered it), so
123
+ * cursor restarts at zero — keeping `bom` here skipped
124
+ * the copy's first unit and corrupted the first slice */
125
+ it->buf = (const char*)it->owned;
126
+ it->len = tlen;
127
+ it->cursor = 0;
128
+ } else {
129
+ it->cursor = bom; /* the mark is the front-end's prefix */
130
+ }
131
+ size_t nlen = 0;
132
+ int kept_raw = 0;
133
+ char* norm = yep_engine_normalize_breaks(sys, it->buf + it->cursor,
134
+ it->len - it->cursor, &nlen, &kept_raw);
135
+ if (norm != NULL) {
136
+ it->norm = norm;
137
+ it->buf = norm;
138
+ it->len = nlen;
139
+ it->cursor = 0; /* the copy starts at its own zero */
140
+ }
141
+ }
142
+ if (it->done && it->pending_stream_end && it->next >= it->store.n) {
143
+ it->pending_stream_end = 0;
144
+ if (!it->emitted_stream_start) {
145
+ /* a stream with zero documents still frames +STR */
146
+ it->emitted_stream_start = 1;
147
+ it->final_pair[0].type = YEPTRIS_EV_STREAM_START;
148
+ it->final_pair[1].type = YEPTRIS_EV_STREAM_END;
149
+ if (count != NULL) {
150
+ *count = 2;
151
+ }
152
+ return it->final_pair;
153
+ }
154
+ it->final_end.type = YEPTRIS_EV_STREAM_END;
155
+ if (count != NULL) {
156
+ *count = 1;
157
+ }
158
+ return &it->final_end;
159
+ }
160
+ if (it->next < it->store.n) {
161
+ /* materialize the whole captured slice (one document) */
162
+ size_t n = it->store.n;
163
+ if (n + 1 > it->mat_cap) {
164
+ YeptrisEvent* nm = realloc(it->mat, (n + 1) * sizeof(*nm));
165
+ if (nm == NULL) {
166
+ it->done = 1;
167
+ it->status = YEPTRIS_ERROR_MEMORY;
168
+ return NULL;
169
+ }
170
+ it->mat = nm;
171
+ it->mat_cap = n + 1;
172
+ }
173
+ for (size_t i = 0; i < n; i++) {
174
+ yep_rec_materialize(&it->store, i, &it->mat[i]);
175
+ }
176
+ size_t base = 0;
177
+ if (!it->emitted_stream_start) {
178
+ it->emitted_stream_start = 1;
179
+ /* prepend the synthesized STREAM_START */
180
+ memmove(&it->mat[1], it->mat, n * sizeof(*it->mat));
181
+ memset(&it->mat[0], 0, sizeof(it->mat[0]));
182
+ it->mat[0].type = YEPTRIS_EV_STREAM_START;
183
+ base = 1;
184
+ }
185
+ it->next = it->store.n; /* consumed */
186
+ if (count != NULL) {
187
+ *count = n + base;
188
+ }
189
+ return it->mat;
190
+ }
191
+ if (it->done) {
192
+ return NULL;
193
+ }
194
+ /* capture the next document: abort the run at its DOCUMENT_END;
195
+ * the marker line stays unconsumed and doubles as the next
196
+ * document's start on the resumed run */
197
+ yep_rec_reset(&it->store);
198
+ it->next = 0;
199
+ yep_iter_sink s = {&it->store, 0, 0};
200
+ yep_engine* eng = yep_engine_create(yep_system_allocator());
201
+ if (eng == NULL) {
202
+ it->done = 1;
203
+ it->status = YEPTRIS_ERROR_MEMORY;
204
+ return NULL;
205
+ }
206
+ yep_sink sink = {.on_event = iter_on_event,
207
+ .ctx = &s,
208
+ .on_flow_build = NULL,
209
+ .on_flow_commit = NULL,
210
+ .on_flow_rollback = NULL,
211
+ .on_block_pair = NULL,
212
+ .on_block_open = NULL,
213
+ .on_block_item = NULL};
214
+ yep_text_stats pst;
215
+ yep_text_active()->scan_stats(it->buf + it->cursor, it->len - it->cursor, &pst);
216
+ yep_engine_prepare(eng, &pst);
217
+ int rc = yep_engine_run(eng, it->buf + it->cursor, it->len - it->cursor, &sink);
218
+ size_t pos = yep_engine_pos(eng);
219
+ /* the error slot lives inside the engine and destroy munmaps it
220
+ * (glibc serves the ~260KB engine with mmap): copy the verdict
221
+ * out BEFORE the free */
222
+ yep_err_code err_code = YEP_ERR_NONE;
223
+ uint32_t err_line = 0, err_col = 0;
224
+ {
225
+ const yep_error* err = yep_engine_error(eng);
226
+ if (err != NULL) {
227
+ err_code = err->code;
228
+ err_line = err->line;
229
+ err_col = err->col;
230
+ }
231
+ }
232
+ yep_engine_destroy(eng);
233
+ /* A failed run with a SET channel is a parse-class error and the
234
+ * CODE picks the public status; a failed run with a CLEAN
235
+ * channel is the capture sink dying — memory, never a parse
236
+ * error, and never a silent stream end (the old code fell into
237
+ * the doc-complete arm on rc == -2 and the final event
238
+ * vanished). The abort (rc == -2 without s.oom) stays the
239
+ * normal per-document completion. */
240
+ int failed = rc == -1 || s.oom;
241
+ if (failed) {
242
+ it->done = 1;
243
+ if (err_code != YEP_ERR_NONE) {
244
+ it->err_line = err_line;
245
+ it->err_col = err_col;
246
+ it->status = err_code == YEP_ERR_MEMORY ? YEPTRIS_ERROR_MEMORY
247
+ : err_code == YEP_ERR_ENCODING ? YEPTRIS_ERROR_ENCODING
248
+ : YEPTRIS_ERROR_PARSE;
249
+ } else {
250
+ it->status = YEPTRIS_ERROR_MEMORY;
251
+ }
252
+ if (it->store.n == 0) {
253
+ if (!it->emitted_stream_start) {
254
+ /* the engine emitted +STR before failing: match it */
255
+ it->emitted_stream_start = 1;
256
+ it->final_end.type = YEPTRIS_EV_STREAM_START;
257
+ if (count != NULL) {
258
+ *count = 1;
259
+ }
260
+ return &it->final_end;
261
+ }
262
+ return NULL;
263
+ }
264
+ continue; /* surface the partial slice, then stop */
265
+ }
266
+ it->cursor += pos;
267
+ if (rc == 0 || s.doc_ends == 0) {
268
+ it->done = 1; /* natural end or blank tail: stream is over */
269
+ it->pending_stream_end = 1;
270
+ }
271
+ }
272
+ }
273
+
274
+ YEPTRIS_API YeptrisStatus yeptris_iterparse_status(const YeptrisIterparse it, uint32_t* line,
275
+ uint32_t* col) {
276
+ if (it == NULL) {
277
+ return YEPTRIS_ERROR_ARG;
278
+ }
279
+ if (line != NULL) {
280
+ *line = it->err_line;
281
+ }
282
+ if (col != NULL) {
283
+ *col = it->err_col;
284
+ }
285
+ return it->status;
286
+ }
287
+
288
+ YEPTRIS_API void yeptris_iterparse_free(YeptrisIterparse it) {
289
+ if (it == NULL) {
290
+ return;
291
+ }
292
+ const yep_allocator* sys = yep_system_allocator();
293
+ yep_free(sys, it->owned);
294
+ yep_free(sys, it->norm);
295
+ yep_rec_free(&it->store);
296
+ free(it->mat);
297
+ free(it);
298
+ }
@@ -0,0 +1,117 @@
1
+ /* pull.c — StAX-style cursor (TODO.impl/12).
2
+ *
3
+ * Zero C->host dispatch: the run completes into the shared capture,
4
+ * then events are handed out one (or a batch) at a time. Event strings
5
+ * reference the puller's arena and are valid until the next call. */
6
+
7
+ #include <stdlib.h>
8
+ #include <string.h>
9
+
10
+ #include "../../include/yeptris/events.h"
11
+ #include "../common/simd_text.h"
12
+ #include "../parse/engine.h"
13
+ #include "capture.h"
14
+
15
+ struct yeptris_pull {
16
+ yep_rec_store store;
17
+ size_t next;
18
+ YeptrisStatus status;
19
+ uint32_t err_line;
20
+ uint32_t err_col;
21
+ YeptrisEvent current;
22
+ };
23
+
24
+ YEPTRIS_API YeptrisPullParser yeptris_pull_new(const char* buf, size_t len) {
25
+ if (buf == NULL && len != 0) {
26
+ return NULL;
27
+ }
28
+ struct yeptris_pull* p = calloc(1, sizeof(*p));
29
+ if (p == NULL) {
30
+ return NULL;
31
+ }
32
+ yep_rec_init(&p->store);
33
+ yep_engine* eng = yep_engine_create(yep_system_allocator());
34
+ if (eng == NULL) {
35
+ yeptris_pull_free(p);
36
+ return NULL;
37
+ }
38
+ yep_sink sink = {.on_event = yep_rec_on_event,
39
+ .ctx = &p->store,
40
+ .on_flow_build = NULL,
41
+ .on_flow_commit = NULL,
42
+ .on_block_item = NULL};
43
+ yep_text_stats pst;
44
+ yep_text_active()->scan_stats(buf, len, &pst);
45
+ yep_engine_prepare(eng, &pst);
46
+ int rc = yep_engine_run(eng, buf, len, &sink);
47
+ /* the error slot lives INSIDE the engine, and the engine is a
48
+ * ~260KB allocation glibc serves with mmap — destroy munmaps it,
49
+ * so the slot's verdict must be copied out BEFORE destroy (the
50
+ * round-5 CI segfaulted reading err->code after the free). */
51
+ yep_err_code err_code = YEP_ERR_NONE;
52
+ uint32_t err_line = 0, err_col = 0;
53
+ {
54
+ const yep_error* err = yep_engine_error(eng);
55
+ if (err != NULL) {
56
+ err_code = err->code;
57
+ err_line = err->line;
58
+ err_col = err->col;
59
+ }
60
+ }
61
+ yep_engine_destroy(eng);
62
+ /* the error CODE decides the public status — the parse route's law
63
+ * (the recorder twin carries the full comment). A clean channel
64
+ * under a failed run is the capture sink failing: memory. */
65
+ if (rc != 0 && err_code != YEP_ERR_NONE) {
66
+ p->err_line = err_line;
67
+ p->err_col = err_col;
68
+ p->status = err_code == YEP_ERR_MEMORY ? YEPTRIS_ERROR_MEMORY
69
+ : err_code == YEP_ERR_ENCODING ? YEPTRIS_ERROR_ENCODING
70
+ : YEPTRIS_ERROR_PARSE;
71
+ } else {
72
+ p->status = rc == 0 ? YEPTRIS_OK : YEPTRIS_ERROR_MEMORY;
73
+ }
74
+ return p;
75
+ }
76
+
77
+ YEPTRIS_API const YeptrisEvent* yeptris_pull_next(YeptrisPullParser pull) {
78
+ if (pull == NULL || pull->next >= pull->store.n) {
79
+ return NULL;
80
+ }
81
+ yep_rec_materialize(&pull->store, pull->next++, &pull->current);
82
+ return &pull->current;
83
+ }
84
+
85
+ YEPTRIS_API size_t yeptris_pull_next_batch(YeptrisPullParser pull, YeptrisEvent* out, size_t max) {
86
+ if (pull == NULL || out == NULL) {
87
+ return 0;
88
+ }
89
+ size_t n = 0;
90
+ while (n < max && pull->next < pull->store.n) {
91
+ yep_rec_materialize(&pull->store, pull->next++, &out[n]);
92
+ n++;
93
+ }
94
+ return n;
95
+ }
96
+
97
+ YEPTRIS_API YeptrisStatus yeptris_pull_status(const YeptrisPullParser pull, uint32_t* line,
98
+ uint32_t* col) {
99
+ if (pull == NULL) {
100
+ return YEPTRIS_ERROR_ARG;
101
+ }
102
+ if (line != NULL) {
103
+ *line = pull->err_line;
104
+ }
105
+ if (col != NULL) {
106
+ *col = pull->err_col;
107
+ }
108
+ return pull->status;
109
+ }
110
+
111
+ YEPTRIS_API void yeptris_pull_free(YeptrisPullParser pull) {
112
+ if (pull == NULL) {
113
+ return;
114
+ }
115
+ yep_rec_free(&pull->store);
116
+ free(pull);
117
+ }