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,19 @@
|
|
|
1
|
+
/* tape_in.h — the tape module's internal seams (not public ABI).
|
|
2
|
+
*
|
|
3
|
+
* parse.c's #342 slice-2 lazy route drives the fused lenient walk
|
|
4
|
+
* directly: the gate and opener checks it already ran must not be
|
|
5
|
+
* repeated (the lenient public entry re-gates). The walk's contract
|
|
6
|
+
* is the public entry's: gate-clean buffer, p[open] is '[' or '{',
|
|
7
|
+
* tail must be whitespace-only. */
|
|
8
|
+
#ifndef YEP_TAPE_IN_H
|
|
9
|
+
#define YEP_TAPE_IN_H
|
|
10
|
+
|
|
11
|
+
#include <stddef.h>
|
|
12
|
+
|
|
13
|
+
#include <yeptris/tape.h>
|
|
14
|
+
|
|
15
|
+
/* tape.c (was tape_walk_lnt_fused) */
|
|
16
|
+
YeptrisStatus yep_tape_walk_lenient_fused(const char* p, size_t len, size_t open,
|
|
17
|
+
yeptris_json_tape* t);
|
|
18
|
+
|
|
19
|
+
#endif
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/* dom_visit.c — DOM subtree → visitor (TODO.restructure/24). */
|
|
2
|
+
|
|
3
|
+
#include <string.h>
|
|
4
|
+
|
|
5
|
+
#include "../dom/dom.h"
|
|
6
|
+
#include "../parse/numbers.h"
|
|
7
|
+
#include "doc.h"
|
|
8
|
+
|
|
9
|
+
#include <yeptris/resolve.h>
|
|
10
|
+
#include <yeptris/visit.h>
|
|
11
|
+
|
|
12
|
+
static int visit_id(const yep_dom* d, uint32_t id, const YeptrisVisitVTable* vt, void* ctx);
|
|
13
|
+
|
|
14
|
+
static int visit_id(const yep_dom* d, uint32_t id, const YeptrisVisitVTable* vt, void* ctx) {
|
|
15
|
+
const yep_dnode* n = yep_dom_node(d, id);
|
|
16
|
+
if (n == NULL) {
|
|
17
|
+
return -1;
|
|
18
|
+
}
|
|
19
|
+
if (n->anchor.len != 0 && n->kind != YEP_DOM_ALIAS && vt->on_anchor) {
|
|
20
|
+
yep_view a = yep_dom_view(d, n->anchor);
|
|
21
|
+
if (vt->on_anchor(ctx, a.p, a.len) != 0) {
|
|
22
|
+
return -1;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
switch (n->kind) {
|
|
26
|
+
case YEP_DOM_ALIAS: {
|
|
27
|
+
yep_view a = yep_dom_view(d, n->value);
|
|
28
|
+
if (vt->on_alias && vt->on_alias(ctx, a.p, a.len) != 0) {
|
|
29
|
+
return -1;
|
|
30
|
+
}
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
case YEP_DOM_SEQUENCE:
|
|
34
|
+
if (vt->on_seq_start && vt->on_seq_start(ctx) != 0) {
|
|
35
|
+
return -1;
|
|
36
|
+
}
|
|
37
|
+
for (uint32_t c = n->first_child; c != UINT32_MAX; c = d->nodes[c].next_sibling) {
|
|
38
|
+
if (visit_id(d, c, vt, ctx) != 0) {
|
|
39
|
+
return -1;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (vt->on_seq_end && vt->on_seq_end(ctx) != 0) {
|
|
43
|
+
return -1;
|
|
44
|
+
}
|
|
45
|
+
return 0;
|
|
46
|
+
case YEP_DOM_MAPPING:
|
|
47
|
+
if (vt->on_map_start && vt->on_map_start(ctx) != 0) {
|
|
48
|
+
return -1;
|
|
49
|
+
}
|
|
50
|
+
for (uint32_t c = n->first_child; c != UINT32_MAX;) {
|
|
51
|
+
uint32_t k = c;
|
|
52
|
+
uint32_t v = d->nodes[c].next_sibling;
|
|
53
|
+
if (v == UINT32_MAX) {
|
|
54
|
+
return -1;
|
|
55
|
+
}
|
|
56
|
+
/* key */
|
|
57
|
+
const yep_dnode* kn = yep_dom_node(d, k);
|
|
58
|
+
if (kn != NULL && kn->kind == YEP_DOM_SCALAR && vt->on_key) {
|
|
59
|
+
yep_view kv = yep_dom_view(d, kn->value);
|
|
60
|
+
if (vt->on_key(ctx, kv.p, kv.len) != 0) {
|
|
61
|
+
return -1;
|
|
62
|
+
}
|
|
63
|
+
} else if (visit_id(d, k, vt, ctx) != 0) {
|
|
64
|
+
return -1;
|
|
65
|
+
}
|
|
66
|
+
if (visit_id(d, v, vt, ctx) != 0) {
|
|
67
|
+
return -1;
|
|
68
|
+
}
|
|
69
|
+
c = d->nodes[v].next_sibling;
|
|
70
|
+
}
|
|
71
|
+
if (vt->on_map_end && vt->on_map_end(ctx) != 0) {
|
|
72
|
+
return -1;
|
|
73
|
+
}
|
|
74
|
+
return 0;
|
|
75
|
+
default: { /* scalar */
|
|
76
|
+
yep_view s = yep_dom_view(d, n->value);
|
|
77
|
+
switch (n->tag_id) {
|
|
78
|
+
case YEPTRIS_TAG_NULL:
|
|
79
|
+
return vt->on_null ? vt->on_null(ctx) : 0;
|
|
80
|
+
case YEPTRIS_TAG_BOOL: {
|
|
81
|
+
int b = yep_num_bool_ci(s.p, (uint32_t)s.len);
|
|
82
|
+
return vt->on_bool ? vt->on_bool(ctx, b) : 0;
|
|
83
|
+
}
|
|
84
|
+
case YEPTRIS_TAG_INT: {
|
|
85
|
+
int64_t v = 0;
|
|
86
|
+
if (yep_num_i64(s.p, (uint32_t)s.len, &v) != 0) {
|
|
87
|
+
return vt->on_string ? vt->on_string(ctx, s.p, s.len) : 0;
|
|
88
|
+
}
|
|
89
|
+
return vt->on_int ? vt->on_int(ctx, v) : 0;
|
|
90
|
+
}
|
|
91
|
+
case YEPTRIS_TAG_FLOAT: {
|
|
92
|
+
double v = 0.0;
|
|
93
|
+
if (yep_num_f64(s.p, (uint32_t)s.len, &v) != 0) {
|
|
94
|
+
return vt->on_string ? vt->on_string(ctx, s.p, s.len) : 0;
|
|
95
|
+
}
|
|
96
|
+
return vt->on_float ? vt->on_float(ctx, v) : 0;
|
|
97
|
+
}
|
|
98
|
+
default:
|
|
99
|
+
return vt->on_string ? vt->on_string(ctx, s.p, s.len) : 0;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
YEPTRIS_API YeptrisStatus yeptris_visit_node(YeptrisNode node, const YeptrisVisitVTable* vt,
|
|
106
|
+
void* ctx) {
|
|
107
|
+
if (node == NULL || vt == NULL) {
|
|
108
|
+
return YEPTRIS_ERROR_ARG;
|
|
109
|
+
}
|
|
110
|
+
yeptris_node* h = (yeptris_node*)node;
|
|
111
|
+
if (h->doc == NULL || h->doc->dom == NULL) {
|
|
112
|
+
return YEPTRIS_ERROR_ARG;
|
|
113
|
+
}
|
|
114
|
+
return visit_id(h->doc->dom, h->id, vt, ctx) == 0 ? YEPTRIS_OK : YEPTRIS_ERROR_INTERNAL;
|
|
115
|
+
}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
/* json_visit.c — fused RFC 8259 scan → visitor (TODO.restructure/24).
|
|
2
|
+
*
|
|
3
|
+
* One pass, no DOM, no records: the JSON kernels tokenize and the
|
|
4
|
+
* vtable receives values directly. Escaped strings decode into a
|
|
5
|
+
* small scratch that lives only for the on_string callback. */
|
|
6
|
+
|
|
7
|
+
#include <stdlib.h>
|
|
8
|
+
#include <string.h>
|
|
9
|
+
|
|
10
|
+
#include "../parse/numbers.h"
|
|
11
|
+
#include "../parse/scalars.h"
|
|
12
|
+
#include "../scan/json.h"
|
|
13
|
+
|
|
14
|
+
#include <yeptris/visit.h>
|
|
15
|
+
|
|
16
|
+
typedef struct {
|
|
17
|
+
const char* p;
|
|
18
|
+
size_t len;
|
|
19
|
+
size_t i;
|
|
20
|
+
const YeptrisVisitVTable* vt;
|
|
21
|
+
void* ctx;
|
|
22
|
+
char* scratch;
|
|
23
|
+
size_t scratch_cap;
|
|
24
|
+
int depth;
|
|
25
|
+
int err; /* 0 ok, -1 oom/abort, -2 parse */
|
|
26
|
+
} jv;
|
|
27
|
+
|
|
28
|
+
#define YEP_JV_MAX_DEPTH 1000
|
|
29
|
+
|
|
30
|
+
static int jv_emit_str(jv* j, const char* s, size_t n) {
|
|
31
|
+
if (j->vt->on_string == NULL) {
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
return j->vt->on_string(j->ctx, s, n);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static int jv_value(jv* j);
|
|
38
|
+
|
|
39
|
+
static void jv_ws(jv* j) {
|
|
40
|
+
while (j->i < j->len) {
|
|
41
|
+
char c = j->p[j->i];
|
|
42
|
+
if (c == ' ' || c == '\t' || c == '\n' || c == '\r') {
|
|
43
|
+
j->i++;
|
|
44
|
+
} else {
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static int jv_string(jv* j, int as_key) {
|
|
51
|
+
size_t start = j->i;
|
|
52
|
+
size_t close = 0;
|
|
53
|
+
int has_esc = 0;
|
|
54
|
+
if (!yep_json_string(j->p, j->len, &j->i, &close, &has_esc)) {
|
|
55
|
+
j->err = -2;
|
|
56
|
+
return -1;
|
|
57
|
+
}
|
|
58
|
+
const char* sp;
|
|
59
|
+
size_t sl;
|
|
60
|
+
if (has_esc) {
|
|
61
|
+
uint32_t span = (uint32_t)(close - start - 1);
|
|
62
|
+
if (span + 1 > j->scratch_cap) {
|
|
63
|
+
size_t cap = j->scratch_cap ? j->scratch_cap : 64;
|
|
64
|
+
while (cap < span + 1) {
|
|
65
|
+
cap *= 2;
|
|
66
|
+
}
|
|
67
|
+
char* ns = realloc(j->scratch, cap);
|
|
68
|
+
if (ns == NULL) {
|
|
69
|
+
j->err = -1;
|
|
70
|
+
return -1;
|
|
71
|
+
}
|
|
72
|
+
j->scratch = ns;
|
|
73
|
+
j->scratch_cap = cap;
|
|
74
|
+
}
|
|
75
|
+
sl = yep_finish_double_into(j->p, (uint32_t)(start + 1), (uint32_t)close, j->scratch, span);
|
|
76
|
+
sp = j->scratch;
|
|
77
|
+
} else {
|
|
78
|
+
sp = j->p + start + 1;
|
|
79
|
+
sl = close - start - 1;
|
|
80
|
+
}
|
|
81
|
+
int rc;
|
|
82
|
+
if (as_key && j->vt->on_key != NULL) {
|
|
83
|
+
rc = j->vt->on_key(j->ctx, sp, sl);
|
|
84
|
+
} else {
|
|
85
|
+
rc = jv_emit_str(j, sp, sl);
|
|
86
|
+
}
|
|
87
|
+
if (rc != 0) {
|
|
88
|
+
j->err = -1;
|
|
89
|
+
return -1;
|
|
90
|
+
}
|
|
91
|
+
return 0;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
static int jv_number(jv* j) {
|
|
95
|
+
size_t start = j->i;
|
|
96
|
+
if (!yep_json_number(j->p, j->len, &j->i)) {
|
|
97
|
+
j->err = -2;
|
|
98
|
+
return -1;
|
|
99
|
+
}
|
|
100
|
+
const char* s = j->p + start;
|
|
101
|
+
uint32_t n = (uint32_t)(j->i - start);
|
|
102
|
+
/* integer if no '.' and no exponent — matches JSON.parse */
|
|
103
|
+
int is_float = 0;
|
|
104
|
+
for (uint32_t k = 0; k < n; k++) {
|
|
105
|
+
char c = s[k];
|
|
106
|
+
if (c == '.' || c == 'e' || c == 'E') {
|
|
107
|
+
is_float = 1;
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (is_float) {
|
|
112
|
+
double d = 0.0;
|
|
113
|
+
if (yep_num_f64(s, n, &d) != 0) {
|
|
114
|
+
j->err = -2;
|
|
115
|
+
return -1;
|
|
116
|
+
}
|
|
117
|
+
if (j->vt->on_float != NULL && j->vt->on_float(j->ctx, d) != 0) {
|
|
118
|
+
j->err = -1;
|
|
119
|
+
return -1;
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
int64_t v = 0;
|
|
123
|
+
if (yep_num_i64(s, n, &v) != 0) {
|
|
124
|
+
/* overflow: hand up as double (JSON.parse does this past
|
|
125
|
+
* 2^53 roughly; we keep int64 max then float) */
|
|
126
|
+
double d = 0.0;
|
|
127
|
+
if (yep_num_f64(s, n, &d) != 0) {
|
|
128
|
+
j->err = -2;
|
|
129
|
+
return -1;
|
|
130
|
+
}
|
|
131
|
+
if (j->vt->on_float != NULL && j->vt->on_float(j->ctx, d) != 0) {
|
|
132
|
+
j->err = -1;
|
|
133
|
+
return -1;
|
|
134
|
+
}
|
|
135
|
+
} else if (j->vt->on_int != NULL && j->vt->on_int(j->ctx, v) != 0) {
|
|
136
|
+
j->err = -1;
|
|
137
|
+
return -1;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return 0;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
static int jv_literal(jv* j, const char* word, int kind) {
|
|
144
|
+
if (!yep_json_literal(j->p, j->len, &j->i, word)) {
|
|
145
|
+
j->err = -2;
|
|
146
|
+
return -1;
|
|
147
|
+
}
|
|
148
|
+
int rc = 0;
|
|
149
|
+
if (kind == 0) { /* null */
|
|
150
|
+
if (j->vt->on_null) {
|
|
151
|
+
rc = j->vt->on_null(j->ctx);
|
|
152
|
+
}
|
|
153
|
+
} else if (j->vt->on_bool) {
|
|
154
|
+
rc = j->vt->on_bool(j->ctx, kind > 0);
|
|
155
|
+
}
|
|
156
|
+
if (rc != 0) {
|
|
157
|
+
j->err = -1;
|
|
158
|
+
return -1;
|
|
159
|
+
}
|
|
160
|
+
return 0;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
static int jv_container(jv* j, int is_map) {
|
|
164
|
+
if (j->depth >= YEP_JV_MAX_DEPTH) {
|
|
165
|
+
j->err = -2;
|
|
166
|
+
return -1;
|
|
167
|
+
}
|
|
168
|
+
j->i++; /* skip [ or { */
|
|
169
|
+
j->depth++;
|
|
170
|
+
if (is_map) {
|
|
171
|
+
if (j->vt->on_map_start && j->vt->on_map_start(j->ctx) != 0) {
|
|
172
|
+
j->err = -1;
|
|
173
|
+
return -1;
|
|
174
|
+
}
|
|
175
|
+
} else if (j->vt->on_seq_start && j->vt->on_seq_start(j->ctx) != 0) {
|
|
176
|
+
j->err = -1;
|
|
177
|
+
return -1;
|
|
178
|
+
}
|
|
179
|
+
jv_ws(j);
|
|
180
|
+
char close = is_map ? '}' : ']';
|
|
181
|
+
if (j->i < j->len && j->p[j->i] == close) {
|
|
182
|
+
j->i++;
|
|
183
|
+
j->depth--;
|
|
184
|
+
if (is_map) {
|
|
185
|
+
if (j->vt->on_map_end && j->vt->on_map_end(j->ctx) != 0) {
|
|
186
|
+
j->err = -1;
|
|
187
|
+
return -1;
|
|
188
|
+
}
|
|
189
|
+
} else if (j->vt->on_seq_end && j->vt->on_seq_end(j->ctx) != 0) {
|
|
190
|
+
j->err = -1;
|
|
191
|
+
return -1;
|
|
192
|
+
}
|
|
193
|
+
return 0;
|
|
194
|
+
}
|
|
195
|
+
for (;;) {
|
|
196
|
+
if (is_map) {
|
|
197
|
+
jv_ws(j);
|
|
198
|
+
if (j->i >= j->len || j->p[j->i] != '"') {
|
|
199
|
+
j->err = -2;
|
|
200
|
+
return -1;
|
|
201
|
+
}
|
|
202
|
+
if (jv_string(j, 1) != 0) {
|
|
203
|
+
return -1;
|
|
204
|
+
}
|
|
205
|
+
jv_ws(j);
|
|
206
|
+
if (j->i >= j->len || j->p[j->i] != ':') {
|
|
207
|
+
j->err = -2;
|
|
208
|
+
return -1;
|
|
209
|
+
}
|
|
210
|
+
j->i++;
|
|
211
|
+
if (jv_value(j) != 0) {
|
|
212
|
+
return -1;
|
|
213
|
+
}
|
|
214
|
+
} else if (jv_value(j) != 0) {
|
|
215
|
+
return -1;
|
|
216
|
+
}
|
|
217
|
+
jv_ws(j);
|
|
218
|
+
if (j->i >= j->len) {
|
|
219
|
+
j->err = -2;
|
|
220
|
+
return -1;
|
|
221
|
+
}
|
|
222
|
+
if (j->p[j->i] == ',') {
|
|
223
|
+
j->i++;
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
if (j->p[j->i] == close) {
|
|
227
|
+
j->i++;
|
|
228
|
+
j->depth--;
|
|
229
|
+
if (is_map) {
|
|
230
|
+
if (j->vt->on_map_end && j->vt->on_map_end(j->ctx) != 0) {
|
|
231
|
+
j->err = -1;
|
|
232
|
+
return -1;
|
|
233
|
+
}
|
|
234
|
+
} else if (j->vt->on_seq_end && j->vt->on_seq_end(j->ctx) != 0) {
|
|
235
|
+
j->err = -1;
|
|
236
|
+
return -1;
|
|
237
|
+
}
|
|
238
|
+
return 0;
|
|
239
|
+
}
|
|
240
|
+
j->err = -2;
|
|
241
|
+
return -1;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
static int jv_value(jv* j) {
|
|
246
|
+
jv_ws(j);
|
|
247
|
+
if (j->i >= j->len) {
|
|
248
|
+
j->err = -2;
|
|
249
|
+
return -1;
|
|
250
|
+
}
|
|
251
|
+
char c = j->p[j->i];
|
|
252
|
+
if (c == '{') {
|
|
253
|
+
return jv_container(j, 1);
|
|
254
|
+
}
|
|
255
|
+
if (c == '[') {
|
|
256
|
+
return jv_container(j, 0);
|
|
257
|
+
}
|
|
258
|
+
if (c == '"') {
|
|
259
|
+
return jv_string(j, 0);
|
|
260
|
+
}
|
|
261
|
+
if (c == 't') {
|
|
262
|
+
return jv_literal(j, "true", 1);
|
|
263
|
+
}
|
|
264
|
+
if (c == 'f') {
|
|
265
|
+
return jv_literal(j, "false", -1);
|
|
266
|
+
}
|
|
267
|
+
if (c == 'n') {
|
|
268
|
+
return jv_literal(j, "null", 0);
|
|
269
|
+
}
|
|
270
|
+
if (c == '-' || (c >= '0' && c <= '9')) {
|
|
271
|
+
return jv_number(j);
|
|
272
|
+
}
|
|
273
|
+
j->err = -2;
|
|
274
|
+
return -1;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
YEPTRIS_API YeptrisStatus yeptris_visit_json(const char* data, size_t len,
|
|
278
|
+
const YeptrisVisitVTable* vt, void* ctx) {
|
|
279
|
+
if (vt == NULL || (data == NULL && len != 0)) {
|
|
280
|
+
return YEPTRIS_ERROR_ARG;
|
|
281
|
+
}
|
|
282
|
+
jv j = {data, len, 0, vt, ctx, NULL, 0, 0, 0};
|
|
283
|
+
if (jv_value(&j) != 0) {
|
|
284
|
+
free(j.scratch);
|
|
285
|
+
return j.err == -1 ? YEPTRIS_ERROR_MEMORY : YEPTRIS_ERROR_PARSE;
|
|
286
|
+
}
|
|
287
|
+
jv_ws(&j);
|
|
288
|
+
free(j.scratch);
|
|
289
|
+
if (j.i != len) {
|
|
290
|
+
return YEPTRIS_ERROR_PARSE;
|
|
291
|
+
}
|
|
292
|
+
return YEPTRIS_OK;
|
|
293
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/* yaml_visit.c — engine → visitor (TODO.restructure/24).
|
|
2
|
+
*
|
|
3
|
+
* Reuses the value-record pipeline (the conversion SSOT) and replays
|
|
4
|
+
* records into the vtable. One allocation of records is still far
|
|
5
|
+
* cheaper than host-side walks; the JSON fused path is the one that
|
|
6
|
+
* must beat JSON.parse and skips records entirely. */
|
|
7
|
+
|
|
8
|
+
#include <string.h>
|
|
9
|
+
|
|
10
|
+
#include "../events/values_priv.h"
|
|
11
|
+
|
|
12
|
+
#include <yeptris/visit.h>
|
|
13
|
+
|
|
14
|
+
/* CLOSE needs open-kind: replay with a small kind stack. */
|
|
15
|
+
static int play_stacked(const yep_value_ctx* c, const YeptrisVisitVTable* vt, void* ctx) {
|
|
16
|
+
const YeptrisValue* vals = c->vals;
|
|
17
|
+
const char* arena = c->arena ? c->arena : "";
|
|
18
|
+
unsigned char stack[1024];
|
|
19
|
+
int sp = 0;
|
|
20
|
+
for (size_t i = 0; i < c->n; i++) {
|
|
21
|
+
const YeptrisValue* v = &vals[i];
|
|
22
|
+
int rc = 0;
|
|
23
|
+
switch (v->kind) {
|
|
24
|
+
case YEP_V_DOC:
|
|
25
|
+
if (vt->on_doc) {
|
|
26
|
+
rc = vt->on_doc(ctx);
|
|
27
|
+
}
|
|
28
|
+
break;
|
|
29
|
+
case YEP_V_NULL:
|
|
30
|
+
if (vt->on_null) {
|
|
31
|
+
rc = vt->on_null(ctx);
|
|
32
|
+
}
|
|
33
|
+
break;
|
|
34
|
+
case YEP_V_BOOL:
|
|
35
|
+
if (vt->on_bool) {
|
|
36
|
+
rc = vt->on_bool(ctx, v->b);
|
|
37
|
+
}
|
|
38
|
+
break;
|
|
39
|
+
case YEP_V_INT:
|
|
40
|
+
if (vt->on_int) {
|
|
41
|
+
rc = vt->on_int(ctx, (int64_t)v->p);
|
|
42
|
+
}
|
|
43
|
+
break;
|
|
44
|
+
case YEP_V_FLOAT: {
|
|
45
|
+
double d;
|
|
46
|
+
memcpy(&d, &v->p, sizeof(d));
|
|
47
|
+
if (vt->on_float) {
|
|
48
|
+
rc = vt->on_float(ctx, d);
|
|
49
|
+
}
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
case YEP_V_STR:
|
|
53
|
+
case YEP_V_TIMESTAMP: {
|
|
54
|
+
const char* s = arena + v->off;
|
|
55
|
+
/* is_key alternation only MEANS something inside a map:
|
|
56
|
+
* the slot rule marks a container's first record
|
|
57
|
+
* spuriously when the parent is a sequence */
|
|
58
|
+
int in_map = sp > 0 && stack[sp - 1] == 1;
|
|
59
|
+
if (in_map && v->is_key && vt->on_key) {
|
|
60
|
+
rc = vt->on_key(ctx, s, v->len);
|
|
61
|
+
} else if (vt->on_string) {
|
|
62
|
+
rc = vt->on_string(ctx, s, v->len);
|
|
63
|
+
}
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
case YEP_V_SEQ_OPEN:
|
|
67
|
+
if (sp < (int)sizeof(stack)) {
|
|
68
|
+
stack[sp++] = 0;
|
|
69
|
+
}
|
|
70
|
+
if (vt->on_seq_start) {
|
|
71
|
+
rc = vt->on_seq_start(ctx);
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
case YEP_V_MAP_OPEN:
|
|
75
|
+
if (sp < (int)sizeof(stack)) {
|
|
76
|
+
stack[sp++] = 1;
|
|
77
|
+
}
|
|
78
|
+
if (vt->on_map_start) {
|
|
79
|
+
rc = vt->on_map_start(ctx);
|
|
80
|
+
}
|
|
81
|
+
break;
|
|
82
|
+
case YEP_V_CLOSE:
|
|
83
|
+
if (sp > 0) {
|
|
84
|
+
unsigned char kind = stack[--sp];
|
|
85
|
+
if (kind) {
|
|
86
|
+
if (vt->on_map_end) {
|
|
87
|
+
rc = vt->on_map_end(ctx);
|
|
88
|
+
}
|
|
89
|
+
} else if (vt->on_seq_end) {
|
|
90
|
+
rc = vt->on_seq_end(ctx);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
break;
|
|
94
|
+
case YEP_V_ANCHOR:
|
|
95
|
+
if (vt->on_anchor) {
|
|
96
|
+
rc = vt->on_anchor(ctx, arena + v->off, v->len);
|
|
97
|
+
}
|
|
98
|
+
break;
|
|
99
|
+
case YEP_V_ALIAS:
|
|
100
|
+
if (vt->on_alias) {
|
|
101
|
+
rc = vt->on_alias(ctx, arena + v->off, v->len);
|
|
102
|
+
}
|
|
103
|
+
break;
|
|
104
|
+
default:
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
if (rc != 0) {
|
|
108
|
+
return -1;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return 0;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
YEPTRIS_API YeptrisStatus yeptris_visit(const char* data, size_t len, YeptrisSchema schema,
|
|
115
|
+
const YeptrisVisitVTable* vt, void* ctx) {
|
|
116
|
+
if (vt == NULL || (data == NULL && len != 0)) {
|
|
117
|
+
return YEPTRIS_ERROR_ARG;
|
|
118
|
+
}
|
|
119
|
+
yep_value_ctx* c = NULL;
|
|
120
|
+
int rc = yep_values_from_input(data, len, schema == YEPTRIS_SCHEMA_11_COMPAT, &c);
|
|
121
|
+
if (rc != 0) {
|
|
122
|
+
return rc == -1 ? YEPTRIS_ERROR_MEMORY : YEPTRIS_ERROR_PARSE;
|
|
123
|
+
}
|
|
124
|
+
int prc = play_stacked(c, vt, ctx);
|
|
125
|
+
yep_value_ctx_free(c);
|
|
126
|
+
return prc == 0 ? YEPTRIS_OK : YEPTRIS_ERROR_INTERNAL;
|
|
127
|
+
}
|