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,477 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yeptris
4
+ # Value-stream materialization (TODO.impl/15 phase F): one drain of
5
+ # PRE-CONVERTED typed values from the C side, then a minimal Ruby
6
+ # walk — no per-scalar parsing (the number kernels already ran),
7
+ # key/value pairing rides the entries' is_key bit, anchors arrive
8
+ # as uniform entries decorating the value they bind. The Psych
9
+ # quirks re-decide from tag_id + the raw bytes every entry carries.
10
+ module ValueML
11
+ DOC = 0
12
+ V_NULL = 1
13
+ V_BOOL = 2
14
+ V_INT = 3
15
+ V_FLOAT = 4
16
+ V_STR = 5
17
+
18
+ # Psych's integer shape (scalar_scanner): sign optional, no
19
+ # leading zero, '_' / ',' separators only between digits. Beyond
20
+ # int64 the C resolver leaves the scalar a string; Psych
21
+ # materializes Integer (issue #31) — every walk rebuilds it.
22
+ PSYCH_INT_SHAPE = /\A[-+]?(?:0|[1-9](?:[0-9]|,[0-9]|_[0-9])*)\z/.freeze
23
+
24
+ # The typed-string conversion law, ONE place: a big-int-shaped
25
+ # string rebuilds to Integer, an implicit-plain ':name' scans to a
26
+ # Symbol (Psych's ScalarScanner; quoted ':x' stays a String).
27
+ # Every str-column conversion rides this — the pair fast path
28
+ # drifted once and handed bignums/symbol-keys through as Strings
29
+ # (audit 2026-10-31). The Symbol arm rides Materializer.resolve_symbol
30
+ # (#1304: the quoted literal form strips its quoting).
31
+ def self.str_to_value(text, typed)
32
+ return text unless typed
33
+
34
+ if text.length > 18 && PSYCH_INT_SHAPE.match?(text)
35
+ text.delete(",_").to_i
36
+ elsif text.length > 1 && text.start_with?(":") && !text.start_with?("::")
37
+ ::Yeptris::Materializer.resolve_symbol(text)
38
+ else
39
+ text
40
+ end
41
+ end
42
+
43
+ # A quoted-symbol literal's byte fingerprint: the plain text of
44
+ # `:"x y"` / `:'q z'` carries the colon DIRECTLY followed by a
45
+ # quote. A source that contains it may name a quoted symbol, and
46
+ # the C marshal builder names symbols from the raw scalar text —
47
+ # it strips the leading colon but keeps the quotes (engine finding,
48
+ # #1304). The binding refuses the marshal lane for such sources and
49
+ # walks in Ruby, where the strip law lives; when the engine strip
50
+ # lands, the lane reopens by relaxing this one predicate.
51
+ QUOTED_SYMBOL_TEXT = /:(["'])/.freeze
52
+
53
+ def self.marshal_lane_ok?(source)
54
+ !QUOTED_SYMBOL_TEXT.match?(source)
55
+ end
56
+
57
+ V_TS = 6
58
+ SEQ_OPEN = 7
59
+ MAP_OPEN = 8
60
+ CLOSE = 9
61
+ ALIAS = 10
62
+ ANCHOR = 11
63
+
64
+ FIELDS = 7
65
+ VALUE_SIZE = 24
66
+ # kind, tag, is_key, b | off, len | pad4 | payload (INT/FLOAT bits)
67
+ UNPACK = "C4V2x4q<"
68
+
69
+ module_function
70
+
71
+ def load_all(yaml, schema: :compat_11)
72
+ yaml = Yeptris.read_input(yaml)
73
+ yaml = yaml.to_s
74
+ vals_p = ::FFI::MemoryPointer.new(:pointer)
75
+ count_p = ::FFI::MemoryPointer.new(:size_t)
76
+ arena_p = ::FFI::MemoryPointer.new(:pointer)
77
+ alen_p = ::FFI::MemoryPointer.new(:size_t)
78
+ st = FFI.yeptris_value_drain(
79
+ yaml, yaml.bytesize,
80
+ schema == :compat_11 ? FFI::SCHEMA_11_COMPAT : FFI::SCHEMA_12_CORE,
81
+ vals_p, count_p, arena_p, alen_p
82
+ )
83
+ raise ParseError, FFI.last_error_message if st != FFI::OK
84
+
85
+ vals = vals_p.read_pointer
86
+ arena = arena_p.read_pointer
87
+ begin
88
+ count = Yeptris::FFI.read_c_size_t(count_p)
89
+ flat = vals.read_bytes(count * VALUE_SIZE).unpack(UNPACK * count)
90
+ arena_bytes = arena.read_bytes(Yeptris::FFI.read_c_size_t(alen_p))
91
+ arena_bytes.force_encoding(Encoding::UTF_8)
92
+ walk(flat, arena_bytes, schema == :compat_11)
93
+ ensure
94
+ FFI.yeptris_value_free(vals, arena)
95
+ end
96
+ end
97
+
98
+ # Columnar path (libyeptris > 0.1.1): whole columns unpack in one
99
+ # call each, and the walk indexes tight arrays (no 7-slot stride).
100
+ # Semantics are IDENTICAL to the record walk — the two bodies are
101
+ # maintained in lockstep; field-access shape is the only difference.
102
+ def load_all_columns(yaml, schema: :compat_11)
103
+ yaml = Yeptris.read_input(yaml)
104
+ yaml = yaml.to_s
105
+ cols = FFI::ValueColumns.new
106
+ st = FFI.yeptris_value_drain_columns(
107
+ yaml, yaml.bytesize,
108
+ schema == :compat_11 ? FFI::SCHEMA_11_COMPAT : FFI::SCHEMA_12_CORE,
109
+ cols
110
+ )
111
+ raise ParseError, FFI.last_error_message if st != FFI::OK
112
+
113
+ begin
114
+ n = cols[:count]
115
+ kinds = cols[:kinds].read_bytes(n).unpack("C*")
116
+ tags = cols[:tags].read_bytes(n).unpack("C*")
117
+ ikeys = cols[:is_keys].read_bytes(n).unpack("C*")
118
+ bools = cols[:bools].read_bytes(n).unpack("C*")
119
+ offs = cols[:offs].read_bytes(n * 4).unpack("V*")
120
+ lens = cols[:lens].read_bytes(n * 4).unpack("V*")
121
+ pays = cols[:payloads].read_bytes(n * 8).unpack("q<*")
122
+ arena_bytes = cols[:arena].read_bytes(cols[:arena_len])
123
+ arena_bytes.force_encoding(Encoding::UTF_8)
124
+ walk_columns(kinds, tags, ikeys, bools, offs, lens, pays, arena_bytes,
125
+ schema == :compat_11)
126
+ ensure
127
+ FFI.yeptris_value_free_columns(cols)
128
+ end
129
+ end
130
+
131
+ # The Marshal fast path (TODO.restructure/21): the C side emits
132
+ # Ruby Marshal 4.8 bytes; one Marshal.load call (a core-C routine)
133
+ # materializes the whole object graph. ~10x faster than walking
134
+ # the columns in pure Ruby on JSON-shaped input; ~5x on YAML. Falls
135
+ # back to load_all_columns on the constructs the format cannot
136
+ # express (merge keys, timestamps — rare; the record walk handles
137
+ # them). Feature-detected: older libyeptris returns the walk.
138
+ def load_all_marshal(yaml, schema: :compat_11, mode: :first)
139
+ yaml = Yeptris.read_input(yaml)
140
+ yaml = yaml.to_s
141
+ out_p = ::FFI::MemoryPointer.new(:pointer)
142
+ olen_p = ::FFI::MemoryPointer.new(:size_t)
143
+ mode_id = mode == :all ? FFI::MARSHAL_ALL_DOCS : FFI::MARSHAL_FIRST_DOC
144
+ st = FFI.yeptris_marshal(
145
+ yaml, yaml.bytesize,
146
+ schema == :compat_11 ? FFI::SCHEMA_11_COMPAT : FFI::SCHEMA_12_CORE,
147
+ mode_id, out_p, olen_p
148
+ )
149
+ return nil if st == FFI::ERROR_UNSUPPORTED
150
+ raise ParseError, FFI.last_error_message if st != FFI::OK
151
+ buf = out_p.read_pointer
152
+ len = Yeptris::FFI.read_c_size_t(olen_p)
153
+ bytes = buf.read_bytes(len)
154
+ bytes.force_encoding(Encoding::ASCII_8BIT)
155
+ ::Marshal.load(bytes)
156
+ ensure
157
+ FFI.yeptris_marshal_free(buf) if buf && !buf.null?
158
+ end
159
+
160
+ def load(yaml, schema: :compat_11)
161
+ docs = load_all(yaml, schema: schema)
162
+ docs.empty? ? nil : docs.first
163
+ end
164
+
165
+ # field offsets in the unpacked 7-tuple
166
+ KIND = 0
167
+ TAG = 1
168
+ IS_KEY = 2
169
+ B = 3
170
+ OFF = 4
171
+ LEN = 5
172
+ P64 = 6
173
+
174
+ def walk(flat, arena, compat = true)
175
+ docs = []
176
+ stack = []
177
+ anchors = {}
178
+ pending_key = []
179
+ pending_key_tag = []
180
+ pending_anchor = nil
181
+ merge_target = []
182
+
183
+ i = 0
184
+ n = flat.length
185
+ while i < n
186
+ kind = flat[i + KIND]
187
+ case kind
188
+ when V_STR
189
+ text = arena.byteslice(flat[i + OFF], flat[i + LEN])
190
+ # implicit-plain ':name' scans to a Symbol (Psych's
191
+ # ScalarScanner); quoted ':x' stays a String
192
+ v = str_to_value(text, flat[i + B] == 1)
193
+ if pending_anchor
194
+ anchors[pending_anchor] = v
195
+ pending_anchor = nil
196
+ end
197
+ slot(docs, stack, pending_key, pending_key_tag, v, merge_target, flat[i + IS_KEY], flat[i + TAG])
198
+ when V_INT
199
+ v = flat[i + P64]
200
+ if pending_anchor
201
+ anchors[pending_anchor] = v
202
+ pending_anchor = nil
203
+ end
204
+ slot(docs, stack, pending_key, pending_key_tag, v, merge_target, flat[i + IS_KEY], flat[i + TAG])
205
+ when V_FLOAT
206
+ text = arena.byteslice(flat[i + OFF], flat[i + LEN])
207
+ # Psych's float grammar requires the dot (or an inf/nan
208
+ # word, or sexagesimal ':') — exponent-only forms are
209
+ # Strings even when the compat tag says FLOAT
210
+ v = if !compat || text.include?(".") || text.include?(":") || text.start_with?(".")
211
+ [flat[i + P64]].pack("q<").unpack1("E")
212
+ else
213
+ text
214
+ end
215
+ if pending_anchor
216
+ anchors[pending_anchor] = v
217
+ pending_anchor = nil
218
+ end
219
+ slot(docs, stack, pending_key, pending_key_tag, v, merge_target, flat[i + IS_KEY], flat[i + TAG])
220
+ when V_BOOL
221
+ text = arena.byteslice(flat[i + OFF], flat[i + LEN])
222
+ # Psych quirk: single-char y/n stay Strings
223
+ v = text.length == 1 ? text : flat[i + B] == 1
224
+ if pending_anchor
225
+ anchors[pending_anchor] = v
226
+ pending_anchor = nil
227
+ end
228
+ slot(docs, stack, pending_key, pending_key_tag, v, merge_target, flat[i + IS_KEY], flat[i + TAG])
229
+ when V_NULL
230
+ # the pending anchor binds to the null (an anchored empty
231
+ # scalar) — without this it would leak onto the next value
232
+ if pending_anchor
233
+ anchors[pending_anchor] = nil
234
+ pending_anchor = nil
235
+ end
236
+ slot(docs, stack, pending_key, pending_key_tag, nil, merge_target, flat[i + IS_KEY], flat[i + TAG])
237
+ when V_TS
238
+ v = Materializer.parse_timestamp(arena.byteslice(flat[i + OFF], flat[i + LEN]))
239
+ if pending_anchor
240
+ anchors[pending_anchor] = v
241
+ pending_anchor = nil
242
+ end
243
+ slot(docs, stack, pending_key, pending_key_tag, v, merge_target, flat[i + IS_KEY], flat[i + TAG])
244
+ when MAP_OPEN
245
+ h = {}
246
+ if pending_anchor
247
+ anchors[pending_anchor] = h
248
+ pending_anchor = nil
249
+ end
250
+ merge_target.push(slot(docs, stack, pending_key, pending_key_tag, h, merge_target,
251
+ flat[i + IS_KEY], flat[i + TAG]))
252
+ stack.push(h)
253
+ pending_key.push(nil)
254
+ pending_key_tag.push(nil)
255
+ when SEQ_OPEN
256
+ a = []
257
+ if pending_anchor
258
+ anchors[pending_anchor] = a
259
+ pending_anchor = nil
260
+ end
261
+ merge_target.push(slot(docs, stack, pending_key, pending_key_tag, a, merge_target,
262
+ flat[i + IS_KEY], flat[i + TAG]))
263
+ stack.push(a)
264
+ pending_key.push(nil)
265
+ pending_key_tag.push(nil)
266
+ when CLOSE
267
+ closed = stack.pop
268
+ pending_key.pop
269
+ pending_key_tag.pop
270
+ target = merge_target.pop
271
+ if target
272
+ if closed.is_a?(Hash) || (closed.is_a?(Array) && closed.all? { |e| e.is_a?(Hash) })
273
+ Materializer.merge_into(target, closed)
274
+ else
275
+ target["<<"] = closed # Psych keeps non-mergeable merge values literally
276
+ end
277
+ end
278
+ when DOC
279
+ docs.push(nil)
280
+ when ALIAS
281
+ v = anchors[arena.byteslice(flat[i + OFF], flat[i + LEN])]
282
+ slot(docs, stack, pending_key, pending_key_tag, v, merge_target, flat[i + IS_KEY], flat[i + TAG])
283
+ when ANCHOR
284
+ pending_anchor = arena.byteslice(flat[i + OFF], flat[i + LEN])
285
+ end
286
+ i += FIELDS
287
+ end
288
+ docs
289
+ end
290
+
291
+ # The columnar twin of walk above (lockstep: same semantics, same
292
+ # order; fields come from tight per-kind arrays, stride 1).
293
+ def walk_columns(kinds, tags, ikeys, bools, offs, lens, pays, arena, compat = true)
294
+ docs = []
295
+ stack = []
296
+ anchors = {}
297
+ pending_key = []
298
+ pending_key_tag = []
299
+ pending_anchor = nil
300
+ merge_target = []
301
+
302
+ i = 0
303
+ n = kinds.length
304
+ while i < n
305
+ # the dominant shape: a str:str pair inside one map — place
306
+ # both directly, same conversions as the STR arm (the ':sym'
307
+ # scan rides is_key's text; anchors/merges fall through)
308
+ if kinds[i] == V_STR && ikeys[i] == 1 && i + 1 < n &&
309
+ kinds[i + 1] == V_STR && ikeys[i + 1] == 0 &&
310
+ pending_anchor.nil? && !stack.empty? && stack.last.is_a?(Hash)
311
+ kt = arena.byteslice(offs[i], lens[i])
312
+ if kt != "<<"
313
+ key = str_to_value(kt, bools[i] == 1)
314
+ vt = arena.byteslice(offs[i + 1], lens[i + 1])
315
+ stack.last[key] = str_to_value(vt, bools[i + 1] == 1)
316
+ i += 2
317
+ next
318
+ end
319
+ end
320
+ case kinds[i]
321
+ when V_STR
322
+ text = arena.byteslice(offs[i], lens[i])
323
+ v = str_to_value(text, bools[i] == 1)
324
+ if pending_anchor
325
+ anchors[pending_anchor] = v
326
+ pending_anchor = nil
327
+ end
328
+ # inline the dominant placement (Hash parent, value slot,
329
+ # non-merge key): a slot() call per pair was measurable
330
+ if !stack.empty?
331
+ parent = stack.last
332
+ if parent.is_a?(Hash) && ikeys[i] == 0 && (k = pending_key[-1]) && k != "<<"
333
+ parent[k] = v
334
+ pending_key[-1] = nil
335
+ else
336
+ slot(docs, stack, pending_key, pending_key_tag, v, merge_target, ikeys[i], tags[i])
337
+ end
338
+ else
339
+ docs[-1] = v
340
+ end
341
+ when V_INT
342
+ v = pays[i]
343
+ if pending_anchor
344
+ anchors[pending_anchor] = v
345
+ pending_anchor = nil
346
+ end
347
+ if !stack.empty?
348
+ parent = stack.last
349
+ if parent.is_a?(Hash) && ikeys[i] == 0 && (k = pending_key[-1]) && k != "<<"
350
+ parent[k] = v
351
+ pending_key[-1] = nil
352
+ else
353
+ slot(docs, stack, pending_key, pending_key_tag, v, merge_target, ikeys[i], tags[i])
354
+ end
355
+ else
356
+ docs[-1] = v
357
+ end
358
+ when V_FLOAT
359
+ text = arena.byteslice(offs[i], lens[i])
360
+ v = if !compat || text.include?(".") || text.include?(":") || text.start_with?(".")
361
+ [pays[i]].pack("q<").unpack1("E")
362
+ else
363
+ text
364
+ end
365
+ if pending_anchor
366
+ anchors[pending_anchor] = v
367
+ pending_anchor = nil
368
+ end
369
+ slot(docs, stack, pending_key, pending_key_tag, v, merge_target, ikeys[i], tags[i])
370
+ when V_BOOL
371
+ text = arena.byteslice(offs[i], lens[i])
372
+ v = text.length == 1 ? text : bools[i] == 1
373
+ if pending_anchor
374
+ anchors[pending_anchor] = v
375
+ pending_anchor = nil
376
+ end
377
+ slot(docs, stack, pending_key, pending_key_tag, v, merge_target, ikeys[i], tags[i])
378
+ when V_NULL
379
+ if pending_anchor
380
+ anchors[pending_anchor] = nil
381
+ pending_anchor = nil
382
+ end
383
+ slot(docs, stack, pending_key, pending_key_tag, nil, merge_target, ikeys[i], tags[i])
384
+ when V_TS
385
+ v = Materializer.parse_timestamp(arena.byteslice(offs[i], lens[i]))
386
+ if pending_anchor
387
+ anchors[pending_anchor] = v
388
+ pending_anchor = nil
389
+ end
390
+ slot(docs, stack, pending_key, pending_key_tag, v, merge_target, ikeys[i], tags[i])
391
+ when MAP_OPEN
392
+ h = {}
393
+ if pending_anchor
394
+ anchors[pending_anchor] = h
395
+ pending_anchor = nil
396
+ end
397
+ merge_target.push(slot(docs, stack, pending_key, pending_key_tag, h, merge_target,
398
+ ikeys[i], tags[i]))
399
+ stack.push(h)
400
+ pending_key.push(nil)
401
+ pending_key_tag.push(nil)
402
+ when SEQ_OPEN
403
+ a = []
404
+ if pending_anchor
405
+ anchors[pending_anchor] = a
406
+ pending_anchor = nil
407
+ end
408
+ merge_target.push(slot(docs, stack, pending_key, pending_key_tag, a, merge_target,
409
+ ikeys[i], tags[i]))
410
+ stack.push(a)
411
+ pending_key.push(nil)
412
+ pending_key_tag.push(nil)
413
+ when CLOSE
414
+ closed = stack.pop
415
+ pending_key.pop
416
+ pending_key_tag.pop
417
+ target = merge_target.pop
418
+ if target
419
+ if closed.is_a?(Hash) || (closed.is_a?(Array) && closed.all? { |e| e.is_a?(Hash) })
420
+ Materializer.merge_into(target, closed)
421
+ else
422
+ target["<<"] = closed # Psych keeps non-mergeable merge values literally
423
+ end
424
+ end
425
+ when DOC
426
+ docs.push(nil)
427
+ when ALIAS
428
+ v = anchors[arena.byteslice(offs[i], lens[i])]
429
+ slot(docs, stack, pending_key, pending_key_tag, v, merge_target, ikeys[i], tags[i])
430
+ when ANCHOR
431
+ pending_anchor = arena.byteslice(offs[i], lens[i])
432
+ end
433
+ i += 1
434
+ end
435
+ docs
436
+ end
437
+
438
+ # Places a completed value: document root, sequence entry, or a
439
+ # map's key (is_key) / value (completing the pending pair).
440
+ # Returns the merge TARGET when the value is a still-empty
441
+ # container placed under a '<<' key — the open-site caller pushes
442
+ # it so the matching CLOSE merges into it (an inline map's
443
+ # contents arrive after its open); scalar merges apply now.
444
+ def slot(docs, stack, pending_key, pending_key_tag, v, _merge_target, is_key, tag)
445
+ if stack.empty?
446
+ docs[-1] = v
447
+ return nil
448
+ end
449
+ parent = stack.last
450
+ if parent.is_a?(Array)
451
+ parent.push(v)
452
+ return nil
453
+ end
454
+ if is_key == 1
455
+ pending_key[-1] = v
456
+ pending_key_tag[-1] = tag
457
+ return nil
458
+ end
459
+ key = pending_key[-1]
460
+ pending_key[-1] = nil
461
+ if key == "<<" && pending_key_tag[-1] == 9 # TAG_MERGE
462
+ if (v.is_a?(Hash) || v.is_a?(Array)) && v.empty?
463
+ parent # deferred: contents arrive after the open
464
+ elsif v.is_a?(Hash) || (v.is_a?(Array) && v.all? { |e| e.is_a?(Hash) })
465
+ Materializer.merge_into(parent, v)
466
+ nil
467
+ else
468
+ parent["<<"] = v # Psych keeps non-mergeable merge values literally
469
+ nil
470
+ end
471
+ else
472
+ parent[key] = v
473
+ nil
474
+ end
475
+ end
476
+ end
477
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The YAML leg of the Descriptor plan walk (yeptris#293 slice three,
4
+ # over the C DOM plan walk of libyeptris v0.6.4): the same compiled
5
+ # row shape as Yeptris::JSON::Descriptor, applied to a parsed YAML
6
+ # document — block YAML hydrates to typed columns with no
7
+ # intermediate Ruby tree.
8
+ #
9
+ # descriptor = Yeptris::YAML::Descriptor.build(
10
+ # kind: :map, path: ["data", "items"], # segmented paths work
11
+ # children: [{ name: "id", kind: :int }, { name: "name", kind: :str }])
12
+ # descriptor.walk(yaml).column("id") # => [1, 2, ...]
13
+ #
14
+ # Typed extraction rides the parse-time tag ids (schema: selects the
15
+ # resolver — :compat_11 keeps the Psych/libyaml implicit typing
16
+ # YAML.load uses); string columns are materialized from the
17
+ # document's regions before the result returns (nothing borrowed).
18
+ class Yeptris::YAML::Descriptor < ::Yeptris::JSON::Descriptor
19
+ # schema: :core_12 (YAML 1.2) or :compat_11 (the Psych-compatible
20
+ # implicit typing Yeptris::YAML.load uses).
21
+ def initialize(handle, names, schema)
22
+ super(handle, names)
23
+ @schema = schema
24
+ end
25
+
26
+ # @api private — the compile rides the JSON Descriptor's grammar
27
+ # (inherited private class method); schema selects the resolver
28
+ def self.build(kind:, path: nil, children:, schema: :compat_11)
29
+ handle, names = compile_handle(kind, path, children)
30
+ new(handle, names, schema)
31
+ end
32
+
33
+ def walk(yaml)
34
+ src = ::Yeptris.read_input(yaml).to_s
35
+ doc = ::Yeptris::Document.parse(src, schema: @schema)
36
+ return [] if doc.nil? # the legal empty stream
37
+
38
+ begin
39
+ st = ::FFI::MemoryPointer.new(:int)
40
+ raw = ::Yeptris::FFI.yeptris_document_plan_walk(doc.c_ptr, @handle, st)
41
+ if raw.null?
42
+ raise ::Yeptris::JSON::Descriptor::Error,
43
+ "plan walk failed (status=#{st.read_int}) — the document shape " \
44
+ "disagrees with the plan"
45
+ end
46
+
47
+ begin
48
+ ::Yeptris::JSON::Descriptor::PlanResult.read_dom(raw, @names)
49
+ ensure
50
+ ::Yeptris::FFI.yeptris_plan_result_free(raw)
51
+ end
52
+ ensure
53
+ doc.free
54
+ end
55
+ end
56
+ end