yeptris 0.6.64.0-riscv64-linux-gnu
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.adoc +150 -0
- data/ext/build_windows_native.rb +60 -0
- data/ext/libyeptris/extconf.rb +57 -0
- data/ext/yeptris_native/cbor_ruby.c +198 -0
- data/ext/yeptris_native/extconf.rb +99 -0
- data/ext/yeptris_native/json_ruby.c +414 -0
- data/ext/yeptris_native/version.h +29 -0
- data/ext/yeptris_native/yeptris_native.c +507 -0
- data/lib/yeptris/3.3/native.so +0 -0
- data/lib/yeptris/cbor.rb +169 -0
- data/lib/yeptris/document.rb +319 -0
- data/lib/yeptris/ffi.rb +572 -0
- data/lib/yeptris/json/descriptor.rb +266 -0
- data/lib/yeptris/json.rb +502 -0
- data/lib/yeptris/materializer.rb +389 -0
- data/lib/yeptris/node.rb +482 -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 +95 -0
- data/lib/yeptris/psych/parser.rb +114 -0
- data/lib/yeptris/psych/scalar_scanner.rb +149 -0
- data/lib/yeptris/psych/tree_builder.rb +119 -0
- data/lib/yeptris/psych/visitors.rb +670 -0
- data/lib/yeptris/psych.rb +796 -0
- data/lib/yeptris/schema.rb +253 -0
- data/lib/yeptris/validation.rb +320 -0
- data/lib/yeptris/valueml.rb +477 -0
- data/lib/yeptris/yaml/descriptor.rb +56 -0
- data/lib/yeptris/yaml.rb +668 -0
- data/lib/yeptris.rb +130 -0
- data/libyeptris.so +0 -0
- data/vendor/libyeptris/CMakeLists.txt +280 -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 +183 -0
- data/vendor/libyeptris/src/include/yeptris/api.h +32 -0
- data/vendor/libyeptris/src/include/yeptris/cbor.h +174 -0
- data/vendor/libyeptris/src/include/yeptris/dom.h +196 -0
- data/vendor/libyeptris/src/include/yeptris/emit.h +128 -0
- data/vendor/libyeptris/src/include/yeptris/error.h +42 -0
- data/vendor/libyeptris/src/include/yeptris/events.h +171 -0
- data/vendor/libyeptris/src/include/yeptris/json.h +57 -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 +75 -0
- data/vendor/libyeptris/src/include/yeptris/parse.h +121 -0
- data/vendor/libyeptris/src/include/yeptris/plan.h +100 -0
- data/vendor/libyeptris/src/include/yeptris/resolve.h +81 -0
- data/vendor/libyeptris/src/include/yeptris/schema.h +121 -0
- data/vendor/libyeptris/src/include/yeptris/tape.h +128 -0
- data/vendor/libyeptris/src/include/yeptris/types.h +38 -0
- data/vendor/libyeptris/src/include/yeptris/validate.h +401 -0
- data/vendor/libyeptris/src/include/yeptris/values.h +108 -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 +24 -0
- data/vendor/libyeptris/src/yeptris/build.c +393 -0
- data/vendor/libyeptris/src/yeptris/cbor/cbor.h +35 -0
- data/vendor/libyeptris/src/yeptris/cbor/decode.c +1054 -0
- data/vendor/libyeptris/src/yeptris/cbor/encode.c +836 -0
- data/vendor/libyeptris/src/yeptris/cbor/encode_priv.h +32 -0
- data/vendor/libyeptris/src/yeptris/cbor/from_marshal.c +982 -0
- data/vendor/libyeptris/src/yeptris/cbor/sink.h +36 -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 +81 -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 +342 -0
- data/vendor/libyeptris/src/yeptris/common/simd_text_avx2.c +672 -0
- data/vendor/libyeptris/src/yeptris/common/simd_text_neon.c +793 -0
- data/vendor/libyeptris/src/yeptris/common/simd_text_scalar.c +324 -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 +86 -0
- data/vendor/libyeptris/src/yeptris/dom/dom.c +1312 -0
- data/vendor/libyeptris/src/yeptris/dom/dom.h +332 -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/dom/ytape.c +2323 -0
- data/vendor/libyeptris/src/yeptris/dom/ytape.h +96 -0
- data/vendor/libyeptris/src/yeptris/emit/emit.c +670 -0
- data/vendor/libyeptris/src/yeptris/emit/float/api.h +43 -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/fpconv.c +428 -0
- data/vendor/libyeptris/src/yeptris/emit/float/print.c +396 -0
- data/vendor/libyeptris/src/yeptris/emit/style.c +21 -0
- data/vendor/libyeptris/src/yeptris/emit/style.h +32 -0
- data/vendor/libyeptris/src/yeptris/emit/writer.c +1951 -0
- data/vendor/libyeptris/src/yeptris/emit/writer.h +111 -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 +157 -0
- data/vendor/libyeptris/src/yeptris/encoding/utf8_validate.c +178 -0
- data/vendor/libyeptris/src/yeptris/events/capture.c +166 -0
- data/vendor/libyeptris/src/yeptris/events/capture.h +39 -0
- data/vendor/libyeptris/src/yeptris/events/iterparse.c +298 -0
- data/vendor/libyeptris/src/yeptris/events/pull.c +117 -0
- data/vendor/libyeptris/src/yeptris/events/push.c +151 -0
- data/vendor/libyeptris/src/yeptris/events/recorder.c +144 -0
- data/vendor/libyeptris/src/yeptris/events/values.c +630 -0
- data/vendor/libyeptris/src/yeptris/events/values_priv.h +53 -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/to_json.c +650 -0
- data/vendor/libyeptris/src/yeptris/marshal.c +988 -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 +150 -0
- data/vendor/libyeptris/src/yeptris/memory/arena.h +52 -0
- data/vendor/libyeptris/src/yeptris/memory/pool.c +133 -0
- data/vendor/libyeptris/src/yeptris/memory/pool.h +36 -0
- data/vendor/libyeptris/src/yeptris/parse/engine.c +6528 -0
- data/vendor/libyeptris/src/yeptris/parse/engine.h +96 -0
- data/vendor/libyeptris/src/yeptris/parse/events.h +137 -0
- data/vendor/libyeptris/src/yeptris/parse/numbers.c +374 -0
- data/vendor/libyeptris/src/yeptris/parse/numbers.h +33 -0
- data/vendor/libyeptris/src/yeptris/parse/scalars.c +435 -0
- data/vendor/libyeptris/src/yeptris/parse/scalars.h +87 -0
- data/vendor/libyeptris/src/yeptris/parse/stream_iter.c +358 -0
- data/vendor/libyeptris/src/yeptris/parse.c +1074 -0
- data/vendor/libyeptris/src/yeptris/plan.c +824 -0
- data/vendor/libyeptris/src/yeptris/resolve/compat11.c +339 -0
- data/vendor/libyeptris/src/yeptris/resolve/core12.c +153 -0
- data/vendor/libyeptris/src/yeptris/resolve/full12.c +201 -0
- data/vendor/libyeptris/src/yeptris/resolve/json12.c +109 -0
- data/vendor/libyeptris/src/yeptris/resolve/resolver.h +103 -0
- data/vendor/libyeptris/src/yeptris/resolve/tags.c +250 -0
- data/vendor/libyeptris/src/yeptris/scan/json.c +839 -0
- data/vendor/libyeptris/src/yeptris/scan/json.h +116 -0
- data/vendor/libyeptris/src/yeptris/scan/scan.c +862 -0
- data/vendor/libyeptris/src/yeptris/scan/scan.h +177 -0
- data/vendor/libyeptris/src/yeptris/schema.c +309 -0
- data/vendor/libyeptris/src/yeptris/tape.c +2375 -0
- data/vendor/libyeptris/src/yeptris/tape_in.h +39 -0
- data/vendor/libyeptris/src/yeptris/validate/compile.c +306 -0
- data/vendor/libyeptris/src/yeptris/validate/internal.h +347 -0
- data/vendor/libyeptris/src/yeptris/validate/jsonschema.c +1922 -0
- data/vendor/libyeptris/src/yeptris/validate/output.c +246 -0
- data/vendor/libyeptris/src/yeptris/validate/regexp.c +1600 -0
- data/vendor/libyeptris/src/yeptris/validate/registry.c +118 -0
- data/vendor/libyeptris/src/yeptris/validate/resources.c +601 -0
- data/vendor/libyeptris/src/yeptris/validate/stream.c +1155 -0
- data/vendor/libyeptris/src/yeptris/validate/validate.c +1043 -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 +221 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/* json12.c — the spec 10.2 JSON schema resolver (#882).
|
|
2
|
+
*
|
|
3
|
+
* The productions are the spec 10.2.2 table (1.2.2 erratum kept: the
|
|
4
|
+
* float regex needs NO digits after the dot — "0." is a float):
|
|
5
|
+
* null: null
|
|
6
|
+
* bool: true | false
|
|
7
|
+
* int: -? ( 0 | [1-9] [0-9]* )
|
|
8
|
+
* float: -? ( 0 | [1-9] [0-9]* ) ( \. [0-9]* )? ( [eE] [-+]? [0-9]+ )?
|
|
9
|
+
* * -> str (see below: example 10.8 governs; the Error row does not)
|
|
10
|
+
*
|
|
11
|
+
* Deliberately NOT accepted (the core schema's extensions): "True"/
|
|
12
|
+
* "False"/"NULL" casings, "~"/empty nulls, +signs, 0o/0x radix, .inf/
|
|
13
|
+
* .nan, underscores. The example-10.8 Invalid list pins each one.
|
|
14
|
+
*
|
|
15
|
+
* Shape: yep_json12_plain is the ONE classifier — the resolver wraps
|
|
16
|
+
* it, and the validator re-asks it per plain scalar key (no second
|
|
17
|
+
* truth table anywhere). SPEC NOTE (the 10.2.2 contradiction): the
|
|
18
|
+
* table's `* -> Error` row says no-match plains "should be considered
|
|
19
|
+
* an error", but example 10.8 — the spec's own JSON Tag Resolution
|
|
20
|
+
* demonstration — resolves no-match plains as strings BOTH as keys
|
|
21
|
+
* ("A null", "Booleans") and as values (the "Invalid" list). Example
|
|
22
|
+
* 10.8 wins: a scalar outside the productions resolves str so the DOM
|
|
23
|
+
* stays family-neutral, and the validation face does NOT turn no-match
|
|
24
|
+
* plains into diagnostics; the family's teeth are the string-key
|
|
25
|
+
* demand (12_JSON) and explicit non-JSON tags.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
#include <stdint.h>
|
|
29
|
+
#include <string.h>
|
|
30
|
+
|
|
31
|
+
#include "resolver.h"
|
|
32
|
+
|
|
33
|
+
/* JSON int: -?(0|[1-9][0-9]*); optionally continues as the float
|
|
34
|
+
* production (the int regex is a prefix of the float one). Returns 1
|
|
35
|
+
* (int), 2 (float), 0 (no production). */
|
|
36
|
+
int yep_json12_plain(const char* p, uint32_t n) {
|
|
37
|
+
if (n == 0) {
|
|
38
|
+
return 0;
|
|
39
|
+
}
|
|
40
|
+
if (n == 4 && memcmp(p, "null", 4) == 0) {
|
|
41
|
+
return 4; /* null */
|
|
42
|
+
}
|
|
43
|
+
if (n == 4 && memcmp(p, "true", 4) == 0) {
|
|
44
|
+
return 3; /* bool */
|
|
45
|
+
}
|
|
46
|
+
if (n == 5 && memcmp(p, "false", 5) == 0) {
|
|
47
|
+
return 3;
|
|
48
|
+
}
|
|
49
|
+
uint32_t i = (p[0] == '-') ? 1 : 0;
|
|
50
|
+
if (i >= n) {
|
|
51
|
+
return 0; /* lone "-" (or empty after the prefix check) */
|
|
52
|
+
}
|
|
53
|
+
/* int part: 0 | [1-9][0-9]* — no +sign, no leading zeros */
|
|
54
|
+
if (p[i] == '0') {
|
|
55
|
+
i++;
|
|
56
|
+
} else if (p[i] >= '1' && p[i] <= '9') {
|
|
57
|
+
i++;
|
|
58
|
+
while (i < n && p[i] >= '0' && p[i] <= '9') {
|
|
59
|
+
i++;
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
return 0;
|
|
63
|
+
}
|
|
64
|
+
if (i == n) {
|
|
65
|
+
return 1; /* bare int */
|
|
66
|
+
}
|
|
67
|
+
/* float tail: (\.[0-9]*)? ([eE][-+]?[0-9]+)? — at least one of the
|
|
68
|
+
* two must be present (a bare int already returned) */
|
|
69
|
+
int floaty = 0;
|
|
70
|
+
if (p[i] == '.') {
|
|
71
|
+
floaty = 1;
|
|
72
|
+
i++;
|
|
73
|
+
while (i < n && p[i] >= '0' && p[i] <= '9') {
|
|
74
|
+
i++; /* digits optional after the dot (1.2.2 erratum) */
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (i < n && (p[i] == 'e' || p[i] == 'E')) {
|
|
78
|
+
i++;
|
|
79
|
+
if (i < n && (p[i] == '+' || p[i] == '-')) {
|
|
80
|
+
i++;
|
|
81
|
+
}
|
|
82
|
+
int ed = 0;
|
|
83
|
+
while (i < n && p[i] >= '0' && p[i] <= '9') {
|
|
84
|
+
i++;
|
|
85
|
+
ed = 1;
|
|
86
|
+
}
|
|
87
|
+
if (!ed) {
|
|
88
|
+
return 0; /* exponent sign(s) with no digits */
|
|
89
|
+
}
|
|
90
|
+
floaty = 1;
|
|
91
|
+
}
|
|
92
|
+
return (floaty && i == n) ? 2 : 0;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
static yep_tag_id json12(void* ctx, const char* p, uint32_t n) {
|
|
96
|
+
(void)ctx;
|
|
97
|
+
return (yep_tag_id)yep_json12_plain(p, n);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
static yep_tag_id json12_number(void* ctx, int is_float) {
|
|
101
|
+
(void)ctx;
|
|
102
|
+
return is_float ? 2 : 1;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
static const yep_resolver k_json12 = {json12, json12_number, NULL, 0};
|
|
106
|
+
|
|
107
|
+
const yep_resolver* yep_resolver_json12(void) {
|
|
108
|
+
return &k_json12;
|
|
109
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/* resolver.h — the internal resolver interface (TODO.impl/10).
|
|
2
|
+
*
|
|
3
|
+
* MECE: scan produces facts, the engine parses, the RESOLVER alone
|
|
4
|
+
* decides implicit typing. OCP: a new schema is a new resolver
|
|
5
|
+
* instance; no schema branches exist anywhere else.
|
|
6
|
+
*/
|
|
7
|
+
#ifndef YEP_RESOLVER_H
|
|
8
|
+
#define YEP_RESOLVER_H
|
|
9
|
+
|
|
10
|
+
#include <stdint.h>
|
|
11
|
+
|
|
12
|
+
#include "common/string_view.h"
|
|
13
|
+
|
|
14
|
+
/* yep_view: bytes + length, the one string representation (SSOT). */
|
|
15
|
+
|
|
16
|
+
/* The tag-id space is the public YeptrisTagId (resolve.h); internal
|
|
17
|
+
* re-export for the table SSOT. */
|
|
18
|
+
typedef uint8_t yep_tag_id;
|
|
19
|
+
|
|
20
|
+
typedef struct yep_resolver {
|
|
21
|
+
/* Returns the implicit tag for a PLAIN, untagged scalar. */
|
|
22
|
+
yep_tag_id (*resolve)(void* ctx, const char* p, uint32_t len);
|
|
23
|
+
/* Optional fast path for spans a validator already classified as
|
|
24
|
+
* strict numbers (is_float: the text contains '.' or an exponent):
|
|
25
|
+
* skips the digit re-walk resolve() would pay. NULL = resolve(). */
|
|
26
|
+
yep_tag_id (*resolve_number)(void* ctx, int is_float);
|
|
27
|
+
void* ctx;
|
|
28
|
+
/* 1 when timestamp:yaml.org,2002 is IN the family's implicit set —
|
|
29
|
+
* the validator family-checks explicit !!timestamp content through
|
|
30
|
+
* resolve() (#906 slice 3). Core leaves it consumer-defined (the
|
|
31
|
+
* core schema has no timestamp, spec 10.3); 11_COMPAT is not a
|
|
32
|
+
* validation family; json12 rejects the tag wholesale. */
|
|
33
|
+
int timestamped;
|
|
34
|
+
} yep_resolver;
|
|
35
|
+
|
|
36
|
+
/* Typing for a validated number span, through whichever hook the
|
|
37
|
+
* schema provides (the typing SSOT either way). */
|
|
38
|
+
static inline yep_tag_id yep_resolve_number(const yep_resolver* r, int is_float) {
|
|
39
|
+
if (r->resolve_number != NULL) {
|
|
40
|
+
return r->resolve_number(NULL, is_float);
|
|
41
|
+
}
|
|
42
|
+
return is_float ? 2 /* float */ : 1 /* int */;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* The two built-in resolvers (no ctx). */
|
|
46
|
+
const yep_resolver* yep_resolver_core12(void);
|
|
47
|
+
const yep_resolver* yep_resolver_compat11(void);
|
|
48
|
+
/* The core schema's plain-scalar classifier (the core truth table):
|
|
49
|
+
* the resolver wraps it and the full family composes it. */
|
|
50
|
+
yep_tag_id yep_core12_plain(const char* p, uint32_t n);
|
|
51
|
+
|
|
52
|
+
/* The spec 10.2 JSON schema resolver (#882): null/true/false exact,
|
|
53
|
+
* the JSON int and float productions, everything else str. Parse stays
|
|
54
|
+
* lenient — the VALIDATOR flags plain scalars that matched no
|
|
55
|
+
* production (the spec's `*` -> Error row) through the classifier. */
|
|
56
|
+
const yep_resolver* yep_resolver_json12(void);
|
|
57
|
+
/* 1 when the plain span matches a JSON-schema production. The one
|
|
58
|
+
* truth table for the 12_JSON family (validate/ re-asks it). */
|
|
59
|
+
int yep_json12_plain(const char* p, uint32_t n);
|
|
60
|
+
|
|
61
|
+
/* The FULL 1.2 family resolver (#906 slice 3): the core productions
|
|
62
|
+
* verbatim (spec 10.4: interoperable schemas are "strongly recommended
|
|
63
|
+
* ... based on the core schema") extended with the yaml.org type
|
|
64
|
+
* repository's carried-forward set — RFC3339-era timestamps on untagged
|
|
65
|
+
* plains (spec 2.22's canonical/iso8601/spaced/date forms; PyYAML's
|
|
66
|
+
* timestamp regex as the practice oracle) and the merge/value words.
|
|
67
|
+
* The 1.1 NUMERIC quirks (underscores, sexagesimal, leading-0 octal,
|
|
68
|
+
* y/n booleans) stay in compat11 — full is spec-refereed, not
|
|
69
|
+
* psych-refereed. */
|
|
70
|
+
const yep_resolver* yep_resolver_full12(void);
|
|
71
|
+
|
|
72
|
+
/* core tag id <-> canonical URI (tags.c is the identity SSOT). */
|
|
73
|
+
const char* yep_tag_uri(yep_tag_id id);
|
|
74
|
+
|
|
75
|
+
/* Explicit-tag resolution: the tag URI a node carried maps to a core
|
|
76
|
+
* id when it matches one, else YEPTRIS_TAG_CUSTOM. */
|
|
77
|
+
yep_tag_id yep_tag_from_uri(const char* p, uint32_t len);
|
|
78
|
+
|
|
79
|
+
/* Canonical word for a resolved float view: ".inf" / "-.inf" / ".nan"
|
|
80
|
+
* or NULL when the view is not an infinity/nan word (the canonical
|
|
81
|
+
* emitter re-prints these words; libc strtod does not accept them
|
|
82
|
+
* portably). */
|
|
83
|
+
const char* yep_tag_float_word(const char* p, uint32_t len);
|
|
84
|
+
|
|
85
|
+
/* The BOOL truth table for a resolved-bool view: 1 true, 0 false,
|
|
86
|
+
* -1 not a bool word. One table, two consumers: compat11's classify
|
|
87
|
+
* and the canonical/JSON emitter's BOOL arm — the DOM stores only the
|
|
88
|
+
* tag + source text, so the emitter re-asks the table (#937: guessing
|
|
89
|
+
* the value from the text's length spelled every non-4-char true-word
|
|
90
|
+
* false). The ci union of the families' sets (core's true/false forms
|
|
91
|
+
* are in the compat superset), so no family fact is needed. */
|
|
92
|
+
int yep_tag_bool_value(const char* p, uint32_t len);
|
|
93
|
+
|
|
94
|
+
/* Decode a resolved-INT view to its value through the family's own
|
|
95
|
+
* accepted forms: radix prefixes 0x/0o in both (0b and the leading-0
|
|
96
|
+
* octal + _/,/sexagesimal forms only when compat — core spells
|
|
97
|
+
* leading-0 decimal), digits otherwise. Overflow beyond the int64
|
|
98
|
+
* range returns nonzero and *out is untouched. The canonical/JSON
|
|
99
|
+
* emitter's INT arm (#937: source text like 0x1F is not a JSON
|
|
100
|
+
* token). */
|
|
101
|
+
int yep_tag_int64(const char* p, uint32_t len, int compat, int64_t* out);
|
|
102
|
+
|
|
103
|
+
#endif /* YEP_RESOLVER_H */
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/* tags.c — the tag identity SSOT (TODO.impl/10).
|
|
2
|
+
*
|
|
3
|
+
* Dense ids for the core set; canonical URIs live here once. Custom
|
|
4
|
+
* tags keep their string (the DOM already stores the view) and use
|
|
5
|
+
* YEPTRIS_TAG_CUSTOM.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#include "resolver.h"
|
|
9
|
+
|
|
10
|
+
#include <string.h>
|
|
11
|
+
|
|
12
|
+
typedef struct {
|
|
13
|
+
yep_tag_id id;
|
|
14
|
+
const char* uri;
|
|
15
|
+
} yep_tag_entry;
|
|
16
|
+
|
|
17
|
+
static const yep_tag_entry k_core[] = {
|
|
18
|
+
{0, "tag:yaml.org,2002:str"}, {1, "tag:yaml.org,2002:int"},
|
|
19
|
+
{2, "tag:yaml.org,2002:float"}, {3, "tag:yaml.org,2002:bool"},
|
|
20
|
+
{4, "tag:yaml.org,2002:null"}, {5, "tag:yaml.org,2002:timestamp"},
|
|
21
|
+
{6, "tag:yaml.org,2002:seq"}, {7, "tag:yaml.org,2002:map"},
|
|
22
|
+
{8, "tag:yaml.org,2002:binary"}, {9, "tag:yaml.org,2002:merge"},
|
|
23
|
+
{10, "tag:yaml.org,2002:value"},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const char* yep_tag_uri(yep_tag_id id) {
|
|
27
|
+
if (id < sizeof(k_core) / sizeof(k_core[0])) {
|
|
28
|
+
return k_core[id].uri;
|
|
29
|
+
}
|
|
30
|
+
return NULL;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
yep_tag_id yep_tag_from_uri(const char* p, uint32_t len) {
|
|
34
|
+
for (size_t i = 0; i < sizeof(k_core) / sizeof(k_core[0]); i++) {
|
|
35
|
+
if (strlen(k_core[i].uri) == len && memcmp(k_core[i].uri, p, len) == 0) {
|
|
36
|
+
return k_core[i].id;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return 11; /* YEPTRIS_TAG_CUSTOM */
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const char* yep_tag_float_word(const char* p, uint32_t len) {
|
|
43
|
+
static const struct {
|
|
44
|
+
const char* word;
|
|
45
|
+
const char* canon;
|
|
46
|
+
} words[] = {
|
|
47
|
+
{".inf", ".inf"}, {".Inf", ".inf"}, {".INF", ".inf"}, {"-.inf", "-.inf"},
|
|
48
|
+
{"-.Inf", "-.inf"}, {"-.INF", "-.inf"}, {"+.inf", ".inf"}, {"+.Inf", ".inf"},
|
|
49
|
+
{"+.INF", ".inf"}, {".nan", ".nan"}, {".NaN", ".nan"}, {".NAN", ".nan"},
|
|
50
|
+
};
|
|
51
|
+
for (size_t i = 0; i < sizeof(words) / sizeof(words[0]); i++) {
|
|
52
|
+
uint32_t wl = (uint32_t)strlen(words[i].word);
|
|
53
|
+
if (len == wl && memcmp(p, words[i].word, wl) == 0) {
|
|
54
|
+
return words[i].canon;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return NULL;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static int ci_eq(const char* p, uint32_t n, const char* s) {
|
|
61
|
+
uint32_t m = 0;
|
|
62
|
+
while (s[m] != '\0') {
|
|
63
|
+
m++;
|
|
64
|
+
}
|
|
65
|
+
if (n != m) {
|
|
66
|
+
return 0;
|
|
67
|
+
}
|
|
68
|
+
for (uint32_t k = 0; k < n; k++) {
|
|
69
|
+
char a = p[k], b = s[k];
|
|
70
|
+
if (a >= 'A' && a <= 'Z') {
|
|
71
|
+
a = (char)(a - 'A' + 'a');
|
|
72
|
+
}
|
|
73
|
+
if (b >= 'A' && b <= 'Z') {
|
|
74
|
+
b = (char)(b - 'A' + 'a');
|
|
75
|
+
}
|
|
76
|
+
if (a != b) {
|
|
77
|
+
return 0;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return 1;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
int yep_tag_bool_value(const char* p, uint32_t len) {
|
|
84
|
+
static const char* const words[8] = {"y", "yes", "true", "on", "n", "no", "false", "off"};
|
|
85
|
+
for (unsigned i = 0; i < 8; i++) {
|
|
86
|
+
if (ci_eq(p, len, words[i])) {
|
|
87
|
+
return i < 4 ? 1 : 0;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return -1;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/* One base-denominated digit with overflow detection (uint64 keeps
|
|
94
|
+
* the INT64_MIN magnitude representable). */
|
|
95
|
+
static int acc_digit(uint64_t* acc, int base, int dv) {
|
|
96
|
+
uint64_t na = *acc * (uint64_t)base;
|
|
97
|
+
if (na / (uint64_t)base != *acc) {
|
|
98
|
+
return 1;
|
|
99
|
+
}
|
|
100
|
+
na += (uint64_t)dv;
|
|
101
|
+
if (na < *acc) {
|
|
102
|
+
return 1;
|
|
103
|
+
}
|
|
104
|
+
*acc = na;
|
|
105
|
+
return 0;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
int yep_tag_int64(const char* p, uint32_t n, int compat, int64_t* out) {
|
|
109
|
+
uint32_t i = 0;
|
|
110
|
+
int neg = 0;
|
|
111
|
+
if (n == 0) {
|
|
112
|
+
return 1;
|
|
113
|
+
}
|
|
114
|
+
if (p[0] == '-' || p[0] == '+') {
|
|
115
|
+
neg = p[0] == '-';
|
|
116
|
+
i = 1;
|
|
117
|
+
if (i >= n) {
|
|
118
|
+
return 1;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/* radix prefixes first (both families, lowercase only — "0X1A"
|
|
122
|
+
* rides a string in core AND compat; 0o is core's spelling, 0b
|
|
123
|
+
* compat's), then compat's leading-0 octal, then the plain
|
|
124
|
+
* decimal/sexagesimal walk */
|
|
125
|
+
uint64_t acc = 0;
|
|
126
|
+
int digits = 0;
|
|
127
|
+
int base = 10;
|
|
128
|
+
uint32_t d = i;
|
|
129
|
+
if (n - i > 2 && p[i] == '0' && p[i + 1] == 'x') {
|
|
130
|
+
base = 16;
|
|
131
|
+
d = i + 2;
|
|
132
|
+
if (compat && p[d] == '_') {
|
|
133
|
+
d++;
|
|
134
|
+
if (p[d] == '_') {
|
|
135
|
+
return 1;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
} else if (n - i > 2 && p[i] == '0' && p[i + 1] == 'o') {
|
|
139
|
+
if (compat) {
|
|
140
|
+
return 1; /* 0o is not a compat form (psych) */
|
|
141
|
+
}
|
|
142
|
+
base = 8;
|
|
143
|
+
d = i + 2;
|
|
144
|
+
} else if (compat && n - i > 2 && p[i] == '0' && p[i + 1] == 'b') {
|
|
145
|
+
base = 2;
|
|
146
|
+
d = i + 2;
|
|
147
|
+
if (p[d] == '_') {
|
|
148
|
+
d++;
|
|
149
|
+
if (p[d] == '_') {
|
|
150
|
+
return 1;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
} else if (compat && p[i] == '0' && n - i >= 2) {
|
|
154
|
+
/* leading-0 octal (psych): 0[_]*[0-7][0-7_]* — the radix
|
|
155
|
+
* prefixes above never reach this arm */
|
|
156
|
+
base = 8;
|
|
157
|
+
d = i + 1;
|
|
158
|
+
while (d < n && p[d] == '_') {
|
|
159
|
+
d++;
|
|
160
|
+
}
|
|
161
|
+
if (d >= n) {
|
|
162
|
+
*out = 0; /* plain "0" / "000" */
|
|
163
|
+
return 0;
|
|
164
|
+
}
|
|
165
|
+
} else if (compat && p[i] == '0' && n - i == 1) {
|
|
166
|
+
*out = 0;
|
|
167
|
+
return 0;
|
|
168
|
+
} else if (compat && p[i] >= '0' && p[i] <= '9') {
|
|
169
|
+
/* sexagesimal int (compat only): d[d_,]*(:[0-5]?d){1,2} — the
|
|
170
|
+
* fractional form is float-tagged and never reaches here, but
|
|
171
|
+
* a '.' still refuses (the decode must not guess). '_' and ','
|
|
172
|
+
* are the compat separators (psych legacy). */
|
|
173
|
+
uint32_t k = i;
|
|
174
|
+
while (k < n && ((p[k] >= '0' && p[k] <= '9') || p[k] == '_' || p[k] == ',')) {
|
|
175
|
+
if (p[k] != '_' && p[k] != ',') {
|
|
176
|
+
if (acc_digit(&acc, 10, p[k] - '0')) {
|
|
177
|
+
return 1;
|
|
178
|
+
}
|
|
179
|
+
digits = 1;
|
|
180
|
+
}
|
|
181
|
+
k++;
|
|
182
|
+
}
|
|
183
|
+
if (k < n && p[k] == ':') {
|
|
184
|
+
while (k < n && p[k] == ':') {
|
|
185
|
+
k++;
|
|
186
|
+
int gd = 0;
|
|
187
|
+
int g = 0;
|
|
188
|
+
while (k < n && p[k] >= '0' && p[k] <= '9' && gd < 2) {
|
|
189
|
+
g = g * 10 + (p[k] - '0');
|
|
190
|
+
gd++;
|
|
191
|
+
k++;
|
|
192
|
+
}
|
|
193
|
+
if (gd < 1 || g > 59) {
|
|
194
|
+
return 1;
|
|
195
|
+
}
|
|
196
|
+
if (acc_digit(&acc, 60, g)) {
|
|
197
|
+
return 1;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (k == n) {
|
|
201
|
+
*out = neg ? -(int64_t)acc : (int64_t)acc;
|
|
202
|
+
return 0;
|
|
203
|
+
}
|
|
204
|
+
return 1;
|
|
205
|
+
}
|
|
206
|
+
/* a ':'-less digit span: the plain decimal path below would
|
|
207
|
+
* re-read it — answer directly */
|
|
208
|
+
if (k == n && digits) {
|
|
209
|
+
*out = neg ? -(int64_t)acc : (int64_t)acc;
|
|
210
|
+
return 0;
|
|
211
|
+
}
|
|
212
|
+
return 1;
|
|
213
|
+
}
|
|
214
|
+
acc = 0;
|
|
215
|
+
digits = 0;
|
|
216
|
+
for (uint32_t k = d; k < n; k++) {
|
|
217
|
+
char c = p[k];
|
|
218
|
+
int dv;
|
|
219
|
+
if (c >= '0' && c <= '9') {
|
|
220
|
+
dv = c - '0';
|
|
221
|
+
} else if (base == 16 && c >= 'a' && c <= 'f') {
|
|
222
|
+
dv = c - 'a' + 10;
|
|
223
|
+
} else if (base == 16 && c >= 'A' && c <= 'F') {
|
|
224
|
+
dv = c - 'A' + 10;
|
|
225
|
+
} else if (compat && (c == '_' || c == ',')) {
|
|
226
|
+
continue;
|
|
227
|
+
} else {
|
|
228
|
+
return 1;
|
|
229
|
+
}
|
|
230
|
+
if (base != 16 && dv >= base) {
|
|
231
|
+
return 1;
|
|
232
|
+
}
|
|
233
|
+
if (acc_digit(&acc, base, dv)) {
|
|
234
|
+
return 1;
|
|
235
|
+
}
|
|
236
|
+
digits = 1;
|
|
237
|
+
}
|
|
238
|
+
if (!digits) {
|
|
239
|
+
return 1;
|
|
240
|
+
}
|
|
241
|
+
if (neg && acc == (uint64_t)INT64_MAX + 1u) {
|
|
242
|
+
*out = INT64_MIN;
|
|
243
|
+
return 0;
|
|
244
|
+
}
|
|
245
|
+
if (acc > (uint64_t)INT64_MAX) {
|
|
246
|
+
return 1;
|
|
247
|
+
}
|
|
248
|
+
*out = neg ? -(int64_t)acc : (int64_t)acc;
|
|
249
|
+
return 0;
|
|
250
|
+
}
|