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.
Files changed (164) hide show
  1. checksums.yaml +7 -0
  2. data/README.adoc +150 -0
  3. data/ext/build_windows_native.rb +60 -0
  4. data/ext/libyeptris/extconf.rb +57 -0
  5. data/ext/yeptris_native/cbor_ruby.c +198 -0
  6. data/ext/yeptris_native/extconf.rb +99 -0
  7. data/ext/yeptris_native/json_ruby.c +414 -0
  8. data/ext/yeptris_native/version.h +29 -0
  9. data/ext/yeptris_native/yeptris_native.c +507 -0
  10. data/lib/yeptris/3.3/native.so +0 -0
  11. data/lib/yeptris/cbor.rb +169 -0
  12. data/lib/yeptris/document.rb +319 -0
  13. data/lib/yeptris/ffi.rb +572 -0
  14. data/lib/yeptris/json/descriptor.rb +266 -0
  15. data/lib/yeptris/json.rb +502 -0
  16. data/lib/yeptris/materializer.rb +389 -0
  17. data/lib/yeptris/node.rb +482 -0
  18. data/lib/yeptris/psych/class_loader.rb +24 -0
  19. data/lib/yeptris/psych/coder_shim.rb +55 -0
  20. data/lib/yeptris/psych/drop_in.rb +63 -0
  21. data/lib/yeptris/psych/encodable.rb +14 -0
  22. data/lib/yeptris/psych/handler.rb +95 -0
  23. data/lib/yeptris/psych/parser.rb +114 -0
  24. data/lib/yeptris/psych/scalar_scanner.rb +149 -0
  25. data/lib/yeptris/psych/tree_builder.rb +119 -0
  26. data/lib/yeptris/psych/visitors.rb +670 -0
  27. data/lib/yeptris/psych.rb +796 -0
  28. data/lib/yeptris/schema.rb +253 -0
  29. data/lib/yeptris/validation.rb +320 -0
  30. data/lib/yeptris/valueml.rb +477 -0
  31. data/lib/yeptris/yaml/descriptor.rb +56 -0
  32. data/lib/yeptris/yaml.rb +668 -0
  33. data/lib/yeptris.rb +130 -0
  34. data/libyeptris.so +0 -0
  35. data/vendor/libyeptris/CMakeLists.txt +280 -0
  36. data/vendor/libyeptris/cmake/yeptris-config.cmake.in +5 -0
  37. data/vendor/libyeptris/cmake/yeptris.pc.in +11 -0
  38. data/vendor/libyeptris/src/CMakeLists.txt +183 -0
  39. data/vendor/libyeptris/src/include/yeptris/api.h +32 -0
  40. data/vendor/libyeptris/src/include/yeptris/cbor.h +174 -0
  41. data/vendor/libyeptris/src/include/yeptris/dom.h +196 -0
  42. data/vendor/libyeptris/src/include/yeptris/emit.h +128 -0
  43. data/vendor/libyeptris/src/include/yeptris/error.h +42 -0
  44. data/vendor/libyeptris/src/include/yeptris/events.h +171 -0
  45. data/vendor/libyeptris/src/include/yeptris/json.h +57 -0
  46. data/vendor/libyeptris/src/include/yeptris/json.hpp +258 -0
  47. data/vendor/libyeptris/src/include/yeptris/jsonc_compat.h +115 -0
  48. data/vendor/libyeptris/src/include/yeptris/marshal.h +75 -0
  49. data/vendor/libyeptris/src/include/yeptris/parse.h +121 -0
  50. data/vendor/libyeptris/src/include/yeptris/plan.h +100 -0
  51. data/vendor/libyeptris/src/include/yeptris/resolve.h +81 -0
  52. data/vendor/libyeptris/src/include/yeptris/schema.h +121 -0
  53. data/vendor/libyeptris/src/include/yeptris/tape.h +128 -0
  54. data/vendor/libyeptris/src/include/yeptris/types.h +38 -0
  55. data/vendor/libyeptris/src/include/yeptris/validate.h +401 -0
  56. data/vendor/libyeptris/src/include/yeptris/values.h +108 -0
  57. data/vendor/libyeptris/src/include/yeptris/version.h.in +29 -0
  58. data/vendor/libyeptris/src/include/yeptris/visit.h +77 -0
  59. data/vendor/libyeptris/src/include/yeptris/yajl_compat.h +135 -0
  60. data/vendor/libyeptris/src/include/yeptris.h +24 -0
  61. data/vendor/libyeptris/src/yeptris/build.c +393 -0
  62. data/vendor/libyeptris/src/yeptris/cbor/cbor.h +35 -0
  63. data/vendor/libyeptris/src/yeptris/cbor/decode.c +1054 -0
  64. data/vendor/libyeptris/src/yeptris/cbor/encode.c +836 -0
  65. data/vendor/libyeptris/src/yeptris/cbor/encode_priv.h +32 -0
  66. data/vendor/libyeptris/src/yeptris/cbor/from_marshal.c +982 -0
  67. data/vendor/libyeptris/src/yeptris/cbor/sink.h +36 -0
  68. data/vendor/libyeptris/src/yeptris/common/chartype.c +41 -0
  69. data/vendor/libyeptris/src/yeptris/common/chartype.h +77 -0
  70. data/vendor/libyeptris/src/yeptris/common/cpu.c +81 -0
  71. data/vendor/libyeptris/src/yeptris/common/cpu.h +40 -0
  72. data/vendor/libyeptris/src/yeptris/common/error.c +65 -0
  73. data/vendor/libyeptris/src/yeptris/common/error.h +81 -0
  74. data/vendor/libyeptris/src/yeptris/common/mutex.h +45 -0
  75. data/vendor/libyeptris/src/yeptris/common/nametab.c +275 -0
  76. data/vendor/libyeptris/src/yeptris/common/nametab.h +68 -0
  77. data/vendor/libyeptris/src/yeptris/common/port.h +74 -0
  78. data/vendor/libyeptris/src/yeptris/common/simd_text.c +49 -0
  79. data/vendor/libyeptris/src/yeptris/common/simd_text.h +342 -0
  80. data/vendor/libyeptris/src/yeptris/common/simd_text_avx2.c +672 -0
  81. data/vendor/libyeptris/src/yeptris/common/simd_text_neon.c +793 -0
  82. data/vendor/libyeptris/src/yeptris/common/simd_text_scalar.c +324 -0
  83. data/vendor/libyeptris/src/yeptris/common/string_view.c +34 -0
  84. data/vendor/libyeptris/src/yeptris/common/string_view.h +93 -0
  85. data/vendor/libyeptris/src/yeptris/doc.h +86 -0
  86. data/vendor/libyeptris/src/yeptris/dom/dom.c +1312 -0
  87. data/vendor/libyeptris/src/yeptris/dom/dom.h +332 -0
  88. data/vendor/libyeptris/src/yeptris/dom/hpool.c +107 -0
  89. data/vendor/libyeptris/src/yeptris/dom/mapindex.c +173 -0
  90. data/vendor/libyeptris/src/yeptris/dom/mapindex.h +61 -0
  91. data/vendor/libyeptris/src/yeptris/dom/mutate.c +431 -0
  92. data/vendor/libyeptris/src/yeptris/dom/ytape.c +2323 -0
  93. data/vendor/libyeptris/src/yeptris/dom/ytape.h +96 -0
  94. data/vendor/libyeptris/src/yeptris/emit/emit.c +670 -0
  95. data/vendor/libyeptris/src/yeptris/emit/float/api.h +43 -0
  96. data/vendor/libyeptris/src/yeptris/emit/float/dragon.c +405 -0
  97. data/vendor/libyeptris/src/yeptris/emit/float/floatint.h +231 -0
  98. data/vendor/libyeptris/src/yeptris/emit/float/fpconv.c +428 -0
  99. data/vendor/libyeptris/src/yeptris/emit/float/print.c +396 -0
  100. data/vendor/libyeptris/src/yeptris/emit/style.c +21 -0
  101. data/vendor/libyeptris/src/yeptris/emit/style.h +32 -0
  102. data/vendor/libyeptris/src/yeptris/emit/writer.c +1951 -0
  103. data/vendor/libyeptris/src/yeptris/emit/writer.h +111 -0
  104. data/vendor/libyeptris/src/yeptris/encoding/bom.c +31 -0
  105. data/vendor/libyeptris/src/yeptris/encoding/encoding.h +63 -0
  106. data/vendor/libyeptris/src/yeptris/encoding/transcode.c +157 -0
  107. data/vendor/libyeptris/src/yeptris/encoding/utf8_validate.c +178 -0
  108. data/vendor/libyeptris/src/yeptris/events/capture.c +166 -0
  109. data/vendor/libyeptris/src/yeptris/events/capture.h +39 -0
  110. data/vendor/libyeptris/src/yeptris/events/iterparse.c +298 -0
  111. data/vendor/libyeptris/src/yeptris/events/pull.c +117 -0
  112. data/vendor/libyeptris/src/yeptris/events/push.c +151 -0
  113. data/vendor/libyeptris/src/yeptris/events/recorder.c +144 -0
  114. data/vendor/libyeptris/src/yeptris/events/values.c +630 -0
  115. data/vendor/libyeptris/src/yeptris/events/values_priv.h +53 -0
  116. data/vendor/libyeptris/src/yeptris/events/yaml_compat.c +86 -0
  117. data/vendor/libyeptris/src/yeptris/events/yaml_compat.h +90 -0
  118. data/vendor/libyeptris/src/yeptris/jsonapi/jsonc_compat.c +687 -0
  119. data/vendor/libyeptris/src/yeptris/jsonapi/yajl_compat.c +728 -0
  120. data/vendor/libyeptris/src/yeptris/marshal/to_json.c +650 -0
  121. data/vendor/libyeptris/src/yeptris/marshal.c +988 -0
  122. data/vendor/libyeptris/src/yeptris/memory/allocator.c +20 -0
  123. data/vendor/libyeptris/src/yeptris/memory/allocator.h +43 -0
  124. data/vendor/libyeptris/src/yeptris/memory/arena.c +150 -0
  125. data/vendor/libyeptris/src/yeptris/memory/arena.h +52 -0
  126. data/vendor/libyeptris/src/yeptris/memory/pool.c +133 -0
  127. data/vendor/libyeptris/src/yeptris/memory/pool.h +36 -0
  128. data/vendor/libyeptris/src/yeptris/parse/engine.c +6528 -0
  129. data/vendor/libyeptris/src/yeptris/parse/engine.h +96 -0
  130. data/vendor/libyeptris/src/yeptris/parse/events.h +137 -0
  131. data/vendor/libyeptris/src/yeptris/parse/numbers.c +374 -0
  132. data/vendor/libyeptris/src/yeptris/parse/numbers.h +33 -0
  133. data/vendor/libyeptris/src/yeptris/parse/scalars.c +435 -0
  134. data/vendor/libyeptris/src/yeptris/parse/scalars.h +87 -0
  135. data/vendor/libyeptris/src/yeptris/parse/stream_iter.c +358 -0
  136. data/vendor/libyeptris/src/yeptris/parse.c +1074 -0
  137. data/vendor/libyeptris/src/yeptris/plan.c +824 -0
  138. data/vendor/libyeptris/src/yeptris/resolve/compat11.c +339 -0
  139. data/vendor/libyeptris/src/yeptris/resolve/core12.c +153 -0
  140. data/vendor/libyeptris/src/yeptris/resolve/full12.c +201 -0
  141. data/vendor/libyeptris/src/yeptris/resolve/json12.c +109 -0
  142. data/vendor/libyeptris/src/yeptris/resolve/resolver.h +103 -0
  143. data/vendor/libyeptris/src/yeptris/resolve/tags.c +250 -0
  144. data/vendor/libyeptris/src/yeptris/scan/json.c +839 -0
  145. data/vendor/libyeptris/src/yeptris/scan/json.h +116 -0
  146. data/vendor/libyeptris/src/yeptris/scan/scan.c +862 -0
  147. data/vendor/libyeptris/src/yeptris/scan/scan.h +177 -0
  148. data/vendor/libyeptris/src/yeptris/schema.c +309 -0
  149. data/vendor/libyeptris/src/yeptris/tape.c +2375 -0
  150. data/vendor/libyeptris/src/yeptris/tape_in.h +39 -0
  151. data/vendor/libyeptris/src/yeptris/validate/compile.c +306 -0
  152. data/vendor/libyeptris/src/yeptris/validate/internal.h +347 -0
  153. data/vendor/libyeptris/src/yeptris/validate/jsonschema.c +1922 -0
  154. data/vendor/libyeptris/src/yeptris/validate/output.c +246 -0
  155. data/vendor/libyeptris/src/yeptris/validate/regexp.c +1600 -0
  156. data/vendor/libyeptris/src/yeptris/validate/registry.c +118 -0
  157. data/vendor/libyeptris/src/yeptris/validate/resources.c +601 -0
  158. data/vendor/libyeptris/src/yeptris/validate/stream.c +1155 -0
  159. data/vendor/libyeptris/src/yeptris/validate/validate.c +1043 -0
  160. data/vendor/libyeptris/src/yeptris/version.c +7 -0
  161. data/vendor/libyeptris/src/yeptris/visit/dom_visit.c +115 -0
  162. data/vendor/libyeptris/src/yeptris/visit/json_visit.c +293 -0
  163. data/vendor/libyeptris/src/yeptris/visit/yaml_visit.c +127 -0
  164. metadata +221 -0
@@ -0,0 +1,96 @@
1
+ /* engine.h — the one parser engine (TODO.impl/07).
2
+ *
3
+ * Non-recursive block machine + iterative flow kernel, producing events
4
+ * into any sink (DOM builder today; pull/recorder in 12). v1 runs the
5
+ * whole buffer in one call; resumable stepping lands with 12's streaming
6
+ * (recorded as the item's open phase). Depth guard rejects pathological
7
+ * nesting with an error, never a crash.
8
+ */
9
+ #ifndef YEP_ENGINE_H
10
+ #define YEP_ENGINE_H
11
+
12
+ #include "common/error.h"
13
+ #include "common/simd_text.h"
14
+
15
+ #include "memory/allocator.h"
16
+ #include "memory/pool.h"
17
+ #include "parse/events.h"
18
+
19
+ #ifdef __cplusplus
20
+ extern "C" {
21
+ #endif
22
+
23
+ /* Pinned by Parse.NormBreakLeadsMatchRuntimeBuild (test_parse.cpp). */
24
+ extern const yep_stopset yep_norm_break_leads;
25
+
26
+ typedef struct yep_engine yep_engine;
27
+
28
+ yep_engine* yep_engine_create(const yep_allocator* sys);
29
+ void yep_engine_destroy(yep_engine* e);
30
+
31
+ /* Parses [buf, buf+len) — must be validated UTF-8 (05). Returns 0 on
32
+ * success, -1 on parse error (see yep_engine_error), -2 sink abort. */
33
+ int yep_engine_run(yep_engine* e, const char* buf, size_t len, const yep_sink* sink);
34
+
35
+ /* Content-derived pre-sizing before run(): reserves the anchor interner
36
+ * from the stream's '&' occurrences (every anchor definition carries
37
+ * exactly one, so the count never undershoots). */
38
+ void yep_engine_prepare(yep_engine* e, const yep_text_stats* st);
39
+ /* the caller already BOM-sniffed/transcoded the bytes (parse.c,
40
+ * values.c): the engine must not re-strip a content U+FEFF */
41
+ void yep_engine_front_done(yep_engine* e);
42
+
43
+ /* Resumable stepping (TODO.impl/07): chunks accumulate; every feed
44
+ * parses the complete DOCUMENTS received so far (cut at `---` / `...`
45
+ * boundaries at column 0, outside quotes and flow) and keeps the
46
+ * trailing partial document buffered. final != 0 flushes it and ends
47
+ * the stream. STREAM markers bracket the whole stepped stream, not
48
+ * each step; each document's events arrive exactly once, in order.
49
+ * Returns 0, -1 parse error, -2 sink abort. */
50
+ int yep_engine_step(yep_engine* e, const char* chunk, size_t len, int final, const yep_sink* sink);
51
+
52
+ /* Detaches the finish pool (ownership moves to the caller; the engine
53
+ * allocates a fresh one if reused). Returns NULL when absent. */
54
+ yep_pool* yep_engine_detach_pool(yep_engine* e);
55
+
56
+ /* Detaches the run's break-normalizer copy (ownership moves to the
57
+ * caller; the caller owns the returned buffer once detached). Returns
58
+ * NULL when the run kept the input zero-copy. */
59
+ char* yep_engine_detach_norm_buf(yep_engine* e, size_t* len_out);
60
+
61
+ /* Implicit-typing schema for the next run (NULL: 1.2 core), and the
62
+ * runtime nesting limit. */
63
+ struct yep_resolver;
64
+ void yep_engine_set_resolver(yep_engine* e, const struct yep_resolver* r);
65
+ void yep_engine_set_max_depth(yep_engine* e, int depth);
66
+
67
+ /* The 1.1-compat grammar (libyaml/psych parity): the block-level flow
68
+ * indent floor (9C9N, VJP3) is a yaml-test-suite rule libyaml never
69
+ * enforced — real-world locale files close multi-line flow collections
70
+ * at their parent's column ("k: {\n a: b\n}"). Off by default (the
71
+ * strict 1.2 engine the conformance suite runs keeps the floor). */
72
+ void yep_engine_set_compat_grammar(yep_engine* e, int on);
73
+
74
+ /* Byte offset the last run reached (into that run's buffer); used by
75
+ * consumers that stop the engine at a boundary and resume. */
76
+ size_t yep_engine_pos(const yep_engine* e);
77
+
78
+ const yep_error* yep_engine_error(const yep_engine* e);
79
+
80
+ /* The NEL/LS/PS -> '\n' copy; NULL when the input is clean (probe rides
81
+ * the stopset kernel). One-shot parse runs this BEFORE the engine so
82
+ * the copy owns the document's transcoded slot; the engine's per-feed
83
+ * copy (norm_buf) stays for the streaming feeds. */
84
+ /* kept_raw (nullable) reports whether raw NEL/LS/PS SURVIVED the
85
+ * quote-aware walk (they ride inside quoted regions). The packed-tape
86
+ * fused runner predates the multibyte break cut — a document still
87
+ * carrying raw sequences parses on the engine route instead (the
88
+ * nightly's r75). */
89
+ char* yep_engine_normalize_breaks(const yep_allocator* sys, const char* p, size_t len,
90
+ size_t* out_len, int* kept_raw);
91
+
92
+ #ifdef __cplusplus
93
+ }
94
+ #endif
95
+
96
+ #endif /* YEP_ENGINE_H */
@@ -0,0 +1,137 @@
1
+ /* events.h — the one grammar vocabulary (TODO.impl/07).
2
+ *
3
+ * Every consumption model (DOM builder, pull, push, recorder — 11/12) is
4
+ * a sink over these events; the engine knows none of them (OCP). Values
5
+ * are borrowed either from the input buffer or from the engine's finish
6
+ * pool (folded/escaped content) — `borrowed` says which, so the DOM
7
+ * builder copies exactly what must outlive the engine.
8
+ */
9
+ #ifndef YEP_EVENTS_H
10
+ #define YEP_EVENTS_H
11
+
12
+ #include "common/string_view.h"
13
+
14
+ #ifdef __cplusplus
15
+ extern "C" {
16
+ #endif
17
+
18
+ typedef enum {
19
+ YEP_EV_NONE = 0,
20
+ YEP_EV_STREAM_START,
21
+ YEP_EV_STREAM_END,
22
+ YEP_EV_DOCUMENT_START,
23
+ YEP_EV_DOCUMENT_END,
24
+ YEP_EV_SEQ_START,
25
+ YEP_EV_SEQ_END,
26
+ YEP_EV_MAP_START,
27
+ YEP_EV_MAP_END,
28
+ YEP_EV_SCALAR,
29
+ YEP_EV_ALIAS,
30
+ } yep_event_type;
31
+
32
+ /* Mirrors libyaml's style set — the wire vocabulary of 12's compat layer. */
33
+ typedef enum {
34
+ YEP_STYLE_ANY = 0,
35
+ YEP_STYLE_PLAIN,
36
+ YEP_STYLE_SINGLE_QUOTED,
37
+ YEP_STYLE_DOUBLE_QUOTED,
38
+ YEP_STYLE_LITERAL,
39
+ YEP_STYLE_FOLDED,
40
+ } yep_scalar_style;
41
+
42
+ typedef struct yep_event {
43
+ yep_event_type type;
44
+ yep_view value; /* scalar content / alias name */
45
+ yep_view anchor; /* node properties, empty when absent */
46
+ yep_view tag;
47
+ uint8_t style; /* yep_scalar_style */
48
+ uint8_t implicit; /* scalar written without quotes/tag (plain implicit) */
49
+ uint8_t flow; /* collection opened in flow context */
50
+ uint8_t multiline; /* scalar spanned lines: may not be a simple key */
51
+ uint8_t tag_id; /* resolved implicit/explicit tag (resolve/resolver.h) */
52
+ uint8_t borrowed; /* 1: value borrows the INPUT; 0: engine finish pool */
53
+ uint32_t anchor_id; /* 1-based anchor ordinal (the engine's serial);
54
+ * on ALIAS: the TARGET's ordinal. 0 = none. Sinks
55
+ * that key on it skip the name hash entirely. */
56
+ uint32_t line; /* 1-based position of the node start */
57
+ uint32_t col;
58
+ uint32_t end_line; /* #179: 1-based position of the node's end —
59
+ * libyaml's end_mark semantics: a START event
60
+ * ends after its opening token, a scalar/alias
61
+ * spans anchor/tag through content, an END
62
+ * event spans its closing indicator */
63
+ uint32_t end_col;
64
+ } yep_event;
65
+
66
+ struct yep_block_value; /* value facts for on_block_pair (below) */
67
+
68
+ typedef struct yep_sink {
69
+ /* Returns 0 to continue, nonzero to abort the parse (sink error). */
70
+ int (*on_event)(void* ctx, const yep_event* ev);
71
+ void* ctx;
72
+ /* Fused flow fast path (TODO.restructure/53): validate AND build
73
+ * the span at p[open..len) in ONE walk (the grammar walker is
74
+ * scan/json.c's SSOT). Returns 1 = built and staged, *close set —
75
+ * the engine runs its close-based grammar checks next, then
76
+ * COMMITS or ROLLS BACK; 2 = grammar-valid but a map key exceeds
77
+ * the simple-key limit (nothing staged; the engine's pass 2 owns
78
+ * that error); 0 = not JSON-class (nothing staged; the general
79
+ * kernel); <0 = abort. Sinks that consume events (pull/push/
80
+ * recorder) leave the trio NULL. */
81
+ int (*on_flow_build)(void* ctx, const char* p, size_t open, size_t len, uint32_t line,
82
+ size_t line_start, yep_view anchor, yep_view tag, uint32_t anchor_id,
83
+ int max_depth, size_t* close);
84
+ int (*on_flow_commit)(void* ctx);
85
+ void (*on_flow_rollback)(void* ctx);
86
+ /* Optional block fast path (TODO.restructure/54): the engine's
87
+ * classified KEY arm offers the whole line pair — key scalar plus
88
+ * a classified value — before emitting any event. line/cols are
89
+ * the engine's position facts. Return 1 = both nodes built and
90
+ * placed, 0 = not handled (the engine emits the two events
91
+ * exactly as before), <0 = abort. */
92
+ int (*on_block_pair)(void* ctx, const yep_view* key, const struct yep_block_value* v,
93
+ uint32_t line, uint32_t key_col, uint32_t val_col);
94
+ /* Optional block-open fast path (TODO.restructure/57): a `key:`
95
+ * line whose value lives on FOLLOWING lines, when the engine is
96
+ * about to open a FRESH mapping. 1 = the sink built the map node
97
+ * (placed, stack pushed) and the key node — the engine opens its
98
+ * frame silently and skips both events; 0 = events as before. */
99
+ int (*on_block_open)(void* ctx, const yep_view* key, uint32_t line, uint32_t key_col);
100
+ /* Optional dash-item fast path (TODO.restructure/78): a classified
101
+ * `- value` plain item after the engine opened (or continued) the
102
+ * block sequence. 1 = the sink built and placed the item node,
103
+ * 0 = the engine emits the scalar event as before, <0 = abort. */
104
+ int (*on_block_item)(void* ctx, const struct yep_block_value* v);
105
+
106
+ /* Direct scalar path (TODO.restructure/79): the same node the
107
+ * YEP_EV_SCALAR event builds, minus the event seam — emit_now
108
+ * resolves the tag first (the typing SSOT stays in the engine)
109
+ * and calls here when present. NULL = the event path, unchanged. */
110
+ int (*on_scalar)(void* ctx, const struct yep_view* value, const struct yep_view* tag,
111
+ const struct yep_view* anchor, uint32_t anchor_id, uint8_t tag_id,
112
+ uint8_t style, uint8_t implicit, uint8_t flow, int borrowed);
113
+ /* Document composers (libyaml's scanner/composer split): the
114
+ * scanner emits the ALIAS event for ANY name, while a sink that
115
+ * builds a document rejects an alias whose target is undefined or
116
+ * not yet placed ("found undefined alias"). Set for the DOM and
117
+ * record-tape routes; event consumers (recorder/pull/push) leave
118
+ * it 0 so their streams carry every alias like libyaml's. */
119
+ uint8_t compose;
120
+ } yep_sink;
121
+
122
+ /* Value facts for on_block_pair (the classified value classes the
123
+ * block arms own; spans are input-borrowed). */
124
+ typedef struct yep_block_value {
125
+ uint8_t cls; /* YEP_LVAL_PLAIN / _ALIAS / _ANCHOR_PLAIN */
126
+ uint8_t borrowed; /* 1: value borrows the input; 0: engine pool */
127
+ yep_view value; /* scalar content / alias name */
128
+ yep_view anchor; /* _ANCHOR_PLAIN: the &name span */
129
+ uint32_t anchor_id; /* engine ordinal: the definition (_ANCHOR_)
130
+ * or the resolved TARGET (_ALIAS_) */
131
+ } yep_block_value;
132
+
133
+ #ifdef __cplusplus
134
+ }
135
+ #endif
136
+
137
+ #endif /* YEP_EVENTS_H */
@@ -0,0 +1,374 @@
1
+ /* numbers.c — the typed-value conversion kernels (TODO.impl/08B).
2
+ *
3
+ * Extracted verbatim from parse.c's node accessors: behavior is
4
+ * pinned by the typed-accessor spec battery and the 20k randomized
5
+ * strtod cross-checks. */
6
+
7
+ #include <errno.h>
8
+ #include <limits.h>
9
+ #include <math.h>
10
+ #include <stdlib.h>
11
+ #include <string.h>
12
+
13
+ #include "numbers.h"
14
+
15
+ #define NUM_BUF 80
16
+
17
+ /* strips '_' and ',' into a NUL-terminated stack buffer; returns the
18
+ * cleaned length (the raw length when nothing needed stripping —
19
+ * callers then use the original bytes) */
20
+ static size_t num_clean(const char* p, uint32_t len, char* buf) {
21
+ if (memchr(p, '_', len) == NULL && memchr(p, ',', len) == NULL) {
22
+ return len; /* caller reads p directly */
23
+ }
24
+ size_t o = 0;
25
+ for (uint32_t i = 0; i < len && o + 1 < NUM_BUF; i++) {
26
+ char c = p[i];
27
+ if (c == '_' || c == ',') {
28
+ continue;
29
+ }
30
+ buf[o++] = c;
31
+ }
32
+ buf[o] = '\0';
33
+ return o;
34
+ }
35
+
36
+ /* Clinger-bounded exact decimal: mantissa < 2^53, adjusted
37
+ * exponent within +-22 — 23-entry pow10 table (08B) */
38
+ static const double k_pow10[23] = {
39
+ 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11,
40
+ 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, 1e20, 1e21, 1e22,
41
+ };
42
+
43
+ static int fast_double(const char* s, size_t len, double* out) {
44
+ size_t i = 0;
45
+ int neg = 0;
46
+ if (i < len && (s[i] == '-' || s[i] == '+')) {
47
+ neg = s[i] == '-';
48
+ i++;
49
+ }
50
+ uint64_t m = 0;
51
+ int digits = 0;
52
+ int dot = -1;
53
+ for (; i < len; i++) {
54
+ char c = s[i];
55
+ if (c == '.') {
56
+ if (dot >= 0) {
57
+ return 0;
58
+ }
59
+ dot = (int)digits;
60
+ continue;
61
+ }
62
+ if (c < '0' || c > '9') {
63
+ break;
64
+ }
65
+ if (digits >= 15) {
66
+ return 0; /* outside the exact range */
67
+ }
68
+ m = m * 10u + (uint64_t)(c - '0');
69
+ digits++;
70
+ }
71
+ if (digits == 0 || (i < len && s[i] != 'e' && s[i] != 'E')) {
72
+ return 0; /* empty mantissa or trailing junk */
73
+ }
74
+ int e10 = 0;
75
+ if (i < len) {
76
+ i++; /* e/E */
77
+ int eneg = 0;
78
+ if (i < len && (s[i] == '-' || s[i] == '+')) {
79
+ eneg = s[i] == '-';
80
+ i++;
81
+ }
82
+ if (i >= len) {
83
+ return 0;
84
+ }
85
+ for (; i < len; i++) {
86
+ if (s[i] < '0' || s[i] > '9') {
87
+ return 0;
88
+ }
89
+ e10 = e10 * 10 + (s[i] - '0');
90
+ if (e10 > 308) {
91
+ return 0;
92
+ }
93
+ }
94
+ if (eneg) {
95
+ e10 = -e10;
96
+ }
97
+ }
98
+ if (dot >= 0) {
99
+ e10 -= digits - dot;
100
+ }
101
+ if (e10 > 22 || e10 < -22 || m >= (1ull << 53)) {
102
+ return 0; /* outside Clinger's exact range */
103
+ }
104
+ if (e10 >= 0) {
105
+ double v = (double)m * k_pow10[e10];
106
+ *out = neg ? -v : v;
107
+ } else {
108
+ double v = (double)m / k_pow10[-e10];
109
+ *out = neg ? -v : v;
110
+ }
111
+ return 1;
112
+ }
113
+
114
+ int yep_num_i64(const char* p, uint32_t len, int64_t* out) {
115
+ if (p == NULL || len == 0) {
116
+ return 1;
117
+ }
118
+ char buf[NUM_BUF];
119
+ size_t l = num_clean(p, len, buf);
120
+ const char* num =
121
+ (l == len && memchr(p, '_', len) == NULL && memchr(p, ',', len) == NULL) ? p : buf;
122
+ if (num != p) {
123
+ /* cleaned copy already NUL-terminated by num_clean */
124
+ } else {
125
+ if (l >= NUM_BUF) {
126
+ return 1;
127
+ }
128
+ memcpy(buf, num, l);
129
+ buf[l] = '\0';
130
+ num = buf;
131
+ }
132
+ int base = 10;
133
+ const char* s = buf;
134
+ if (buf[0] == '-' || buf[0] == '+') {
135
+ s++;
136
+ }
137
+ if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) {
138
+ base = 16;
139
+ } else if (s[0] == '0' && (s[1] == 'b' || s[1] == 'B')) {
140
+ base = 2;
141
+ } else if (s[0] == '0' && s[1] == 'o') {
142
+ memmove(buf + (size_t)(s - buf) + 1, s + 2, l - (size_t)(s - buf) - 1);
143
+ l -= 1;
144
+ buf[l] = '\0';
145
+ base = 8; /* 0o17 -> 017 octal */
146
+ } else if (s[0] == '0' && s[1] != '\0' && s[1] != '.') {
147
+ base = 8; /* compat leading-0 octal */
148
+ }
149
+ if (memchr(buf, ':', l) != NULL) {
150
+ /* Psych's sexagesimal fold, verbatim (scalar_scanner.rb):
151
+ * component e weighs 60 ** |e - 2| and the SIGN rides the
152
+ * first component only (-1:30 -> -3600 + 1800 = -1800, not
153
+ * -5400). A 2-component value is H:M, seconds implicitly
154
+ * zero (1:30 -> 5400). TODO.restructure/43 / issue #30. */
155
+ const char* q = buf;
156
+ long long sign = 1;
157
+ if (q[0] == '-' || q[0] == '+') {
158
+ if (q[0] == '-')
159
+ sign = -1;
160
+ q++;
161
+ }
162
+ long long v = 0;
163
+ while (*q >= '0' && *q <= '9') {
164
+ int d = *q - '0';
165
+ /* the ERANGE law, spelled out: the plain path rejects
166
+ * unrepresentable values via strtoll, so the fold must
167
+ * too (UBSan: 2222222222222222222 * 10 overflowed, the
168
+ * nightly's round on the combined build) */
169
+ if (v > (LLONG_MAX - (long long)d) / 10) {
170
+ return 1;
171
+ }
172
+ v = v * 10 + d;
173
+ q++;
174
+ }
175
+ if (v > LLONG_MAX / 3600) {
176
+ return 1;
177
+ }
178
+ v *= 3600; /* e0 weight */
179
+ if (sign < 0)
180
+ v = -v;
181
+ int groups = 0;
182
+ while (*q == ':' && groups < 2) {
183
+ q++;
184
+ long long g = 0;
185
+ int d = 0;
186
+ while (*q >= '0' && *q <= '9') {
187
+ int dg = *q - '0';
188
+ /* the group component rides the same ERANGE law as
189
+ * the first component -- the catch-124 fix guarded
190
+ * the hours loop but left this one raw (UBSan:
191
+ * 999999999999999999 * 10, the nightly's run
192
+ * 39049702014) */
193
+ if (g > (LLONG_MAX - (long long)dg) / 10) {
194
+ return 1;
195
+ }
196
+ g = g * 10 + dg;
197
+ q++;
198
+ d++;
199
+ }
200
+ if (d == 0) {
201
+ return 1;
202
+ }
203
+ long long w = groups == 0 ? 60 : 1; /* e1 then e2 */
204
+ if (g > LLONG_MAX / w || v > LLONG_MAX - g * w) {
205
+ return 1;
206
+ }
207
+ v += g * w;
208
+ groups++;
209
+ }
210
+ if (groups == 0 || *q != '\0') {
211
+ return 1;
212
+ }
213
+ *out = v;
214
+ return 0;
215
+ }
216
+ char* end = NULL;
217
+ errno = 0;
218
+ long long v = strtoll(buf, &end, base);
219
+ if (end == buf || *end != '\0' || errno == ERANGE) {
220
+ return 1;
221
+ }
222
+ *out = (int64_t)v;
223
+ return 0;
224
+ }
225
+
226
+ int yep_num_f64(const char* p, uint32_t len, double* out) {
227
+ if (p == NULL || len == 0) {
228
+ return 1;
229
+ }
230
+ char buf[NUM_BUF];
231
+ size_t l = num_clean(p, len, buf);
232
+ const char* num =
233
+ (l == len && memchr(p, '_', len) == NULL && memchr(p, ',', len) == NULL) ? p : buf;
234
+ /* 08B fast path: the common decimal shape converts exactly with
235
+ * integer arithmetic; everything else falls to strtod */
236
+ {
237
+ double fast;
238
+ if (fast_double(num, l, &fast)) {
239
+ *out = fast;
240
+ return 0;
241
+ }
242
+ }
243
+ if (num != p) {
244
+ /* cleaned copy is NUL-terminated */
245
+ } else {
246
+ if (l >= NUM_BUF) {
247
+ return 1;
248
+ }
249
+ memcpy(buf, num, l);
250
+ buf[l] = '\0';
251
+ num = buf;
252
+ }
253
+ /* .inf / .nan family (sign allowed on inf) */
254
+ {
255
+ const char* s = buf;
256
+ size_t sl = l;
257
+ if (s[0] == '-' || s[0] == '+') {
258
+ s++;
259
+ sl--;
260
+ }
261
+ if (sl == 4 && s[0] == '.') {
262
+ if ((s[1] == 'i' || s[1] == 'I') && (s[2] == 'n' || s[2] == 'N') &&
263
+ (s[3] == 'f' || s[3] == 'F')) {
264
+ *out = (buf[0] == '-') ? -INFINITY : INFINITY;
265
+ return 0;
266
+ }
267
+ if ((s[1] == 'n' || s[1] == 'N') && (s[2] == 'a' || s[2] == 'A') &&
268
+ (s[3] == 'n' || s[3] == 'N')) {
269
+ *out = NAN;
270
+ return 0;
271
+ }
272
+ }
273
+ }
274
+ /* sexagesimal float — Psych's fold: weights 60**|e-2|, sign on
275
+ * the first component, the fraction on the LAST component
276
+ * (1:30.5 -> 1*3600 + 30.5*60 = 5430.0). */
277
+ if (memchr(buf, ':', l) != NULL) {
278
+ const char* s = buf;
279
+ double sign = 1.0;
280
+ if (s[0] == '-' || s[0] == '+') {
281
+ if (s[0] == '-')
282
+ sign = -1.0;
283
+ s++;
284
+ }
285
+ double v = 0.0;
286
+ const char* q = s;
287
+ while (*q >= '0' && *q <= '9') {
288
+ v = v * 10.0 + (*q - '0');
289
+ q++;
290
+ }
291
+ v *= 3600.0;
292
+ v *= sign;
293
+ int groups = 0;
294
+ double last = 0.0;
295
+ double weight = 60.0;
296
+ for (;;) {
297
+ if (*q != ':' || groups >= 2)
298
+ break;
299
+ q++;
300
+ double g = 0.0;
301
+ int d = 0;
302
+ while (*q >= '0' && *q <= '9') {
303
+ g = g * 10.0 + (*q - '0');
304
+ q++;
305
+ d++;
306
+ }
307
+ if (d == 0) {
308
+ return 1;
309
+ }
310
+ if (*q == '.') {
311
+ double frac = 0.0, scale = 0.1;
312
+ q++;
313
+ while (*q >= '0' && *q <= '9') {
314
+ frac += (*q - '0') * scale;
315
+ scale /= 10.0;
316
+ q++;
317
+ }
318
+ g += frac;
319
+ }
320
+ v += g * weight;
321
+ weight = 1.0; /* e2 */
322
+ last = g;
323
+ groups++;
324
+ }
325
+ (void)last;
326
+ if (groups == 0 || *q != '\0') {
327
+ return 1;
328
+ }
329
+ *out = v;
330
+ return 0;
331
+ }
332
+ char* end = NULL;
333
+ errno = 0;
334
+ double v = strtod(buf, &end);
335
+ if (end == buf || *end != '\0') {
336
+ return 1;
337
+ }
338
+ (void)errno;
339
+ *out = v;
340
+ return 0;
341
+ }
342
+
343
+ int yep_num_bool(const char* p, uint32_t len) {
344
+ static const char* k_true[] = {"true", "True", "TRUE", "y", "Y", "yes",
345
+ "Yes", "YES", "on", "On", "ON"};
346
+ for (size_t i = 0; i < sizeof(k_true) / sizeof(k_true[0]); i++) {
347
+ size_t m = strlen(k_true[i]);
348
+ if (len == m && memcmp(p, k_true[i], m) == 0) {
349
+ return 1;
350
+ }
351
+ }
352
+ return 0;
353
+ }
354
+
355
+ int yep_num_bool_ci(const char* p, uint32_t len) {
356
+ /* the compat resolver matches bool words case-insensitively;
357
+ * truth follows the same rule (Psych's scanner downcases) */
358
+ static const char* k_true[] = {"y", "yes", "true", "on"};
359
+ char buf[8];
360
+ if (len == 0 || len > 5) {
361
+ return 0;
362
+ }
363
+ for (uint32_t i = 0; i < len; i++) {
364
+ char c = p[i];
365
+ buf[i] = (c >= 'A' && c <= 'Z') ? (char)(c + 32) : c;
366
+ }
367
+ for (size_t i = 0; i < sizeof(k_true) / sizeof(k_true[0]); i++) {
368
+ size_t m = strlen(k_true[i]);
369
+ if (len == m && memcmp(buf, k_true[i], m) == 0) {
370
+ return 1;
371
+ }
372
+ }
373
+ return 0;
374
+ }
@@ -0,0 +1,33 @@
1
+ /* numbers.h — the typed-value conversion kernels (TODO.impl/08B).
2
+ *
3
+ * ONE home for text->int64/double/bool: the node typed accessors,
4
+ * the value stream (values.c), and any future consumer ride these.
5
+ * Pure functions over (pointer, length) — no handles, no state. */
6
+ #ifndef YEP_NUMBERS_H
7
+ #define YEP_NUMBERS_H
8
+
9
+ #include <stdint.h>
10
+ #include <yeptris/api.h>
11
+
12
+ #ifdef __cplusplus
13
+ extern "C" {
14
+ #endif
15
+
16
+ /* Separator-carrying YAML number text (digits, '_', ','; radix
17
+ * forms 0x/0o/0b/leading-0; sexagesimal for the compat schema).
18
+ * Returns 0 and sets *out on success, nonzero otherwise. */
19
+ YEPTRIS_API int yep_num_i64(const char* p, uint32_t len, int64_t* out);
20
+ YEPTRIS_API int yep_num_f64(const char* p, uint32_t len, double* out);
21
+
22
+ /* The resolver's true-word set (true/True/TRUE/y/Y/yes/Yes/YES/on/
23
+ * On/ON); anything else the BOOL tag accepted is false. */
24
+ YEPTRIS_API int yep_num_bool(const char* p, uint32_t len);
25
+
26
+ /* Case-insensitive truth (the compat resolver's matching rule). */
27
+ YEPTRIS_API int yep_num_bool_ci(const char* p, uint32_t len);
28
+
29
+ #ifdef __cplusplus
30
+ }
31
+ #endif
32
+
33
+ #endif /* YEP_NUMBERS_H */