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,298 @@
|
|
|
1
|
+
/* simd_text_scalar.c — the reference truth for every kernel.
|
|
2
|
+
*
|
|
3
|
+
* Deliberately naive: the differential suite compares the active ISA table
|
|
4
|
+
* AND these functions against independently-written naive references in
|
|
5
|
+
* the test, so a shared bug between ISA and scalar code cannot hide.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#include <string.h>
|
|
9
|
+
|
|
10
|
+
#include "simd_text.h"
|
|
11
|
+
|
|
12
|
+
int yep_text_contains_scalar(const char* s, size_t len, char c) {
|
|
13
|
+
return yep_text_find_scalar(s, len, c) >= 0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
ptrdiff_t yep_text_find_scalar(const char* s, size_t len, char c) {
|
|
17
|
+
for (size_t i = 0; i < len; i++) {
|
|
18
|
+
if (s[i] == c) {
|
|
19
|
+
return (ptrdiff_t)i;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return -1;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
ptrdiff_t yep_text_find3_scalar(const char* s, size_t len, char c0, char c1, char c2) {
|
|
26
|
+
if (len < 3) {
|
|
27
|
+
return -1;
|
|
28
|
+
}
|
|
29
|
+
for (size_t i = 0; i + 2 < len; i++) {
|
|
30
|
+
if (s[i] == c0 && s[i + 1] == c1 && s[i + 2] == c2) {
|
|
31
|
+
return (ptrdiff_t)i;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return -1;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
size_t yep_text_count_char_scalar(const char* s, size_t len, char c) {
|
|
38
|
+
size_t n = 0;
|
|
39
|
+
for (size_t i = 0; i < len; i++) {
|
|
40
|
+
n += (s[i] == c);
|
|
41
|
+
}
|
|
42
|
+
return n;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
void yep_text_count3_scalar(const char* s, size_t len, char c0, char c1, char c2, size_t* n0,
|
|
46
|
+
size_t* n1, size_t* n2) {
|
|
47
|
+
size_t a = 0, b = 0, d = 0;
|
|
48
|
+
for (size_t i = 0; i < len; i++) {
|
|
49
|
+
a += (s[i] == c0);
|
|
50
|
+
b += (s[i] == c1);
|
|
51
|
+
d += (s[i] == c2);
|
|
52
|
+
}
|
|
53
|
+
*n0 = a;
|
|
54
|
+
*n1 = b;
|
|
55
|
+
*n2 = d;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
void yep_text_copy_count3_scalar(char* dst, const char* src, size_t len, char c0, char c1, char c2,
|
|
59
|
+
size_t* n0, size_t* n1, size_t* n2) {
|
|
60
|
+
/* len 0 with NULL dst (count-only callers) must not reach memcpy:
|
|
61
|
+
* the nonnull attribute makes the call UB even for size 0 */
|
|
62
|
+
if (len == 0) {
|
|
63
|
+
*n0 = *n1 = *n2 = 0;
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
memcpy(dst, src, len);
|
|
67
|
+
yep_text_count3_scalar(dst, len, c0, c1, c2, n0, n1, n2);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
ptrdiff_t yep_text_find_not_scalar(const char* s, size_t len, char c) {
|
|
71
|
+
for (size_t i = 0; i < len; i++) {
|
|
72
|
+
if (s[i] != c) {
|
|
73
|
+
return (ptrdiff_t)i;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return -1;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
ptrdiff_t yep_text_stopset_find_scalar(const yep_stopset* ss, const char* s, size_t len) {
|
|
80
|
+
for (size_t i = 0; i < len; i++) {
|
|
81
|
+
if (yep_stopset_test(ss->bitmap, (unsigned char)s[i])) {
|
|
82
|
+
return (ptrdiff_t)i;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return -1;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
ptrdiff_t yep_text_qbc_find_scalar(const char* s, size_t len) {
|
|
89
|
+
for (size_t i = 0; i < len; i++) {
|
|
90
|
+
unsigned char c = (unsigned char)s[i];
|
|
91
|
+
if (c == '"' || c == '\\' || c < 0x20) {
|
|
92
|
+
return (ptrdiff_t)i;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return -1;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
ptrdiff_t yep_text_quote_scan_scalar(const char* s, size_t len, char q, int* has_escape) {
|
|
99
|
+
int esc = 0;
|
|
100
|
+
for (size_t i = 0; i < len; i++) {
|
|
101
|
+
if (q == '"' && s[i] == '\\') {
|
|
102
|
+
esc = 1;
|
|
103
|
+
i++; /* skip the escaped byte (a trailing lone backslash ends scanning) */
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (s[i] == q) {
|
|
107
|
+
if (q == '\'' && i + 1 < len && s[i + 1] == '\'') {
|
|
108
|
+
esc = 1;
|
|
109
|
+
i++; /* doubled quote inside a single-quoted scalar */
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (has_escape != NULL) {
|
|
113
|
+
*has_escape = esc;
|
|
114
|
+
}
|
|
115
|
+
return (ptrdiff_t)i;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (has_escape != NULL) {
|
|
119
|
+
*has_escape = esc;
|
|
120
|
+
}
|
|
121
|
+
return -1;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
void yep_text_scan_stats_scalar(const char* s, size_t len, yep_text_stats* out) {
|
|
125
|
+
if (s == NULL || len == 0) {
|
|
126
|
+
memset(out, 0, sizeof(*out));
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
yep_text_stats st = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
|
131
|
+
for (size_t i = 0; i < len; i++) {
|
|
132
|
+
unsigned char c = (unsigned char)s[i];
|
|
133
|
+
if (c >= 0x80) {
|
|
134
|
+
st.nonascii = 1;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
switch (c) {
|
|
138
|
+
case '\n':
|
|
139
|
+
st.nl++;
|
|
140
|
+
break;
|
|
141
|
+
case ',':
|
|
142
|
+
st.comma++;
|
|
143
|
+
break;
|
|
144
|
+
case '-':
|
|
145
|
+
st.dash++;
|
|
146
|
+
break;
|
|
147
|
+
case ':':
|
|
148
|
+
st.colon++;
|
|
149
|
+
break;
|
|
150
|
+
case '[':
|
|
151
|
+
st.bracket++;
|
|
152
|
+
break;
|
|
153
|
+
case '{':
|
|
154
|
+
st.brace++;
|
|
155
|
+
break;
|
|
156
|
+
case '"':
|
|
157
|
+
st.dq++;
|
|
158
|
+
break;
|
|
159
|
+
case '\'':
|
|
160
|
+
st.sq++;
|
|
161
|
+
break;
|
|
162
|
+
case '|':
|
|
163
|
+
st.pipe++;
|
|
164
|
+
break;
|
|
165
|
+
case '&':
|
|
166
|
+
st.amp++;
|
|
167
|
+
break;
|
|
168
|
+
default:
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
if ((c < 0x20 && c != 9 && c != 10 && c != 13) || c == 0x7F) {
|
|
172
|
+
st.bad_printable = 1;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
*out = st;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
int yep_text_gate_scan_scalar(const char* s, size_t len) {
|
|
179
|
+
for (size_t i = 0; i < len; i++) {
|
|
180
|
+
unsigned char c = (unsigned char)s[i];
|
|
181
|
+
if (!((c >= 0x20 && c <= 0x7E) || c == 0x09 || c == 0x0A || c == 0x0D)) {
|
|
182
|
+
return 1;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return 0;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/* yep_swar_eq8 lives in simd_text.h — shared with the walker's
|
|
189
|
+
* fused skips (TODO.restructure/86 wave 2). */
|
|
190
|
+
|
|
191
|
+
/* Eight bytes per step, one data-dependent exit (the break's chunk):
|
|
192
|
+
* the byte-at-a-time trio cost ~60 cycles/line in branch mispredicts
|
|
193
|
+
* alone on the short-line shapes (anchor-heavy's hottest symbol).
|
|
194
|
+
* cap bounds the walk: 0 returns when no break sits within cap bytes
|
|
195
|
+
* (a long line — the caller sweeps) so the ISA kernels use this as
|
|
196
|
+
* BOTH the short-line test and the short-line answer (the previous
|
|
197
|
+
* shape paid a 32-byte probe and then rescanned the same line). */
|
|
198
|
+
int yep_text_line_facts_capped(const char* s, size_t len, size_t pos, size_t cap,
|
|
199
|
+
yep_line_facts* out) {
|
|
200
|
+
static const uint64_t k_nl = 0x0A0A0A0A0A0A0A0Aull, k_cr = 0x0D0D0D0D0D0D0D0Dull,
|
|
201
|
+
k_sp = 0x2020202020202020ull, k_co = 0x3A3A3A3A3A3A3A3Aull,
|
|
202
|
+
k_ha = 0x2323232323232323ull;
|
|
203
|
+
size_t whole = len - pos;
|
|
204
|
+
size_t n = whole < cap ? whole : cap;
|
|
205
|
+
size_t end = n, indent = n, stop = n;
|
|
206
|
+
int have_indent = 0, stop_set = 0, have_end = 0;
|
|
207
|
+
size_t i = 0;
|
|
208
|
+
while (i < n) {
|
|
209
|
+
size_t avail = n - i < 8 ? n - i : 8;
|
|
210
|
+
uint64_t x;
|
|
211
|
+
if (avail == 8) {
|
|
212
|
+
memcpy(&x, s + pos + i, 8);
|
|
213
|
+
} else {
|
|
214
|
+
char buf[8] = {0, 0, 0, 0, 0, 0, 0, 0}; /* NUL padding: matches no fact byte */
|
|
215
|
+
memcpy(buf, s + pos + i, avail);
|
|
216
|
+
memcpy(&x, buf, 8);
|
|
217
|
+
}
|
|
218
|
+
uint64_t valid = avail == 8 ? ~(uint64_t)0 : (((uint64_t)1 << (avail * 8)) - 1);
|
|
219
|
+
uint64_t br = (yep_swar_eq8(x, k_nl) | yep_swar_eq8(x, k_cr)) & valid;
|
|
220
|
+
/* flags strictly below the FIRST break (br - 1 alone keeps the
|
|
221
|
+
* higher break flags of the same chunk) */
|
|
222
|
+
uint64_t room = (br ? ((br & (~br + 1)) - 1) : valid) & YEP_SWAR_FLAGS & valid;
|
|
223
|
+
if (!have_indent) {
|
|
224
|
+
uint64_t nons = ~(yep_swar_eq8(x, k_sp)) & room;
|
|
225
|
+
if (nons) {
|
|
226
|
+
indent = i + (size_t)(yep_ctz64(nons) >> 3);
|
|
227
|
+
have_indent = 1;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (have_indent && !stop_set) {
|
|
231
|
+
uint64_t stm = (yep_swar_eq8(x, k_co) | yep_swar_eq8(x, k_ha)) & room;
|
|
232
|
+
if (stm) {
|
|
233
|
+
size_t cand = i + (size_t)(yep_ctz64(stm) >> 3);
|
|
234
|
+
if (cand >= indent) { /* a stop byte cannot precede the first non-space */
|
|
235
|
+
stop = cand;
|
|
236
|
+
stop_set = 1;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (br) {
|
|
241
|
+
end = i + (size_t)(yep_ctz64(br) >> 3);
|
|
242
|
+
have_end = 1;
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
i += 8;
|
|
246
|
+
}
|
|
247
|
+
if (!have_end && whole > cap) {
|
|
248
|
+
return 0; /* the line continues past the cap: the caller sweeps */
|
|
249
|
+
}
|
|
250
|
+
if (!have_indent) {
|
|
251
|
+
indent = end; /* spaces ran to the break */
|
|
252
|
+
}
|
|
253
|
+
if (!stop_set) {
|
|
254
|
+
stop = end;
|
|
255
|
+
}
|
|
256
|
+
out->end = (uint32_t)(pos + end);
|
|
257
|
+
out->indent = (uint32_t)(pos + indent);
|
|
258
|
+
out->stop = (uint32_t)(pos + stop);
|
|
259
|
+
out->stop_set = stop_set;
|
|
260
|
+
return 1;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
void yep_text_line_facts_scalar(const char* s, size_t len, size_t pos, yep_line_facts* out) {
|
|
264
|
+
(void)yep_text_line_facts_capped(s, len, pos, (size_t)-1, out);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
yep_chunk_masks yep_text_json_chunk_scalar(const char* p, size_t n) {
|
|
268
|
+
yep_chunk_masks m = {0, 0, 0, 0, 0, 0};
|
|
269
|
+
for (size_t i = 0; i < n; i++) {
|
|
270
|
+
unsigned char c = (unsigned char)p[i];
|
|
271
|
+
uint32_t bit = 1u << i;
|
|
272
|
+
m.valid |= bit;
|
|
273
|
+
if (c == '"') {
|
|
274
|
+
m.quote |= bit;
|
|
275
|
+
} else if (c == '\\') {
|
|
276
|
+
m.bs |= bit;
|
|
277
|
+
} else if (c == '{' || c == '}' || c == '[' || c == ']' || c == ',' || c == ':') {
|
|
278
|
+
m.structurals |= bit;
|
|
279
|
+
} else if (c == '-' || (c >= '0' && c <= '9') || c == 't' || c == 'f' || c == 'n') {
|
|
280
|
+
m.valstart |= bit;
|
|
281
|
+
} else if (c < 0x20) {
|
|
282
|
+
m.c0 |= bit;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return m;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/* the stage-1 scalar reference lives in scan/json.c (the grammar
|
|
289
|
+
* home); the table carries it so dispatch stays one point */
|
|
290
|
+
extern int yep_json_stage1_scalar(const char* p, size_t len, uint32_t* idx, size_t* nidx);
|
|
291
|
+
|
|
292
|
+
const yep_text_kernels yep_text_kernels_scalar = {
|
|
293
|
+
yep_text_contains_scalar, yep_text_find_scalar, yep_text_find3_scalar,
|
|
294
|
+
yep_text_count_char_scalar, yep_text_count3_scalar, yep_text_copy_count3_scalar,
|
|
295
|
+
yep_text_find_not_scalar, yep_text_stopset_find_scalar, yep_text_quote_scan_scalar,
|
|
296
|
+
yep_text_scan_stats_scalar, yep_text_qbc_find_scalar, yep_text_gate_scan_scalar,
|
|
297
|
+
yep_text_line_facts_scalar, yep_text_json_chunk_scalar, yep_json_stage1_scalar,
|
|
298
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/* string_view.c — YepView primitives. */
|
|
2
|
+
|
|
3
|
+
#include <string.h>
|
|
4
|
+
|
|
5
|
+
#include "string_view.h"
|
|
6
|
+
|
|
7
|
+
yep_view yep_view_from_cstr(const char* s) {
|
|
8
|
+
yep_view v = {s, s ? (uint32_t)strlen(s) : 0};
|
|
9
|
+
return v;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
bool yep_view_eq_cstr(yep_view a, const char* s) {
|
|
13
|
+
if (s == NULL) {
|
|
14
|
+
return a.len == 0;
|
|
15
|
+
}
|
|
16
|
+
size_t n = strlen(s);
|
|
17
|
+
return a.len == n && (n == 0 || memcmp(a.p, s, n) == 0);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
bool yep_view_starts_with(yep_view v, const char* prefix) {
|
|
21
|
+
if (prefix == NULL) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
size_t n = strlen(prefix);
|
|
25
|
+
return v.len >= n && memcmp(v.p, prefix, n) == 0;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
yep_view yep_view_slice(yep_view v, uint32_t off, uint32_t len) {
|
|
29
|
+
if (off > v.len || len > v.len - off) {
|
|
30
|
+
return yep_view_empty();
|
|
31
|
+
}
|
|
32
|
+
yep_view out = {v.p + off, len};
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/* string_view.h — YepView: the single string representation (SSOT law).
|
|
2
|
+
*
|
|
3
|
+
* Every string in the library is a YepView — either borrowed into the
|
|
4
|
+
* caller's input buffer, or borrowed into the document string arena after
|
|
5
|
+
* a fold/escape copy. No module stores (char*, int) pairs or NUL-
|
|
6
|
+
* terminated strings internally.
|
|
7
|
+
*
|
|
8
|
+
* Views are NOT NUL-terminated; length is authoritative.
|
|
9
|
+
*/
|
|
10
|
+
#ifndef YEP_STRING_VIEW_H
|
|
11
|
+
#define YEP_STRING_VIEW_H
|
|
12
|
+
|
|
13
|
+
#include <stdbool.h>
|
|
14
|
+
#include <stdint.h>
|
|
15
|
+
#include <string.h>
|
|
16
|
+
|
|
17
|
+
#include "port.h"
|
|
18
|
+
|
|
19
|
+
#ifdef __cplusplus
|
|
20
|
+
extern "C" {
|
|
21
|
+
#endif
|
|
22
|
+
|
|
23
|
+
typedef struct yep_view {
|
|
24
|
+
const char* p;
|
|
25
|
+
uint32_t len;
|
|
26
|
+
} yep_view;
|
|
27
|
+
|
|
28
|
+
static inline yep_view yep_view_empty(void) {
|
|
29
|
+
yep_view v = {NULL, 0};
|
|
30
|
+
return v;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/* Wraps a NUL-terminated string (test/convenience paths only). */
|
|
34
|
+
yep_view yep_view_from_cstr(const char* s);
|
|
35
|
+
|
|
36
|
+
static inline bool yep_view_is_empty(yep_view v) {
|
|
37
|
+
return v.len == 0;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* True if a and b are the same bytes. Word-at-a-time: interner probes
|
|
41
|
+
* compare tiny keys millions of times per parse and a libc memcmp call
|
|
42
|
+
* per probe cost ~5% of anchor-heavy parse. */
|
|
43
|
+
static inline bool yep_view_eq(yep_view a, yep_view b) {
|
|
44
|
+
if (a.len != b.len) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
uint32_t n = a.len;
|
|
48
|
+
const char* p = a.p;
|
|
49
|
+
const char* q = b.p;
|
|
50
|
+
while (n >= 8) {
|
|
51
|
+
uint64_t x, y;
|
|
52
|
+
memcpy(&x, p, 8);
|
|
53
|
+
memcpy(&y, q, 8);
|
|
54
|
+
if (x != y) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
p += 8;
|
|
58
|
+
q += 8;
|
|
59
|
+
n -= 8;
|
|
60
|
+
}
|
|
61
|
+
if (n >= 4) {
|
|
62
|
+
uint32_t x, y;
|
|
63
|
+
memcpy(&x, p, 4);
|
|
64
|
+
memcpy(&y, q, 4);
|
|
65
|
+
if (x != y) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
p += 4;
|
|
69
|
+
q += 4;
|
|
70
|
+
n -= 4;
|
|
71
|
+
}
|
|
72
|
+
while (n--) {
|
|
73
|
+
if (*p++ != *q++) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/* True if a equals the NUL-terminated s (without including its NUL). */
|
|
81
|
+
bool yep_view_eq_cstr(yep_view a, const char* s);
|
|
82
|
+
|
|
83
|
+
/* True if v begins with the NUL-terminated prefix. */
|
|
84
|
+
bool yep_view_starts_with(yep_view v, const char* prefix);
|
|
85
|
+
|
|
86
|
+
/* Sub-view [off, off + len). Invalid bounds yield the empty view. */
|
|
87
|
+
yep_view yep_view_slice(yep_view v, uint32_t off, uint32_t len);
|
|
88
|
+
|
|
89
|
+
#ifdef __cplusplus
|
|
90
|
+
}
|
|
91
|
+
#endif
|
|
92
|
+
|
|
93
|
+
#endif /* YEP_STRING_VIEW_H */
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/* doc.h — the internal document shape (TODO.impl/11/13).
|
|
2
|
+
*
|
|
3
|
+
* Private: parse.c builds it, the emitter reads it. The public header
|
|
4
|
+
* only ever sees the opaque handle. */
|
|
5
|
+
#ifndef YEP_DOC_H
|
|
6
|
+
#define YEP_DOC_H
|
|
7
|
+
|
|
8
|
+
#include <stddef.h>
|
|
9
|
+
|
|
10
|
+
#include "dom/dom.h"
|
|
11
|
+
#include "memory/allocator.h"
|
|
12
|
+
|
|
13
|
+
typedef struct yeptris_document {
|
|
14
|
+
yep_dom* dom;
|
|
15
|
+
const yep_allocator* sys;
|
|
16
|
+
int schema; /* the parse's schema (YEPTRIS_SCHEMA_*): document
|
|
17
|
+
* property — host policies (Psych float quirks) are
|
|
18
|
+
* conditioned on it (TODO.restructure/32) */
|
|
19
|
+
unsigned char* transcoded; /* owned when non-NULL */
|
|
20
|
+
size_t transcoded_len;
|
|
21
|
+
const char* input; /* borrowed input (lifetime documentation) */
|
|
22
|
+
void* finish_pool; /* engine finish pool: resolved tags, folded and
|
|
23
|
+
escaped scalars outlive the engine through the
|
|
24
|
+
document */
|
|
25
|
+
void* lazy_tape; /* #342 slice 2: the parsed tape when the tree is
|
|
26
|
+
* deferred (gate-clean strict JSON). dom==NULL until
|
|
27
|
+
* the first tree access materializes via dom_from_tape;
|
|
28
|
+
* freed with the document. void* to avoid a header
|
|
29
|
+
* cycle — parse.c casts to yeptris_json_tape* */
|
|
30
|
+
} yeptris_document;
|
|
31
|
+
|
|
32
|
+
/* Node handle: a (document, node-id) pair so nodes stay usable even if
|
|
33
|
+
* the node pool grows (ids are stable; pointers are not). Defined here
|
|
34
|
+
* (not parse.c) since the query layer and the builder share it. */
|
|
35
|
+
/* #342 slice 2: the lazy-tree choke point. Returns the document's dom,
|
|
36
|
+
* materializing it from lazy_tape on first access (NULL when materialization
|
|
37
|
+
* fails — callers treat it as an empty/unusable tree). Every consumer that
|
|
38
|
+
* reads ->dom on a parse-produced document routes through here; the builder
|
|
39
|
+
* and CBOR decode paths set dom eagerly and are unaffected. parse.c owns it. */
|
|
40
|
+
typedef struct yeptris_node {
|
|
41
|
+
yeptris_document* doc;
|
|
42
|
+
uint32_t id;
|
|
43
|
+
} yeptris_node;
|
|
44
|
+
|
|
45
|
+
#ifdef __cplusplus
|
|
46
|
+
extern "C" {
|
|
47
|
+
#endif
|
|
48
|
+
|
|
49
|
+
yep_dom* yep_doc_dom(yeptris_document* doc);
|
|
50
|
+
yeptris_node* yep_handle_new(yeptris_document* doc, uint32_t id);
|
|
51
|
+
|
|
52
|
+
#ifdef __cplusplus
|
|
53
|
+
}
|
|
54
|
+
#endif
|
|
55
|
+
|
|
56
|
+
#endif /* YEP_DOC_H */
|