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.
- checksums.yaml +7 -0
- data/README.adoc +141 -0
- data/ext/build_windows_native.rb +41 -0
- data/ext/libyeptris/extconf.rb +57 -0
- data/ext/yeptris_native/cbor_ruby.c +193 -0
- data/ext/yeptris_native/extconf.rb +47 -0
- data/ext/yeptris_native/json_ruby.c +354 -0
- data/ext/yeptris_native/yeptris_native.c +497 -0
- data/lib/yeptris/cbor.rb +130 -0
- data/lib/yeptris/document.rb +255 -0
- data/lib/yeptris/ffi.rb +426 -0
- data/lib/yeptris/json/descriptor.rb +266 -0
- data/lib/yeptris/json.rb +394 -0
- data/lib/yeptris/materializer.rb +354 -0
- data/lib/yeptris/native-3.4.so +0 -0
- data/lib/yeptris/node.rb +453 -0
- data/lib/yeptris/psych/class_loader.rb +24 -0
- data/lib/yeptris/psych/coder_shim.rb +55 -0
- data/lib/yeptris/psych/drop_in.rb +63 -0
- data/lib/yeptris/psych/encodable.rb +14 -0
- data/lib/yeptris/psych/handler.rb +90 -0
- data/lib/yeptris/psych/parser.rb +105 -0
- data/lib/yeptris/psych/scalar_scanner.rb +149 -0
- data/lib/yeptris/psych/visitors.rb +545 -0
- data/lib/yeptris/psych.rb +622 -0
- data/lib/yeptris/schema.rb +253 -0
- data/lib/yeptris/valueml.rb +455 -0
- data/lib/yeptris/yaml/descriptor.rb +56 -0
- data/lib/yeptris/yaml.rb +422 -0
- data/lib/yeptris.rb +113 -0
- data/libyeptris.so +0 -0
- data/vendor/libyeptris/CMakeLists.txt +254 -0
- data/vendor/libyeptris/cmake/yeptris-config.cmake.in +5 -0
- data/vendor/libyeptris/cmake/yeptris.pc.in +11 -0
- data/vendor/libyeptris/src/CMakeLists.txt +167 -0
- data/vendor/libyeptris/src/include/yeptris/api.h +32 -0
- data/vendor/libyeptris/src/include/yeptris/cbor.h +101 -0
- data/vendor/libyeptris/src/include/yeptris/dom.h +190 -0
- data/vendor/libyeptris/src/include/yeptris/emit.h +81 -0
- data/vendor/libyeptris/src/include/yeptris/error.h +41 -0
- data/vendor/libyeptris/src/include/yeptris/events.h +157 -0
- data/vendor/libyeptris/src/include/yeptris/json.h +45 -0
- data/vendor/libyeptris/src/include/yeptris/json.hpp +258 -0
- data/vendor/libyeptris/src/include/yeptris/jsonc_compat.h +115 -0
- data/vendor/libyeptris/src/include/yeptris/marshal.h +52 -0
- data/vendor/libyeptris/src/include/yeptris/parse.h +48 -0
- data/vendor/libyeptris/src/include/yeptris/plan.h +100 -0
- data/vendor/libyeptris/src/include/yeptris/resolve.h +71 -0
- data/vendor/libyeptris/src/include/yeptris/schema.h +121 -0
- data/vendor/libyeptris/src/include/yeptris/tape.h +123 -0
- data/vendor/libyeptris/src/include/yeptris/types.h +38 -0
- data/vendor/libyeptris/src/include/yeptris/values.h +102 -0
- data/vendor/libyeptris/src/include/yeptris/version.h.in +29 -0
- data/vendor/libyeptris/src/include/yeptris/visit.h +77 -0
- data/vendor/libyeptris/src/include/yeptris/yajl_compat.h +135 -0
- data/vendor/libyeptris/src/include/yeptris.h +23 -0
- data/vendor/libyeptris/src/yeptris/build.c +376 -0
- data/vendor/libyeptris/src/yeptris/cbor/cbor.h +25 -0
- data/vendor/libyeptris/src/yeptris/cbor/decode.c +981 -0
- data/vendor/libyeptris/src/yeptris/cbor/encode.c +835 -0
- data/vendor/libyeptris/src/yeptris/cbor/sink.h +58 -0
- data/vendor/libyeptris/src/yeptris/common/chartype.c +41 -0
- data/vendor/libyeptris/src/yeptris/common/chartype.h +77 -0
- data/vendor/libyeptris/src/yeptris/common/cpu.c +81 -0
- data/vendor/libyeptris/src/yeptris/common/cpu.h +40 -0
- data/vendor/libyeptris/src/yeptris/common/error.c +65 -0
- data/vendor/libyeptris/src/yeptris/common/error.h +79 -0
- data/vendor/libyeptris/src/yeptris/common/mutex.h +45 -0
- data/vendor/libyeptris/src/yeptris/common/nametab.c +275 -0
- data/vendor/libyeptris/src/yeptris/common/nametab.h +68 -0
- data/vendor/libyeptris/src/yeptris/common/port.h +74 -0
- data/vendor/libyeptris/src/yeptris/common/simd_text.c +49 -0
- data/vendor/libyeptris/src/yeptris/common/simd_text.h +295 -0
- data/vendor/libyeptris/src/yeptris/common/simd_text_avx2.c +534 -0
- data/vendor/libyeptris/src/yeptris/common/simd_text_neon.c +662 -0
- data/vendor/libyeptris/src/yeptris/common/simd_text_scalar.c +298 -0
- data/vendor/libyeptris/src/yeptris/common/string_view.c +34 -0
- data/vendor/libyeptris/src/yeptris/common/string_view.h +93 -0
- data/vendor/libyeptris/src/yeptris/doc.h +56 -0
- data/vendor/libyeptris/src/yeptris/dom/dom.c +1192 -0
- data/vendor/libyeptris/src/yeptris/dom/dom.h +312 -0
- data/vendor/libyeptris/src/yeptris/dom/hpool.c +107 -0
- data/vendor/libyeptris/src/yeptris/dom/mapindex.c +173 -0
- data/vendor/libyeptris/src/yeptris/dom/mapindex.h +61 -0
- data/vendor/libyeptris/src/yeptris/dom/mutate.c +431 -0
- data/vendor/libyeptris/src/yeptris/emit/emit.c +434 -0
- data/vendor/libyeptris/src/yeptris/emit/float/api.h +38 -0
- data/vendor/libyeptris/src/yeptris/emit/float/dragon.c +405 -0
- data/vendor/libyeptris/src/yeptris/emit/float/floatint.h +231 -0
- data/vendor/libyeptris/src/yeptris/emit/float/print.c +396 -0
- data/vendor/libyeptris/src/yeptris/emit/style.c +81 -0
- data/vendor/libyeptris/src/yeptris/emit/style.h +24 -0
- data/vendor/libyeptris/src/yeptris/emit/writer.c +816 -0
- data/vendor/libyeptris/src/yeptris/emit/writer.h +76 -0
- data/vendor/libyeptris/src/yeptris/encoding/bom.c +31 -0
- data/vendor/libyeptris/src/yeptris/encoding/encoding.h +63 -0
- data/vendor/libyeptris/src/yeptris/encoding/transcode.c +148 -0
- data/vendor/libyeptris/src/yeptris/encoding/utf8_validate.c +178 -0
- data/vendor/libyeptris/src/yeptris/events/capture.c +150 -0
- data/vendor/libyeptris/src/yeptris/events/capture.h +39 -0
- data/vendor/libyeptris/src/yeptris/events/iterparse.c +208 -0
- data/vendor/libyeptris/src/yeptris/events/pull.c +97 -0
- data/vendor/libyeptris/src/yeptris/events/push.c +104 -0
- data/vendor/libyeptris/src/yeptris/events/recorder.c +107 -0
- data/vendor/libyeptris/src/yeptris/events/values.c +527 -0
- data/vendor/libyeptris/src/yeptris/events/values_priv.h +51 -0
- data/vendor/libyeptris/src/yeptris/events/yaml_compat.c +86 -0
- data/vendor/libyeptris/src/yeptris/events/yaml_compat.h +90 -0
- data/vendor/libyeptris/src/yeptris/jsonapi/jsonc_compat.c +687 -0
- data/vendor/libyeptris/src/yeptris/jsonapi/yajl_compat.c +728 -0
- data/vendor/libyeptris/src/yeptris/marshal.c +782 -0
- data/vendor/libyeptris/src/yeptris/memory/allocator.c +20 -0
- data/vendor/libyeptris/src/yeptris/memory/allocator.h +43 -0
- data/vendor/libyeptris/src/yeptris/memory/arena.c +134 -0
- data/vendor/libyeptris/src/yeptris/memory/arena.h +52 -0
- data/vendor/libyeptris/src/yeptris/memory/pool.c +122 -0
- data/vendor/libyeptris/src/yeptris/memory/pool.h +36 -0
- data/vendor/libyeptris/src/yeptris/parse/engine.c +3698 -0
- data/vendor/libyeptris/src/yeptris/parse/engine.h +65 -0
- data/vendor/libyeptris/src/yeptris/parse/events.h +124 -0
- data/vendor/libyeptris/src/yeptris/parse/numbers.c +349 -0
- data/vendor/libyeptris/src/yeptris/parse/numbers.h +33 -0
- data/vendor/libyeptris/src/yeptris/parse/scalars.c +416 -0
- data/vendor/libyeptris/src/yeptris/parse/scalars.h +75 -0
- data/vendor/libyeptris/src/yeptris/parse.c +737 -0
- data/vendor/libyeptris/src/yeptris/plan.c +824 -0
- data/vendor/libyeptris/src/yeptris/resolve/compat11.c +334 -0
- data/vendor/libyeptris/src/yeptris/resolve/core12.c +143 -0
- data/vendor/libyeptris/src/yeptris/resolve/resolver.h +56 -0
- data/vendor/libyeptris/src/yeptris/resolve/tags.c +58 -0
- data/vendor/libyeptris/src/yeptris/scan/json.c +792 -0
- data/vendor/libyeptris/src/yeptris/scan/json.h +109 -0
- data/vendor/libyeptris/src/yeptris/scan/scan.c +463 -0
- data/vendor/libyeptris/src/yeptris/scan/scan.h +150 -0
- data/vendor/libyeptris/src/yeptris/schema.c +308 -0
- data/vendor/libyeptris/src/yeptris/tape.c +1308 -0
- data/vendor/libyeptris/src/yeptris/tape_in.h +19 -0
- data/vendor/libyeptris/src/yeptris/version.c +7 -0
- data/vendor/libyeptris/src/yeptris/visit/dom_visit.c +115 -0
- data/vendor/libyeptris/src/yeptris/visit/json_visit.c +293 -0
- data/vendor/libyeptris/src/yeptris/visit/yaml_visit.c +127 -0
- metadata +199 -0
|
@@ -0,0 +1,208 @@
|
|
|
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 "../parse/engine.h"
|
|
15
|
+
#include "capture.h"
|
|
16
|
+
|
|
17
|
+
typedef struct {
|
|
18
|
+
yep_rec_store* store;
|
|
19
|
+
int doc_ends; /* DOCUMENT_END events seen this run */
|
|
20
|
+
} yep_iter_sink;
|
|
21
|
+
|
|
22
|
+
static int iter_on_event(void* ctx, const yep_event* ev) {
|
|
23
|
+
yep_iter_sink* s = (yep_iter_sink*)ctx;
|
|
24
|
+
/* stream framing is synthesized by the iterator (the aborted run
|
|
25
|
+
* never reaches STREAM_END); documents are the slice unit */
|
|
26
|
+
if (ev->type == YEP_EV_STREAM_START || ev->type == YEP_EV_STREAM_END) {
|
|
27
|
+
return 0;
|
|
28
|
+
}
|
|
29
|
+
if (ev->type == YEP_EV_DOCUMENT_END) {
|
|
30
|
+
s->doc_ends++;
|
|
31
|
+
}
|
|
32
|
+
int rc = yep_rec_on_event(s->store, ev);
|
|
33
|
+
if (rc != 0) {
|
|
34
|
+
return rc;
|
|
35
|
+
}
|
|
36
|
+
if (s->doc_ends >= 1) {
|
|
37
|
+
return 1; /* abort: the document is complete */
|
|
38
|
+
}
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
struct yeptris_iterparse {
|
|
43
|
+
const char* buf;
|
|
44
|
+
size_t len;
|
|
45
|
+
size_t cursor;
|
|
46
|
+
int done;
|
|
47
|
+
int emitted_stream_start;
|
|
48
|
+
int pending_stream_end; /* deliver a final lone STREAM_END slice */
|
|
49
|
+
YeptrisStatus status;
|
|
50
|
+
uint32_t err_line;
|
|
51
|
+
uint32_t err_col;
|
|
52
|
+
yep_rec_store store;
|
|
53
|
+
size_t next;
|
|
54
|
+
YeptrisEvent* mat;
|
|
55
|
+
size_t mat_cap;
|
|
56
|
+
YeptrisEvent final_end;
|
|
57
|
+
YeptrisEvent final_pair[2];
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
YEPTRIS_API YeptrisIterparse yeptris_iterparse_new(const char* buf, size_t len) {
|
|
61
|
+
if (buf == NULL && len != 0) {
|
|
62
|
+
return NULL;
|
|
63
|
+
}
|
|
64
|
+
struct yeptris_iterparse* it = calloc(1, sizeof(*it));
|
|
65
|
+
if (it == NULL) {
|
|
66
|
+
return NULL;
|
|
67
|
+
}
|
|
68
|
+
it->buf = buf;
|
|
69
|
+
it->len = len;
|
|
70
|
+
yep_rec_init(&it->store);
|
|
71
|
+
return it;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
YEPTRIS_API const YeptrisEvent* yeptris_iterparse_next(YeptrisIterparse it, size_t* count) {
|
|
75
|
+
if (it == NULL) {
|
|
76
|
+
return NULL;
|
|
77
|
+
}
|
|
78
|
+
for (;;) {
|
|
79
|
+
if (it->done && it->pending_stream_end && it->next >= it->store.n) {
|
|
80
|
+
it->pending_stream_end = 0;
|
|
81
|
+
if (!it->emitted_stream_start) {
|
|
82
|
+
/* a stream with zero documents still frames +STR */
|
|
83
|
+
it->emitted_stream_start = 1;
|
|
84
|
+
it->final_pair[0].type = YEPTRIS_EV_STREAM_START;
|
|
85
|
+
it->final_pair[1].type = YEPTRIS_EV_STREAM_END;
|
|
86
|
+
if (count != NULL) {
|
|
87
|
+
*count = 2;
|
|
88
|
+
}
|
|
89
|
+
return it->final_pair;
|
|
90
|
+
}
|
|
91
|
+
it->final_end.type = YEPTRIS_EV_STREAM_END;
|
|
92
|
+
if (count != NULL) {
|
|
93
|
+
*count = 1;
|
|
94
|
+
}
|
|
95
|
+
return &it->final_end;
|
|
96
|
+
}
|
|
97
|
+
if (it->next < it->store.n) {
|
|
98
|
+
/* materialize the whole captured slice (one document) */
|
|
99
|
+
size_t n = it->store.n;
|
|
100
|
+
if (n + 1 > it->mat_cap) {
|
|
101
|
+
YeptrisEvent* nm = realloc(it->mat, (n + 1) * sizeof(*nm));
|
|
102
|
+
if (nm == NULL) {
|
|
103
|
+
it->done = 1;
|
|
104
|
+
it->status = YEPTRIS_ERROR_MEMORY;
|
|
105
|
+
return NULL;
|
|
106
|
+
}
|
|
107
|
+
it->mat = nm;
|
|
108
|
+
it->mat_cap = n + 1;
|
|
109
|
+
}
|
|
110
|
+
for (size_t i = 0; i < n; i++) {
|
|
111
|
+
yep_rec_materialize(&it->store, i, &it->mat[i]);
|
|
112
|
+
}
|
|
113
|
+
size_t base = 0;
|
|
114
|
+
if (!it->emitted_stream_start) {
|
|
115
|
+
it->emitted_stream_start = 1;
|
|
116
|
+
/* prepend the synthesized STREAM_START */
|
|
117
|
+
memmove(&it->mat[1], it->mat, n * sizeof(*it->mat));
|
|
118
|
+
memset(&it->mat[0], 0, sizeof(it->mat[0]));
|
|
119
|
+
it->mat[0].type = YEPTRIS_EV_STREAM_START;
|
|
120
|
+
base = 1;
|
|
121
|
+
}
|
|
122
|
+
it->next = it->store.n; /* consumed */
|
|
123
|
+
if (count != NULL) {
|
|
124
|
+
*count = n + base;
|
|
125
|
+
}
|
|
126
|
+
return it->mat;
|
|
127
|
+
}
|
|
128
|
+
if (it->done) {
|
|
129
|
+
return NULL;
|
|
130
|
+
}
|
|
131
|
+
/* capture the next document: abort the run at its DOCUMENT_END;
|
|
132
|
+
* the marker line stays unconsumed and doubles as the next
|
|
133
|
+
* document's start on the resumed run */
|
|
134
|
+
yep_rec_reset(&it->store);
|
|
135
|
+
it->next = 0;
|
|
136
|
+
yep_iter_sink s = {&it->store, 0};
|
|
137
|
+
yep_engine* eng = yep_engine_create(yep_system_allocator());
|
|
138
|
+
if (eng == NULL) {
|
|
139
|
+
it->done = 1;
|
|
140
|
+
it->status = YEPTRIS_ERROR_MEMORY;
|
|
141
|
+
return NULL;
|
|
142
|
+
}
|
|
143
|
+
yep_sink sink = {.on_event = iter_on_event,
|
|
144
|
+
.ctx = &s,
|
|
145
|
+
.on_flow_build = NULL,
|
|
146
|
+
.on_flow_commit = NULL,
|
|
147
|
+
.on_flow_rollback = NULL,
|
|
148
|
+
.on_block_pair = NULL,
|
|
149
|
+
.on_block_open = NULL,
|
|
150
|
+
.on_block_item = NULL};
|
|
151
|
+
yep_text_stats pst;
|
|
152
|
+
yep_text_active()->scan_stats(it->buf + it->cursor, it->len - it->cursor, &pst);
|
|
153
|
+
yep_engine_prepare(eng, &pst);
|
|
154
|
+
int rc = yep_engine_run(eng, it->buf + it->cursor, it->len - it->cursor, &sink);
|
|
155
|
+
size_t pos = yep_engine_pos(eng);
|
|
156
|
+
const yep_error* err = yep_engine_error(eng);
|
|
157
|
+
if (rc == -1 && err != NULL) {
|
|
158
|
+
it->err_line = err->line;
|
|
159
|
+
it->err_col = err->col;
|
|
160
|
+
}
|
|
161
|
+
yep_engine_destroy(eng);
|
|
162
|
+
if (rc == -1) {
|
|
163
|
+
it->done = 1;
|
|
164
|
+
it->status = YEPTRIS_ERROR_PARSE;
|
|
165
|
+
if (it->store.n == 0) {
|
|
166
|
+
if (!it->emitted_stream_start) {
|
|
167
|
+
/* the engine emitted +STR before failing: match it */
|
|
168
|
+
it->emitted_stream_start = 1;
|
|
169
|
+
it->final_end.type = YEPTRIS_EV_STREAM_START;
|
|
170
|
+
if (count != NULL) {
|
|
171
|
+
*count = 1;
|
|
172
|
+
}
|
|
173
|
+
return &it->final_end;
|
|
174
|
+
}
|
|
175
|
+
return NULL;
|
|
176
|
+
}
|
|
177
|
+
continue; /* surface the partial slice, then stop */
|
|
178
|
+
}
|
|
179
|
+
it->cursor += pos;
|
|
180
|
+
if (rc == 0 || s.doc_ends == 0) {
|
|
181
|
+
it->done = 1; /* natural end or blank tail: stream is over */
|
|
182
|
+
it->pending_stream_end = 1;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
YEPTRIS_API YeptrisStatus yeptris_iterparse_status(const YeptrisIterparse it, uint32_t* line,
|
|
188
|
+
uint32_t* col) {
|
|
189
|
+
if (it == NULL) {
|
|
190
|
+
return YEPTRIS_ERROR_ARG;
|
|
191
|
+
}
|
|
192
|
+
if (line != NULL) {
|
|
193
|
+
*line = it->err_line;
|
|
194
|
+
}
|
|
195
|
+
if (col != NULL) {
|
|
196
|
+
*col = it->err_col;
|
|
197
|
+
}
|
|
198
|
+
return it->status;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
YEPTRIS_API void yeptris_iterparse_free(YeptrisIterparse it) {
|
|
202
|
+
if (it == NULL) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
yep_rec_free(&it->store);
|
|
206
|
+
free(it->mat);
|
|
207
|
+
free(it);
|
|
208
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
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
|
+
const yep_error* err = yep_engine_error(eng);
|
|
48
|
+
if (err != NULL && rc != 0) {
|
|
49
|
+
p->err_line = err->line;
|
|
50
|
+
p->err_col = err->col;
|
|
51
|
+
}
|
|
52
|
+
yep_engine_destroy(eng);
|
|
53
|
+
p->status = rc == 0 ? YEPTRIS_OK : YEPTRIS_ERROR_PARSE;
|
|
54
|
+
return p;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
YEPTRIS_API const YeptrisEvent* yeptris_pull_next(YeptrisPullParser pull) {
|
|
58
|
+
if (pull == NULL || pull->next >= pull->store.n) {
|
|
59
|
+
return NULL;
|
|
60
|
+
}
|
|
61
|
+
yep_rec_materialize(&pull->store, pull->next++, &pull->current);
|
|
62
|
+
return &pull->current;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
YEPTRIS_API size_t yeptris_pull_next_batch(YeptrisPullParser pull, YeptrisEvent* out, size_t max) {
|
|
66
|
+
if (pull == NULL || out == NULL) {
|
|
67
|
+
return 0;
|
|
68
|
+
}
|
|
69
|
+
size_t n = 0;
|
|
70
|
+
while (n < max && pull->next < pull->store.n) {
|
|
71
|
+
yep_rec_materialize(&pull->store, pull->next++, &out[n]);
|
|
72
|
+
n++;
|
|
73
|
+
}
|
|
74
|
+
return n;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
YEPTRIS_API YeptrisStatus yeptris_pull_status(const YeptrisPullParser pull, uint32_t* line,
|
|
78
|
+
uint32_t* col) {
|
|
79
|
+
if (pull == NULL) {
|
|
80
|
+
return YEPTRIS_ERROR_ARG;
|
|
81
|
+
}
|
|
82
|
+
if (line != NULL) {
|
|
83
|
+
*line = pull->err_line;
|
|
84
|
+
}
|
|
85
|
+
if (col != NULL) {
|
|
86
|
+
*col = pull->err_col;
|
|
87
|
+
}
|
|
88
|
+
return pull->status;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
YEPTRIS_API void yeptris_pull_free(YeptrisPullParser pull) {
|
|
92
|
+
if (pull == NULL) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
yep_rec_free(&pull->store);
|
|
96
|
+
free(pull);
|
|
97
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/* push.c — callback push over the engine sink (TODO.impl/12).
|
|
2
|
+
*
|
|
3
|
+
* The C-user convenience shape: one call per event, strings valid only
|
|
4
|
+
* during the callback. Bindings prefer the recorder's bulk drain. */
|
|
5
|
+
|
|
6
|
+
#include <string.h>
|
|
7
|
+
|
|
8
|
+
#include "../../include/yeptris/events.h"
|
|
9
|
+
#include "../common/simd_text.h"
|
|
10
|
+
#include "../parse/engine.h"
|
|
11
|
+
#include "yeptris/error.h"
|
|
12
|
+
#include "yeptris/parse.h"
|
|
13
|
+
|
|
14
|
+
typedef struct {
|
|
15
|
+
yeptris_event_fn fn;
|
|
16
|
+
void* ctx;
|
|
17
|
+
} yep_push_ctx;
|
|
18
|
+
|
|
19
|
+
static int push_on_event(void* ctx, const yep_event* ev) {
|
|
20
|
+
yep_push_ctx* p = (yep_push_ctx*)ctx;
|
|
21
|
+
YeptrisEvent e;
|
|
22
|
+
memset(&e, 0, sizeof(e));
|
|
23
|
+
switch (ev->type) {
|
|
24
|
+
case YEP_EV_STREAM_START:
|
|
25
|
+
e.type = YEPTRIS_EV_STREAM_START;
|
|
26
|
+
break;
|
|
27
|
+
case YEP_EV_STREAM_END:
|
|
28
|
+
e.type = YEPTRIS_EV_STREAM_END;
|
|
29
|
+
break;
|
|
30
|
+
case YEP_EV_DOCUMENT_START:
|
|
31
|
+
e.type = YEPTRIS_EV_DOCUMENT_START;
|
|
32
|
+
e.explicit_marker = (ev->style == 1);
|
|
33
|
+
break;
|
|
34
|
+
case YEP_EV_DOCUMENT_END:
|
|
35
|
+
e.type = YEPTRIS_EV_DOCUMENT_END;
|
|
36
|
+
e.explicit_marker = (ev->style == 1);
|
|
37
|
+
break;
|
|
38
|
+
case YEP_EV_SEQ_START:
|
|
39
|
+
e.type = YEPTRIS_EV_SEQUENCE_START;
|
|
40
|
+
break;
|
|
41
|
+
case YEP_EV_SEQ_END:
|
|
42
|
+
e.type = YEPTRIS_EV_SEQUENCE_END;
|
|
43
|
+
break;
|
|
44
|
+
case YEP_EV_MAP_START:
|
|
45
|
+
e.type = YEPTRIS_EV_MAPPING_START;
|
|
46
|
+
break;
|
|
47
|
+
case YEP_EV_MAP_END:
|
|
48
|
+
e.type = YEPTRIS_EV_MAPPING_END;
|
|
49
|
+
break;
|
|
50
|
+
case YEP_EV_SCALAR:
|
|
51
|
+
e.type = YEPTRIS_EV_SCALAR;
|
|
52
|
+
e.style = ev->style;
|
|
53
|
+
e.implicit = ev->implicit;
|
|
54
|
+
break;
|
|
55
|
+
case YEP_EV_ALIAS:
|
|
56
|
+
e.type = YEPTRIS_EV_ALIAS;
|
|
57
|
+
break;
|
|
58
|
+
default:
|
|
59
|
+
return 0;
|
|
60
|
+
}
|
|
61
|
+
e.flow = ev->flow;
|
|
62
|
+
e.line = ev->line;
|
|
63
|
+
e.col = ev->col;
|
|
64
|
+
e.value = ev->value.len > 0 ? (const char*)ev->value.p : NULL;
|
|
65
|
+
e.value_len = ev->value.len;
|
|
66
|
+
e.anchor = ev->anchor.len > 0 ? (const char*)ev->anchor.p : NULL;
|
|
67
|
+
e.anchor_len = ev->anchor.len;
|
|
68
|
+
e.tag = ev->tag.len > 0 ? (const char*)ev->tag.p : NULL;
|
|
69
|
+
e.tag_len = ev->tag.len;
|
|
70
|
+
return p->fn(p->ctx, &e);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
YEPTRIS_API YeptrisStatus yeptris_push_parse(const char* buf, size_t len, yeptris_event_fn on_event,
|
|
74
|
+
void* ctx) {
|
|
75
|
+
if (buf == NULL && len != 0) {
|
|
76
|
+
return YEPTRIS_ERROR_ARG;
|
|
77
|
+
}
|
|
78
|
+
if (on_event == NULL) {
|
|
79
|
+
return YEPTRIS_ERROR_ARG;
|
|
80
|
+
}
|
|
81
|
+
yep_engine* eng = yep_engine_create(yep_system_allocator());
|
|
82
|
+
if (eng == NULL) {
|
|
83
|
+
return YEPTRIS_ERROR_MEMORY;
|
|
84
|
+
}
|
|
85
|
+
yep_push_ctx p = {on_event, ctx};
|
|
86
|
+
yep_sink sink = {.on_event = push_on_event,
|
|
87
|
+
.ctx = &p,
|
|
88
|
+
.on_flow_build = NULL,
|
|
89
|
+
.on_flow_commit = NULL,
|
|
90
|
+
.on_flow_rollback = NULL,
|
|
91
|
+
.on_block_pair = NULL,
|
|
92
|
+
.on_block_open = NULL,
|
|
93
|
+
.on_block_item = NULL};
|
|
94
|
+
yep_text_stats pst;
|
|
95
|
+
yep_text_active()->scan_stats(buf, len, &pst);
|
|
96
|
+
yep_engine_prepare(eng, &pst);
|
|
97
|
+
int rc = yep_engine_run(eng, buf, len, &sink);
|
|
98
|
+
yep_engine_destroy(eng);
|
|
99
|
+
if (rc == 0) {
|
|
100
|
+
return YEPTRIS_OK;
|
|
101
|
+
}
|
|
102
|
+
/* -2: the callback aborted — reported as a parse stop, not a bug */
|
|
103
|
+
return YEPTRIS_ERROR_PARSE;
|
|
104
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/* recorder.c — chunked event recorder (TODO.impl/12).
|
|
2
|
+
*
|
|
3
|
+
* Feed chunks, drain bulk: fixed-size records plus one string arena,
|
|
4
|
+
* reset at every feed entry. The engine's resumable stepping (07)
|
|
5
|
+
* advances the parse as complete documents arrive — each feed's
|
|
6
|
+
* records are the events for documents closed by that chunk, so a
|
|
7
|
+
* stream watcher holds one document of memory, not the whole stream. */
|
|
8
|
+
|
|
9
|
+
#include <stdlib.h>
|
|
10
|
+
#include <string.h>
|
|
11
|
+
|
|
12
|
+
#include "../../include/yeptris/events.h"
|
|
13
|
+
#include "../parse/engine.h"
|
|
14
|
+
#include "../resolve/resolver.h"
|
|
15
|
+
#include "capture.h"
|
|
16
|
+
|
|
17
|
+
struct yeptris_recorder {
|
|
18
|
+
yep_rec_store store;
|
|
19
|
+
yep_engine* eng; /* created on first feed; steps per feed */
|
|
20
|
+
int final_fed;
|
|
21
|
+
int compat11;
|
|
22
|
+
YeptrisStatus status;
|
|
23
|
+
uint32_t err_line;
|
|
24
|
+
uint32_t err_col;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
YEPTRIS_API YeptrisRecorder yeptris_recorder_new(void) {
|
|
28
|
+
return yeptris_recorder_new_ex(YEPTRIS_SCHEMA_12_CORE);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
YEPTRIS_API YeptrisRecorder yeptris_recorder_new_ex(YeptrisSchema schema) {
|
|
32
|
+
struct yeptris_recorder* r = calloc(1, sizeof(*r));
|
|
33
|
+
if (r != NULL) {
|
|
34
|
+
yep_rec_init(&r->store);
|
|
35
|
+
r->compat11 = schema == YEPTRIS_SCHEMA_11_COMPAT;
|
|
36
|
+
}
|
|
37
|
+
return r;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
YEPTRIS_API YeptrisStatus yeptris_recorder_feed(YeptrisRecorder rec, const char* chunk, size_t len,
|
|
41
|
+
int final) {
|
|
42
|
+
if (rec == NULL || (chunk == NULL && len != 0)) {
|
|
43
|
+
return YEPTRIS_ERROR_ARG;
|
|
44
|
+
}
|
|
45
|
+
if (rec->final_fed) {
|
|
46
|
+
return YEPTRIS_ERROR_ARG; /* one stream per recorder */
|
|
47
|
+
}
|
|
48
|
+
if (rec->eng == NULL) {
|
|
49
|
+
rec->eng = yep_engine_create(yep_system_allocator());
|
|
50
|
+
if (rec->eng == NULL) {
|
|
51
|
+
return YEPTRIS_ERROR_MEMORY;
|
|
52
|
+
}
|
|
53
|
+
yep_engine_set_resolver(rec->eng,
|
|
54
|
+
rec->compat11 ? yep_resolver_compat11() : yep_resolver_core12());
|
|
55
|
+
}
|
|
56
|
+
if (final) {
|
|
57
|
+
rec->final_fed = 1;
|
|
58
|
+
}
|
|
59
|
+
yep_rec_reset(&rec->store);
|
|
60
|
+
yep_sink sink = {.on_event = yep_rec_on_event,
|
|
61
|
+
.ctx = &rec->store,
|
|
62
|
+
.on_flow_build = NULL,
|
|
63
|
+
.on_flow_commit = NULL,
|
|
64
|
+
.on_block_item = NULL};
|
|
65
|
+
int rc = yep_engine_step(rec->eng, chunk, len, final, &sink);
|
|
66
|
+
if (rc != 0) {
|
|
67
|
+
const yep_error* err = yep_engine_error(rec->eng);
|
|
68
|
+
if (err != NULL) {
|
|
69
|
+
rec->err_line = err->line;
|
|
70
|
+
rec->err_col = err->col;
|
|
71
|
+
}
|
|
72
|
+
rec->final_fed = 1; /* a parse error kills the stream */
|
|
73
|
+
rec->status = YEPTRIS_ERROR_PARSE;
|
|
74
|
+
return rec->status;
|
|
75
|
+
}
|
|
76
|
+
rec->status = YEPTRIS_OK;
|
|
77
|
+
return rec->status;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
YEPTRIS_API const YeptrisEventRecord* yeptris_recorder_records(YeptrisRecorder rec, size_t* count) {
|
|
81
|
+
if (rec == NULL) {
|
|
82
|
+
return NULL;
|
|
83
|
+
}
|
|
84
|
+
if (count != NULL) {
|
|
85
|
+
*count = rec->store.n;
|
|
86
|
+
}
|
|
87
|
+
return rec->store.recs;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
YEPTRIS_API const char* yeptris_recorder_arena(YeptrisRecorder rec, size_t* len) {
|
|
91
|
+
if (rec == NULL) {
|
|
92
|
+
return NULL;
|
|
93
|
+
}
|
|
94
|
+
if (len != NULL) {
|
|
95
|
+
*len = rec->store.arena_len;
|
|
96
|
+
}
|
|
97
|
+
return rec->store.arena;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
YEPTRIS_API void yeptris_recorder_free(YeptrisRecorder rec) {
|
|
101
|
+
if (rec == NULL) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
yep_engine_destroy(rec->eng);
|
|
105
|
+
yep_rec_free(&rec->store);
|
|
106
|
+
free(rec);
|
|
107
|
+
}
|