yeptris 0.6.5.4 → 0.6.7.2
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 +4 -4
- data/ext/libyeptris/extconf.rb +57 -0
- data/lib/yeptris/ffi.rb +12 -15
- data/lib/yeptris/json.rb +5 -2
- data/lib/yeptris/psych.rb +76 -3
- data/lib/yeptris.rb +36 -14
- 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 +181 -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 +119 -0
- data/vendor/libyeptris/src/include/yeptris/tape.h +99 -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 +371 -0
- data/vendor/libyeptris/src/yeptris/cbor/cbor.h +25 -0
- data/vendor/libyeptris/src/yeptris/cbor/decode.c +846 -0
- data/vendor/libyeptris/src/yeptris/cbor/encode.c +824 -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 +37 -0
- data/vendor/libyeptris/src/yeptris/dom/dom.c +973 -0
- data/vendor/libyeptris/src/yeptris/dom/dom.h +290 -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 +429 -0
- data/vendor/libyeptris/src/yeptris/emit/emit.c +349 -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 +203 -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 +746 -0
- data/vendor/libyeptris/src/yeptris/emit/writer.h +61 -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 +744 -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 +115 -0
- data/vendor/libyeptris/src/yeptris/memory/pool.h +36 -0
- data/vendor/libyeptris/src/yeptris/parse/engine.c +3689 -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 +650 -0
- data/vendor/libyeptris/src/yeptris/plan.c +817 -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 +238 -0
- data/vendor/libyeptris/src/yeptris/tape.c +1292 -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 +112 -2
|
@@ -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
|
+
}
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: yeptris
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.6.
|
|
4
|
+
version: 0.6.7.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
@@ -30,11 +30,13 @@ description: A Ruby YAML library over libyeptris — Psych-compatible semantics
|
|
|
30
30
|
email:
|
|
31
31
|
- open.source@ribose.com
|
|
32
32
|
executables: []
|
|
33
|
-
extensions:
|
|
33
|
+
extensions:
|
|
34
|
+
- ext/libyeptris/extconf.rb
|
|
34
35
|
extra_rdoc_files: []
|
|
35
36
|
files:
|
|
36
37
|
- README.adoc
|
|
37
38
|
- ext/build_windows_native.rb
|
|
39
|
+
- ext/libyeptris/extconf.rb
|
|
38
40
|
- ext/yeptris_native/extconf.rb
|
|
39
41
|
- ext/yeptris_native/json_ruby.c
|
|
40
42
|
- ext/yeptris_native/yeptris_native.c
|
|
@@ -56,6 +58,114 @@ files:
|
|
|
56
58
|
- lib/yeptris/valueml.rb
|
|
57
59
|
- lib/yeptris/yaml.rb
|
|
58
60
|
- lib/yeptris/yaml/descriptor.rb
|
|
61
|
+
- vendor/libyeptris/CMakeLists.txt
|
|
62
|
+
- vendor/libyeptris/cmake/yeptris-config.cmake.in
|
|
63
|
+
- vendor/libyeptris/cmake/yeptris.pc.in
|
|
64
|
+
- vendor/libyeptris/src/CMakeLists.txt
|
|
65
|
+
- vendor/libyeptris/src/include/yeptris.h
|
|
66
|
+
- vendor/libyeptris/src/include/yeptris/api.h
|
|
67
|
+
- vendor/libyeptris/src/include/yeptris/cbor.h
|
|
68
|
+
- vendor/libyeptris/src/include/yeptris/dom.h
|
|
69
|
+
- vendor/libyeptris/src/include/yeptris/emit.h
|
|
70
|
+
- vendor/libyeptris/src/include/yeptris/error.h
|
|
71
|
+
- vendor/libyeptris/src/include/yeptris/events.h
|
|
72
|
+
- vendor/libyeptris/src/include/yeptris/json.h
|
|
73
|
+
- vendor/libyeptris/src/include/yeptris/json.hpp
|
|
74
|
+
- vendor/libyeptris/src/include/yeptris/jsonc_compat.h
|
|
75
|
+
- vendor/libyeptris/src/include/yeptris/marshal.h
|
|
76
|
+
- vendor/libyeptris/src/include/yeptris/parse.h
|
|
77
|
+
- vendor/libyeptris/src/include/yeptris/plan.h
|
|
78
|
+
- vendor/libyeptris/src/include/yeptris/resolve.h
|
|
79
|
+
- vendor/libyeptris/src/include/yeptris/schema.h
|
|
80
|
+
- vendor/libyeptris/src/include/yeptris/tape.h
|
|
81
|
+
- vendor/libyeptris/src/include/yeptris/types.h
|
|
82
|
+
- vendor/libyeptris/src/include/yeptris/values.h
|
|
83
|
+
- vendor/libyeptris/src/include/yeptris/version.h.in
|
|
84
|
+
- vendor/libyeptris/src/include/yeptris/visit.h
|
|
85
|
+
- vendor/libyeptris/src/include/yeptris/yajl_compat.h
|
|
86
|
+
- vendor/libyeptris/src/yeptris/build.c
|
|
87
|
+
- vendor/libyeptris/src/yeptris/cbor/cbor.h
|
|
88
|
+
- vendor/libyeptris/src/yeptris/cbor/decode.c
|
|
89
|
+
- vendor/libyeptris/src/yeptris/cbor/encode.c
|
|
90
|
+
- vendor/libyeptris/src/yeptris/common/chartype.c
|
|
91
|
+
- vendor/libyeptris/src/yeptris/common/chartype.h
|
|
92
|
+
- vendor/libyeptris/src/yeptris/common/cpu.c
|
|
93
|
+
- vendor/libyeptris/src/yeptris/common/cpu.h
|
|
94
|
+
- vendor/libyeptris/src/yeptris/common/error.c
|
|
95
|
+
- vendor/libyeptris/src/yeptris/common/error.h
|
|
96
|
+
- vendor/libyeptris/src/yeptris/common/mutex.h
|
|
97
|
+
- vendor/libyeptris/src/yeptris/common/nametab.c
|
|
98
|
+
- vendor/libyeptris/src/yeptris/common/nametab.h
|
|
99
|
+
- vendor/libyeptris/src/yeptris/common/port.h
|
|
100
|
+
- vendor/libyeptris/src/yeptris/common/simd_text.c
|
|
101
|
+
- vendor/libyeptris/src/yeptris/common/simd_text.h
|
|
102
|
+
- vendor/libyeptris/src/yeptris/common/simd_text_avx2.c
|
|
103
|
+
- vendor/libyeptris/src/yeptris/common/simd_text_neon.c
|
|
104
|
+
- vendor/libyeptris/src/yeptris/common/simd_text_scalar.c
|
|
105
|
+
- vendor/libyeptris/src/yeptris/common/string_view.c
|
|
106
|
+
- vendor/libyeptris/src/yeptris/common/string_view.h
|
|
107
|
+
- vendor/libyeptris/src/yeptris/doc.h
|
|
108
|
+
- vendor/libyeptris/src/yeptris/dom/dom.c
|
|
109
|
+
- vendor/libyeptris/src/yeptris/dom/dom.h
|
|
110
|
+
- vendor/libyeptris/src/yeptris/dom/hpool.c
|
|
111
|
+
- vendor/libyeptris/src/yeptris/dom/mapindex.c
|
|
112
|
+
- vendor/libyeptris/src/yeptris/dom/mapindex.h
|
|
113
|
+
- vendor/libyeptris/src/yeptris/dom/mutate.c
|
|
114
|
+
- vendor/libyeptris/src/yeptris/emit/emit.c
|
|
115
|
+
- vendor/libyeptris/src/yeptris/emit/float/api.h
|
|
116
|
+
- vendor/libyeptris/src/yeptris/emit/float/dragon.c
|
|
117
|
+
- vendor/libyeptris/src/yeptris/emit/float/floatint.h
|
|
118
|
+
- vendor/libyeptris/src/yeptris/emit/float/print.c
|
|
119
|
+
- vendor/libyeptris/src/yeptris/emit/style.c
|
|
120
|
+
- vendor/libyeptris/src/yeptris/emit/style.h
|
|
121
|
+
- vendor/libyeptris/src/yeptris/emit/writer.c
|
|
122
|
+
- vendor/libyeptris/src/yeptris/emit/writer.h
|
|
123
|
+
- vendor/libyeptris/src/yeptris/encoding/bom.c
|
|
124
|
+
- vendor/libyeptris/src/yeptris/encoding/encoding.h
|
|
125
|
+
- vendor/libyeptris/src/yeptris/encoding/transcode.c
|
|
126
|
+
- vendor/libyeptris/src/yeptris/encoding/utf8_validate.c
|
|
127
|
+
- vendor/libyeptris/src/yeptris/events/capture.c
|
|
128
|
+
- vendor/libyeptris/src/yeptris/events/capture.h
|
|
129
|
+
- vendor/libyeptris/src/yeptris/events/iterparse.c
|
|
130
|
+
- vendor/libyeptris/src/yeptris/events/pull.c
|
|
131
|
+
- vendor/libyeptris/src/yeptris/events/push.c
|
|
132
|
+
- vendor/libyeptris/src/yeptris/events/recorder.c
|
|
133
|
+
- vendor/libyeptris/src/yeptris/events/values.c
|
|
134
|
+
- vendor/libyeptris/src/yeptris/events/values_priv.h
|
|
135
|
+
- vendor/libyeptris/src/yeptris/events/yaml_compat.c
|
|
136
|
+
- vendor/libyeptris/src/yeptris/events/yaml_compat.h
|
|
137
|
+
- vendor/libyeptris/src/yeptris/jsonapi/jsonc_compat.c
|
|
138
|
+
- vendor/libyeptris/src/yeptris/jsonapi/yajl_compat.c
|
|
139
|
+
- vendor/libyeptris/src/yeptris/marshal.c
|
|
140
|
+
- vendor/libyeptris/src/yeptris/memory/allocator.c
|
|
141
|
+
- vendor/libyeptris/src/yeptris/memory/allocator.h
|
|
142
|
+
- vendor/libyeptris/src/yeptris/memory/arena.c
|
|
143
|
+
- vendor/libyeptris/src/yeptris/memory/arena.h
|
|
144
|
+
- vendor/libyeptris/src/yeptris/memory/pool.c
|
|
145
|
+
- vendor/libyeptris/src/yeptris/memory/pool.h
|
|
146
|
+
- vendor/libyeptris/src/yeptris/parse.c
|
|
147
|
+
- vendor/libyeptris/src/yeptris/parse/engine.c
|
|
148
|
+
- vendor/libyeptris/src/yeptris/parse/engine.h
|
|
149
|
+
- vendor/libyeptris/src/yeptris/parse/events.h
|
|
150
|
+
- vendor/libyeptris/src/yeptris/parse/numbers.c
|
|
151
|
+
- vendor/libyeptris/src/yeptris/parse/numbers.h
|
|
152
|
+
- vendor/libyeptris/src/yeptris/parse/scalars.c
|
|
153
|
+
- vendor/libyeptris/src/yeptris/parse/scalars.h
|
|
154
|
+
- vendor/libyeptris/src/yeptris/plan.c
|
|
155
|
+
- vendor/libyeptris/src/yeptris/resolve/compat11.c
|
|
156
|
+
- vendor/libyeptris/src/yeptris/resolve/core12.c
|
|
157
|
+
- vendor/libyeptris/src/yeptris/resolve/resolver.h
|
|
158
|
+
- vendor/libyeptris/src/yeptris/resolve/tags.c
|
|
159
|
+
- vendor/libyeptris/src/yeptris/scan/json.c
|
|
160
|
+
- vendor/libyeptris/src/yeptris/scan/json.h
|
|
161
|
+
- vendor/libyeptris/src/yeptris/scan/scan.c
|
|
162
|
+
- vendor/libyeptris/src/yeptris/scan/scan.h
|
|
163
|
+
- vendor/libyeptris/src/yeptris/schema.c
|
|
164
|
+
- vendor/libyeptris/src/yeptris/tape.c
|
|
165
|
+
- vendor/libyeptris/src/yeptris/version.c
|
|
166
|
+
- vendor/libyeptris/src/yeptris/visit/dom_visit.c
|
|
167
|
+
- vendor/libyeptris/src/yeptris/visit/json_visit.c
|
|
168
|
+
- vendor/libyeptris/src/yeptris/visit/yaml_visit.c
|
|
59
169
|
homepage: https://github.com/leptris/yeptris
|
|
60
170
|
licenses:
|
|
61
171
|
- MIT
|