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,862 @@
1
+ /* scan.c — line facts and span location (TODO.impl/06).
2
+ *
3
+ * Byte classification truth lives in chartype; SIMD kernels accelerate
4
+ * the span scans; this module owns YAML's line/span semantics only.
5
+ */
6
+
7
+ #include <string.h>
8
+
9
+ #include "common/chartype.h"
10
+ #include "common/simd_text.h"
11
+ #include "scan.h"
12
+
13
+ size_t yep_scan_break_len(const char* p, size_t len, size_t pos) {
14
+ if (pos >= len) {
15
+ return 0;
16
+ }
17
+ if (p[pos] == '\n') {
18
+ return 1;
19
+ }
20
+ if (p[pos] == '\r') {
21
+ return (pos + 1 < len && p[pos + 1] == '\n') ? 2 : 1;
22
+ }
23
+ /* NEL/LS/PS are breaks like LF/CR (libyaml's IS_BREAK): the byte
24
+ * scanners ride them as content otherwise, and a plain value
25
+ * folds across the break INTO a following document marker (the
26
+ * nightly's r74: "&k:\":(<PS>---" read as one scalar, libyaml
27
+ * two events) */
28
+ return yep_scan_mb_break_len(p, len, pos);
29
+ }
30
+
31
+ size_t yep_scan_mb_break_len(const char* p, size_t len, size_t pos) {
32
+ if (pos + 1 < len && (unsigned char)p[pos] == 0xC2 && (unsigned char)p[pos + 1] == 0x85) {
33
+ return 2; /* NEL */
34
+ }
35
+ if (pos + 2 < len && (unsigned char)p[pos] == 0xE2 && (unsigned char)p[pos + 1] == 0x80 &&
36
+ ((unsigned char)p[pos + 2] & 0xFE) == 0xA8) {
37
+ return 3; /* LS / PS */
38
+ }
39
+ return 0;
40
+ }
41
+
42
+ void yep_scan_advance_line(const char* p, size_t* from, size_t to, uint32_t* line,
43
+ size_t* line_start) {
44
+ for (size_t i = *from; i < to; i++) {
45
+ if (p[i] == '\n') {
46
+ (*line)++;
47
+ *line_start = i + 1;
48
+ } else if (p[i] == '\r' && i + 1 < to && p[i + 1] != '\n') {
49
+ /* a lone \r is a break too (the engine's break rule):
50
+ * the JSON fast path's walk missed it and marked every
51
+ * event after the \r one line low while the general
52
+ * kernel (which walks \r) marked them correctly — whole
53
+ * vs chunked diverged on `\r`-containing JSON-class flow
54
+ * (the nightly's run 38549939326) */
55
+ (*line)++;
56
+ *line_start = i + 1;
57
+ } else {
58
+ size_t mb = yep_scan_mb_break_len(p, to, i);
59
+ if (mb > 0) {
60
+ (*line)++;
61
+ i += mb - 1;
62
+ *line_start = i + 1;
63
+ }
64
+ }
65
+ }
66
+ *from = to;
67
+ }
68
+
69
+ /* ONE home for the \n/\r break class (scan owns the concept): the
70
+ * engine's multiline walk shares it — it had rebuilt a duplicate per
71
+ * quoted scalar. Prebuilt nibble-class tables (TODO.restructure/68);
72
+ * the StopsetLiterals spec pins them against yep_stopset_init. */
73
+ const yep_stopset yep_break_stopset = {
74
+ .bitmap = {0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
75
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
76
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
77
+ .groups = 1,
78
+ .lo = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x02,
79
+ 0x00, 0x00}},
80
+ .hi = {{0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
81
+ 0x00, 0x00}},
82
+ };
83
+
84
+ void yep_scan_facts(const char* p, size_t len, size_t pos, yep_line_facts* out) {
85
+ yep_text_active()->line_facts(p, len, pos, out);
86
+ }
87
+
88
+ /* Line facts -> line info (the flags/marker derivation, facts-free).
89
+ * One kernel pass feeds BOTH this and the shape classifier via the
90
+ * engine's combined memo (TODO.restructure/76). */
91
+ void yep_scan_line_f(const char* p, size_t len, size_t pos, const yep_line_facts* f,
92
+ yep_line_info* out) {
93
+ yep_line_info li;
94
+ li.offset = (uint32_t)pos;
95
+ li.indent = 0;
96
+ li.flags = 0;
97
+ li.first = 0;
98
+ li.end = f->end;
99
+ size_t j = f->indent;
100
+ li.indent = (uint32_t)(j - pos);
101
+ if (j < li.end && p[j] == '\t') {
102
+ size_t k = j;
103
+ while (k < li.end && (p[k] == ' ' || p[k] == '\t')) {
104
+ k++;
105
+ }
106
+ if (k >= li.end) {
107
+ li.flags |= YEP_LF_BLANK;
108
+ if (li.indent == 0) {
109
+ li.flags |= YEP_LF_TAB;
110
+ }
111
+ *out = li;
112
+ return;
113
+ }
114
+ li.flags |= YEP_LF_TAB;
115
+ }
116
+
117
+ if (j >= li.end) {
118
+ li.flags |= YEP_LF_BLANK;
119
+ *out = li;
120
+ return;
121
+ }
122
+
123
+ li.first = (unsigned char)p[j];
124
+ if (li.first == '#') {
125
+ li.flags |= YEP_LF_COMMENT;
126
+ *out = li;
127
+ return;
128
+ }
129
+ if (li.first == '%' && li.indent == 0) {
130
+ li.flags |= YEP_LF_DIRECTIVE;
131
+ *out = li;
132
+ return;
133
+ }
134
+
135
+ /* "---" / "..." at column 0, followed by EOL/space/tab/comment —
136
+ * content may follow on the same line ("--- > folded"). */
137
+ if (li.indent == 0 && li.end - j >= 3 && memcmp(p + j, "---", 3) == 0 &&
138
+ (li.end - j == 3 || p[j + 3] == ' ' || p[j + 3] == '\t')) {
139
+ li.flags |= YEP_LF_DOC_START;
140
+ } else if (li.indent == 0 && li.end - j >= 3 && memcmp(p + j, "...", 3) == 0 &&
141
+ (li.end - j == 3 || p[j + 3] == ' ' || p[j + 3] == '\t')) {
142
+ li.flags |= YEP_LF_DOC_END;
143
+ }
144
+ *out = li;
145
+ }
146
+
147
+ yep_line_info yep_scan_line(const char* p, size_t len, size_t pos) {
148
+ yep_line_info li;
149
+ yep_line_facts f;
150
+ yep_scan_facts(p, len, pos, &f);
151
+ yep_scan_line_f(p, len, pos, &f, &li);
152
+ return li;
153
+ }
154
+
155
+ /* Terminator check for ':' — blank, EOL, or (in flow) a flow indicator. */
156
+ static int yep_colon_terminates(const char* p, size_t len, size_t colon, int flow) {
157
+ size_t next = colon + 1;
158
+ if (next >= len) {
159
+ return 1; /* ':' at EOF terminates */
160
+ }
161
+ unsigned char c = (unsigned char)p[next];
162
+ if (c == ' ' || c == '\t' || c == '\n' || c == '\r') {
163
+ return 1;
164
+ }
165
+ /* a raw NEL/LS/PS is a break like LF (libyaml's IS_BLANKZ): the
166
+ * value-position separator arm the #833 dig pinned — the LF twin
167
+ * terminated while the PS spelling kept the colon in the plain */
168
+ if (yep_scan_mb_break_len(p, len, next) > 0) {
169
+ return 1;
170
+ }
171
+ if (flow && yep_ct_is(c, YEP_CT_FLOW_IND)) {
172
+ return 1;
173
+ }
174
+ return 0;
175
+ }
176
+
177
+ int yep_plain_first_ok(unsigned char c) {
178
+ return !(c == ',' || c == ']' || c == '}' || c == '%' || c == '@' || c == '`');
179
+ }
180
+
181
+ int yep_scan_prop_char(unsigned char c) {
182
+ return !yep_ct_any(c, YEP_CT_BLANK | YEP_CT_LBREAK | YEP_CT_FLOW_IND) && c != ',' && c != '#';
183
+ }
184
+
185
+ int yep_scan_dq_forced(const char* p, uint32_t len) {
186
+ for (uint32_t k = 0; k + 1 < len; k++) {
187
+ if ((unsigned char)p[k] == 0xc2 && (unsigned char)p[k + 1] == 0x85) {
188
+ return 1;
189
+ }
190
+ /* LS/PS are breaks like NEL: only their escapes are stable */
191
+ if ((unsigned char)p[k] == 0xe2 && k + 2 < len && (unsigned char)p[k + 1] == 0x80 &&
192
+ ((unsigned char)p[k + 2] == 0xa8 || (unsigned char)p[k + 2] == 0xa9)) {
193
+ return 1;
194
+ }
195
+ if ((unsigned char)p[k] == 0xef && k + 2 < len && (unsigned char)p[k + 1] == 0xbb &&
196
+ (unsigned char)p[k + 2] == 0xbf) {
197
+ return 1;
198
+ }
199
+ if ((unsigned char)p[k] == 0xef && k + 2 < len && (unsigned char)p[k + 1] == 0xbf &&
200
+ ((unsigned char)p[k + 2] == 0xbe || (unsigned char)p[k + 2] == 0xbf)) {
201
+ return 1; /* noncharacter: only its escape re-parses */
202
+ }
203
+ }
204
+ return 0;
205
+ }
206
+
207
+ /* ---- the plain-safety truth table (moved from emit/style.c,
208
+ * #352 lane 3: scan owns bytes→facts; the emitter and the DOM's
209
+ * parse-time fact bit both read THIS walk so they cannot drift) ---- */
210
+
211
+ static int is_blank(char c) {
212
+ return c == ' ' || c == '\t';
213
+ }
214
+
215
+ static int is_break(char c) {
216
+ return c == '\n' || c == '\r';
217
+ }
218
+
219
+ int yep_scan_plain_safe(const char* p, uint32_t len) {
220
+ if (len == 0) {
221
+ return 0; /* empty needs quotes or an empty-value slot */
222
+ }
223
+ if (is_blank(p[0]) || is_blank(p[len - 1])) {
224
+ return 0;
225
+ }
226
+ if (len >= 3 && (unsigned char)p[0] == 0xef && (unsigned char)p[1] == 0xbb &&
227
+ (unsigned char)p[2] == 0xbf) {
228
+ /* a LEADING U+FEFF re-parses as a document BOM and vanishes —
229
+ * the emitted form must carry its escape ("\uFEFF", the
230
+ * nightly's run 38258674337); mid-token BOMs ride plain */
231
+ return 0;
232
+ }
233
+ switch (p[0]) {
234
+ case ':':
235
+ /* libyaml (Psych symbol dumps ":name"): a leading colon only
236
+ * indicates when followed by a blank/EOL — the interior rule
237
+ * below covers it; ":name" stays plain */
238
+ break;
239
+ case '-':
240
+ case '?':
241
+ /* indicators only before a blank or EOL: "-5" and "?x" are
242
+ * plain (libyaml emits negative numbers plain; Psych, too) —
243
+ * but fall through: the document-marker check below owns
244
+ * the bare "---"/"..." (libyaml quotes those) */
245
+ if (len == 1 || is_blank(p[1])) {
246
+ return 0;
247
+ }
248
+ break;
249
+ case ',':
250
+ case '[':
251
+ case ']':
252
+ case '{':
253
+ case '}':
254
+ case '#':
255
+ case '&':
256
+ case '*':
257
+ case '!':
258
+ case '|':
259
+ case '>':
260
+ case '\'':
261
+ case '"':
262
+ case '%':
263
+ case '@':
264
+ case '`':
265
+ return 0;
266
+ default:
267
+ break;
268
+ }
269
+ /* The interior scan in SWAR words: every reject condition is a
270
+ * byte-class adjacency, so one masked word test is exact —
271
+ * break/tab bytes reject directly; ':' rejects with a blank at its
272
+ * NEXT lane (or the span's EOL); '#' with a blank at its PREVIOUS
273
+ * lane (the span's first byte is exempt — the head switch already
274
+ * handled a leading '#'). Cross-word adjacency rides one carried
275
+ * byte per boundary; the tail runs the byte loop, whose rules read
276
+ * real neighbors and need no carries. */
277
+ {
278
+ const uint64_t ONES = 0x0101010101010101ull;
279
+ const uint64_t HIGH = 0x8080808080808080ull;
280
+ #define YST_ZDET(w, ch) \
281
+ ((((w) ^ (uint64_t)(ch) * ONES) - ONES) & ~((w) ^ (uint64_t)(ch) * ONES) & HIGH)
282
+ /* the all-boring accept (#742): a span of pure [0-9A-Za-z_]
283
+ * makes EVERY rule in this function vacuous — no indicators
284
+ * (the head switch), no blanks at the ends, no BOM, no
285
+ * ': '/' #' adjacency, no breaks, and no ---/... marker — so
286
+ * one range test per word accepts without the six-mask walk.
287
+ * Anything else falls through to the exact scan below. */
288
+ {
289
+ uint32_t bi = 0;
290
+ int boring = 1;
291
+ while (bi + 8 <= len) {
292
+ uint64_t bw;
293
+ memcpy(&bw, p + bi, 8);
294
+ if (bw & HIGH) {
295
+ boring = 0;
296
+ break;
297
+ }
298
+ /* per-lane unsigned range checks via borrow bits: alpha
299
+ * is (t - 'a') and ('z' - t) both borrow-free with
300
+ * t = w|0x20 (A-Z fold); digits bound 0x30..0x39 */
301
+ uint64_t t = bw | (ONES * 0x20);
302
+ uint64_t bad = ((t - ONES * 0x61) | (ONES * 0x7A - t)) & HIGH; /* alpha */
303
+ bad |= ((bw - ONES * 0x30) | (ONES * 0x39 - bw)) & HIGH; /* digit */
304
+ bad &= ~YST_ZDET(bw, '_'); /* the one extra boring byte */
305
+ if (bad != 0) {
306
+ boring = 0;
307
+ break;
308
+ }
309
+ bi += 8;
310
+ }
311
+ if (boring) {
312
+ for (; bi < len; bi++) {
313
+ char c = p[bi];
314
+ int a = (c | 0x20);
315
+ if (!((c >= '0' && c <= '9') || (a >= 'a' && a <= 'z') || c == '_')) {
316
+ boring = 0;
317
+ break;
318
+ }
319
+ }
320
+ if (boring) {
321
+ return 1;
322
+ }
323
+ }
324
+ }
325
+ uint32_t i = 0;
326
+ int prev_blank7 = 0;
327
+ while (i + 8 <= len) {
328
+ uint64_t w;
329
+ memcpy(&w, p + i, 8);
330
+ if (w & HIGH) {
331
+ /* multibyte content: the byte loop owns the rest — a raw
332
+ * LS/PS/NEL rides in a scalar value since the quote-aware
333
+ * normalizer (#638) and is a line break on re-parse, so
334
+ * the value must be quoted, not plain (the nightly's
335
+ * round 18, crash-1e79b2e3) */
336
+ break;
337
+ }
338
+ uint64_t space = YST_ZDET(w, ' ');
339
+ uint64_t tab = YST_ZDET(w, '\t');
340
+ uint64_t blank = space | tab;
341
+ uint64_t colon = YST_ZDET(w, ':');
342
+ uint64_t hash = YST_ZDET(w, '#');
343
+ /* tab and the breaks reject outright */
344
+ if (tab | YST_ZDET(w, '\n') | YST_ZDET(w, '\r')) {
345
+ return 0;
346
+ }
347
+ /* ':' + blank next: (blank >> 8) pulls lane i+1's flag down
348
+ * into lane i; the word's last lane takes the peeked byte
349
+ * (EOL at the span end counts as blank — the rule rejects
350
+ * there) */
351
+ if (colon) {
352
+ int next_blank = i + 8 < len ? is_blank(p[i + 8]) : 1;
353
+ if (colon & ((blank >> 8) | (next_blank ? (uint64_t)0x80 << 56 : 0))) {
354
+ return 0;
355
+ }
356
+ }
357
+ /* '#' + blank prev: (blank << 8) lifts lane i-1's flag up
358
+ * into lane i; lane 0 takes the carried last-lane flag */
359
+ if (hash && (hash & ((blank << 8) | (prev_blank7 ? 0x80 : 0)))) {
360
+ return 0;
361
+ }
362
+ prev_blank7 = (int)((blank >> 63) & 1); /* lane 7's flag is its top bit */
363
+ i += 8;
364
+ }
365
+ #undef YST_ZDET
366
+ for (; i < len; i++) {
367
+ char c = p[i];
368
+ if (is_break(c) || c == '\t') {
369
+ return 0;
370
+ }
371
+ if ((unsigned char)c == 0xE2 && i + 2 < len && (unsigned char)p[i + 1] == 0x80 &&
372
+ ((unsigned char)p[i + 2] & 0xFE) == 0xA8) {
373
+ return 0; /* a raw LS/PS re-parses as a line break */
374
+ }
375
+ if ((unsigned char)c == 0xC2 && i + 1 < len && (unsigned char)p[i + 1] == 0x85) {
376
+ return 0; /* a raw NEL ditto */
377
+ }
378
+ if (c == ':') {
379
+ if (i + 1 >= len || is_blank(p[i + 1])) {
380
+ return 0;
381
+ }
382
+ }
383
+ if (c == '#') {
384
+ if (i > 0 && is_blank(p[i - 1])) {
385
+ return 0;
386
+ }
387
+ }
388
+ }
389
+ }
390
+ /* document markers */
391
+ if (len >= 3 && (memcmp(p, "---", 3) == 0 || memcmp(p, "...", 3) == 0) &&
392
+ (len == 3 || p[3] == ' ' || p[3] == '\t' || p[3] == '\n' || p[3] == '\r')) {
393
+ /* a PREFIX marker is worse than the bare one: emitted plain at
394
+ * line start, "--- ..." re-reads as a document marker (the
395
+ * nightly's "--- --- >" folded-plain crasher) — libyaml quotes
396
+ * both */
397
+ return 0;
398
+ }
399
+ return 1;
400
+ }
401
+
402
+ size_t yep_scan_prop_end(const char* p, size_t len, size_t pos) {
403
+ while (pos < len) {
404
+ unsigned char c = (unsigned char)p[pos];
405
+ if (!yep_scan_prop_char(c)) {
406
+ break;
407
+ }
408
+ /* NEL/LS/PS end the name (libyaml's IS_BLANKZ anchor law: the
409
+ * suite's ns-anchor-char excludes breaks): the byte-level
410
+ * table cannot classify a multibyte break, and the name run
411
+ * then swallowed it — the r69/r70 nightly divergence class
412
+ * ("&k:":(<PS>..."), shape-dependent clip downstream */
413
+ if (c == 0xC2 && pos + 1 < len && (unsigned char)p[pos + 1] == 0x85) {
414
+ break;
415
+ }
416
+ if (c == 0xE2 && pos + 2 < len && (unsigned char)p[pos + 1] == 0x80 &&
417
+ ((unsigned char)p[pos + 2] & 0xFE) == 0xA8) {
418
+ break;
419
+ }
420
+ pos++;
421
+ }
422
+ return pos;
423
+ }
424
+
425
+ int yep_scan_tag_char(unsigned char c) {
426
+ if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) {
427
+ return 1;
428
+ }
429
+ if (c >= 0x80) {
430
+ return 1; /* UTF-8 suffix bytes pass through */
431
+ }
432
+ switch (c) {
433
+ case '-':
434
+ case '_':
435
+ case ';':
436
+ case '/':
437
+ case '?':
438
+ case ':':
439
+ case '@':
440
+ case '&':
441
+ case '=':
442
+ case '+':
443
+ case '$':
444
+ case '.':
445
+ case '!':
446
+ case '~':
447
+ case '*':
448
+ case '\'':
449
+ case '(':
450
+ case ')':
451
+ case '%':
452
+ return 1;
453
+ default:
454
+ return 0;
455
+ }
456
+ }
457
+
458
+ /* ---- line-shape classification (TODO.restructure/49) ---- */
459
+
460
+ /* blank/EOL/EOF directly after p[at] (the dash / explicit-key rule). */
461
+ static int shape_blank_next(const char* p, size_t len, size_t at) {
462
+ return at + 1 >= len || p[at + 1] == ' ' || p[at + 1] == '\t' || p[at + 1] == '\n' ||
463
+ p[at + 1] == '\r';
464
+ }
465
+
466
+ /* Value bytes the fast arms do not own: quoted/tagged/block/flow
467
+ * scalars and the compact-syntax leads whose semantics belong to the
468
+ * general chain. */
469
+ static int shape_val_bail(unsigned char c, const char* p, size_t len, size_t at) {
470
+ switch (c) {
471
+ case '"':
472
+ case '\'':
473
+ case '!':
474
+ case '|':
475
+ case '>':
476
+ case '[':
477
+ case '{':
478
+ case '*': /* an alias after an anchor is an error shape (SR86) */
479
+ case '&': /* a second anchor is the suite's 4JVG error (catch 156) */
480
+ return 1;
481
+ case '-':
482
+ case '?':
483
+ return shape_blank_next(p, len, at);
484
+ default:
485
+ return 0;
486
+ }
487
+ }
488
+
489
+ /* The plain value span straight from the fused facts — the value-side
490
+ * mirror of shape_key_span (TODO.max-perf/03): the pair's value starts
491
+ * past the key's stop, so its first stop byte is facts stop2 (or the
492
+ * break when no second stop exists), already classified by the same
493
+ * sweep. The terminating law is re-checked exactly as the walking
494
+ * scan would apply it; a non-terminating stop or a high byte (the
495
+ * multibyte lead probe's territory) hands the span to the walk. The
496
+ * LineShape spec pins the two together. */
497
+ static yep_span shape_value_span(const char* p, size_t len, size_t vt, const yep_line_facts* f) {
498
+ yep_span v;
499
+ v.start = (uint32_t)vt;
500
+ v.term = YEP_TERM_EOF;
501
+ /* Long spans only: the walking scan's own tiny gate keeps a short
502
+ * value's scalar byte loop (cheaper than any facts read); below
503
+ * the threshold the fast path fired on shapes whose walk was
504
+ * already optimal and paid the kernel additions on every line
505
+ * (the anchor-heavy ABBA loss). 64 matches the walk's tiny gate. */
506
+ if (!(f->stop_set && f->stop < vt && !(f->flags & YEP_FACTS_HIGH) &&
507
+ (size_t)(f->end - vt) >= 64)) {
508
+ return yep_scan_plain(p, len, vt, 0);
509
+ }
510
+ size_t cand = 0;
511
+ int have = 0;
512
+ if (f->flags & YEP_FACTS_STOP2) {
513
+ if (f->stop2 >= vt) {
514
+ cand = f->stop2;
515
+ have = 1;
516
+ }
517
+ } else if (f->end >= vt) {
518
+ /* no second stop before the break: the first stop byte at or
519
+ * after the value start is the break itself */
520
+ cand = f->end;
521
+ have = 1;
522
+ }
523
+ if (have && cand <= len) {
524
+ if (cand == len) {
525
+ v.end = (uint32_t)len;
526
+ } else {
527
+ unsigned char c = (unsigned char)p[cand];
528
+ if (c == '\n' || c == '\r') {
529
+ v.end = (uint32_t)cand;
530
+ v.term = YEP_TERM_EOL;
531
+ } else if (c == ':' && yep_colon_terminates(p, len, cand, 0)) {
532
+ v.end = (uint32_t)cand;
533
+ v.term = YEP_TERM_COLON;
534
+ } else if (c == '#' && (cand == vt || p[cand - 1] == ' ' || p[cand - 1] == '\t')) {
535
+ v.end = (uint32_t)cand;
536
+ v.term = YEP_TERM_COMMENT;
537
+ } else {
538
+ return yep_scan_plain(p, len, vt, 0); /* non-terminating: walk */
539
+ }
540
+ }
541
+ while (v.end > v.start && (p[v.end - 1] == ' ' || p[v.end - 1] == '\t')) {
542
+ v.end--;
543
+ }
544
+ return v;
545
+ }
546
+ return yep_scan_plain(p, len, vt, 0);
547
+ }
548
+
549
+ static void shape_value(const char* p, size_t len, const yep_line_info* li, size_t vt,
550
+ const yep_line_facts* f, yep_line_shape* s) {
551
+ s->val_start = (uint32_t)vt;
552
+ if (vt >= li->end || p[vt] == '#') { /* '#' here follows a blank by construction */
553
+ s->val = YEP_LVAL_EMPTY;
554
+ return;
555
+ }
556
+ unsigned char c = (unsigned char)p[vt];
557
+ if (c == '*') {
558
+ s->val = YEP_LVAL_ALIAS; /* the engine's alias walk owns name semantics */
559
+ return;
560
+ }
561
+ if (c == '[' || c == '{') {
562
+ s->val = YEP_LVAL_FLOW;
563
+ return;
564
+ }
565
+ if (c == '&') {
566
+ size_t a_end = yep_scan_prop_end(p, len, vt + 1);
567
+ if (a_end == vt + 1) {
568
+ return; /* an anchor needs a name (libyaml): the general
569
+ * chain owns the error */
570
+ }
571
+ size_t t = a_end;
572
+ while (t < len && (p[t] == ' ' || p[t] == '\t')) {
573
+ t++;
574
+ }
575
+ if (t < li->end && p[t] != '#' && !shape_val_bail((unsigned char)p[t], p, len, t) &&
576
+ yep_plain_first_ok((unsigned char)p[t])) {
577
+ yep_span v = shape_value_span(p, len, t, f);
578
+ if (v.term != YEP_TERM_COLON && v.end > v.start) {
579
+ s->val = YEP_LVAL_ANCHOR_PLAIN;
580
+ s->anchor_end = (uint32_t)a_end;
581
+ s->val_span = v;
582
+ return;
583
+ }
584
+ }
585
+ return; /* anchor with a following-lines value / odd content: bail */
586
+ }
587
+ if (shape_val_bail(c, p, len, vt) || !yep_plain_first_ok(c)) {
588
+ return;
589
+ }
590
+ yep_span v = shape_value_span(p, len, vt, f);
591
+ if (v.term == YEP_TERM_COLON) {
592
+ return; /* a second terminating ':' is compact/error territory */
593
+ }
594
+ s->val = YEP_LVAL_PLAIN;
595
+ s->val_span = v;
596
+ }
597
+
598
+ /* The key span straight from the fused facts (TODO.restructure/76):
599
+ * the common line's key scan becomes zero byte-walking. Rare shapes
600
+ * (interior ':', embedded '#') fall back to the walking scan — the
601
+ * two must agree, and the LineShape spec pins them together. */
602
+ static yep_span shape_key_span(const char* p, size_t len, size_t t, const yep_line_facts* f) {
603
+ yep_span k;
604
+ k.start = (uint32_t)t;
605
+ k.term = YEP_TERM_EOF;
606
+ if (f->stop_set && f->stop >= t) {
607
+ unsigned char c = (unsigned char)p[f->stop];
608
+ if (c == ':') {
609
+ if (yep_colon_terminates(p, len, f->stop, 0)) {
610
+ k.term = YEP_TERM_COLON;
611
+ k.end = f->stop;
612
+ while (k.end > k.start && (p[k.end - 1] == ' ' || p[k.end - 1] == '\t')) {
613
+ k.end--;
614
+ }
615
+ return k;
616
+ }
617
+ } else if (c == '#' && (f->stop == t || p[f->stop - 1] == ' ' || p[f->stop - 1] == '\t')) {
618
+ k.term = YEP_TERM_COMMENT;
619
+ k.end = f->stop;
620
+ while (k.end > k.start && (p[k.end - 1] == ' ' || p[k.end - 1] == '\t')) {
621
+ k.end--;
622
+ }
623
+ return k;
624
+ }
625
+ return yep_scan_plain(p, len, t, 0); /* non-terminating stop: the walk owns it */
626
+ }
627
+ /* no stop byte before EOL: the span runs to the line end */
628
+ k.end = f->end;
629
+ while (k.end > k.start && (p[k.end - 1] == ' ' || p[k.end - 1] == '\t')) {
630
+ k.end--;
631
+ }
632
+ k.term = f->end < len ? YEP_TERM_EOL : YEP_TERM_EOF;
633
+ return k;
634
+ }
635
+
636
+ void yep_scan_shape_f(const char* p, size_t len, const yep_line_info* li, const yep_line_facts* f,
637
+ yep_line_shape* s) {
638
+ memset(s, 0, sizeof(*s));
639
+ s->kind = YEP_LSHAPE_NONE;
640
+ s->val = YEP_LVAL_NONE;
641
+ if (li->flags != 0) {
642
+ return; /* blank/comment/doc/directive/tab lines: general paths */
643
+ }
644
+ size_t t = li->offset + li->indent;
645
+ unsigned char c = (unsigned char)p[t];
646
+
647
+ if (c == '-' && shape_blank_next(p, len, t)) {
648
+ size_t vt = t + 1;
649
+ while (vt < len && (p[vt] == ' ' || p[vt] == '\t')) {
650
+ vt++;
651
+ }
652
+ s->kind = YEP_LSHAPE_DASH;
653
+ s->dash = (uint32_t)t;
654
+ shape_value(p, len, li, vt, f, s);
655
+ return;
656
+ }
657
+
658
+ /* '?' / ':' followed by a blank are the explicit-key and bare-colon
659
+ * lines (the general paths own them); followed by content they are
660
+ * ordinary plain-first bytes. A dash + blank returned as DASH above. */
661
+ if (yep_plain_first_ok(c) && c != '&' && c != '!' && c != '*' && c != '\'' && c != '"' &&
662
+ c != '[' && c != '{' && !((c == '?' || c == ':') && shape_blank_next(p, len, t))) {
663
+ yep_span k = shape_key_span(p, len, t, f);
664
+ if (k.term == YEP_TERM_COLON) {
665
+ /* k.end is the TRIMMED span end: the ':' sits past the
666
+ * trimmed blanks (or past interior stops on the fallback
667
+ * path) — the forward walk is over spaces, a few bytes */
668
+ size_t colon = k.end;
669
+ while (p[colon] != ':') {
670
+ colon++;
671
+ }
672
+ size_t vt = colon + 1;
673
+ while (vt < len && (p[vt] == ' ' || p[vt] == '\t')) {
674
+ vt++;
675
+ }
676
+ s->kind = YEP_LSHAPE_KEY;
677
+ s->key_start = k.start;
678
+ s->key_end = k.end;
679
+ s->colon = (uint32_t)colon;
680
+ shape_value(p, len, li, vt, f, s);
681
+ }
682
+ }
683
+ }
684
+
685
+ void yep_scan_shape(const char* p, size_t len, const yep_line_info* li, yep_line_shape* s) {
686
+ yep_line_facts f;
687
+ yep_scan_facts(p, len, li->offset, &f);
688
+ yep_scan_shape_f(p, len, li, &f, s);
689
+ }
690
+
691
+ /* The two plain-scalar stop classes are constants — they were rebuilt
692
+ on EVERY scan (~2 per line; clear + 4-9 adds ≈ 3M ops on a 100k-line
693
+ document), then became static bitmaps, now prebuilt nibble-class
694
+ tables (TODO.restructure/68). Generated: set[c>>3] |= 1 << (c&7) for
695
+ the stop chars below; lo/hi pinned by the StopsetLiterals spec. */
696
+ const yep_stopset yep_plain_stop_block = {
697
+ .bitmap = {0x00, 0x24, 0x00, 0x00, 0x08, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
698
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
699
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
700
+ /* members: \n \r # : */
701
+ .groups = 1,
702
+ .lo = {{0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x02,
703
+ 0x00, 0x00}},
704
+ .hi = {{0x03, 0x00, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
705
+ 0x00, 0x00}},
706
+ };
707
+
708
+ const yep_stopset yep_plain_stop_flow = {
709
+ .bitmap = {0x00, 0x24, 0x00, 0x00, 0x08, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00,
710
+ 0x28, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
711
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
712
+ /* members: \n \r # , : [ ] { } */
713
+ .groups = 2,
714
+ .lo = {{0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0xA0, 0x08, 0x42,
715
+ 0x00, 0x00},
716
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
717
+ 0x00, 0x00}},
718
+ .hi = {{0x03, 0x00, 0x0C, 0x10, 0x00, 0x60, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
719
+ 0x00, 0x00},
720
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
721
+ 0x00, 0x00}},
722
+ };
723
+
724
+ yep_span yep_scan_plain(const char* p, size_t len, size_t pos, int flow) {
725
+ const yep_text_kernels* k = yep_text_active();
726
+ const yep_stopset* stop = flow ? &yep_plain_stop_flow : &yep_plain_stop_block;
727
+ /* Short spans keep the scalar walk: the kernel dispatch costs more
728
+ * than it saves below a vector (block keys run 2-8 bytes — the
729
+ * same gate scan_line uses for its end-find). */
730
+ const int tiny = (len - pos) < 64;
731
+
732
+ yep_span s;
733
+ s.start = (uint32_t)pos;
734
+ s.end = (uint32_t)pos;
735
+ s.term = YEP_TERM_EOF;
736
+
737
+ size_t i = pos;
738
+ while (i < len) {
739
+ ptrdiff_t hit;
740
+ if (tiny) {
741
+ size_t at = i;
742
+ while (at < len && !yep_stopset_test(stop->bitmap, (unsigned char)p[at])) {
743
+ at++;
744
+ }
745
+ hit = (at < len) ? (ptrdiff_t)(at - i) : -1;
746
+ } else {
747
+ hit = k->stopset_find(stop, p + i, len - i);
748
+ }
749
+ size_t at = (hit < 0) ? len : i + (size_t)hit;
750
+ /* a multibyte break inside the piece ends it like an EOL: the
751
+ * byte stopset cannot see NEL/LS/PS, and the continuation
752
+ * would ride across the break into the next line's tokens.
753
+ * EVERY lead byte in the piece must be tested: the first lead
754
+ * can be an ordinary multibyte character (the r169 yen U+00A5
755
+ * leading a NEL run) while a later one is a break — testing
756
+ * the first lead only declined the check there and rode the
757
+ * break raw into the scalar (the false-lead ride, the r74
758
+ * plain-ends-at-NEL law defeated by the lead's own position). */
759
+ int mb_broken = 0;
760
+ for (size_t scan = i; at > scan;) {
761
+ const char* lead = (const char*)memchr(p + scan, 0xC2, at - scan);
762
+ const char* lead2 = (const char*)memchr(p + scan, 0xE2, at - scan);
763
+ const char* first =
764
+ (lead && lead2) ? (lead < lead2 ? lead : lead2) : (lead ? lead : lead2);
765
+ if (first == NULL) {
766
+ break;
767
+ }
768
+ if (yep_scan_mb_break_len(p, len, (size_t)(first - p)) > 0) {
769
+ at = (size_t)(first - p);
770
+ mb_broken = 1;
771
+ break;
772
+ }
773
+ scan = (size_t)(first - p) + 1; /* a false lead: advance past it */
774
+ }
775
+ if (mb_broken) {
776
+ i = at;
777
+ s.term = YEP_TERM_EOL;
778
+ break;
779
+ }
780
+ unsigned char c = (at < len) ? (unsigned char)p[at] : 0;
781
+
782
+ if (at == len) {
783
+ i = len;
784
+ s.term = YEP_TERM_EOF;
785
+ break;
786
+ }
787
+ if (c == '\n' || c == '\r') {
788
+ i = at;
789
+ s.term = YEP_TERM_EOL;
790
+ break;
791
+ }
792
+ if (c == ':') {
793
+ if (yep_colon_terminates(p, len, at, flow)) {
794
+ i = at;
795
+ s.term = YEP_TERM_COLON;
796
+ break;
797
+ }
798
+ i = at + 1;
799
+ continue;
800
+ }
801
+ if (c == '#') {
802
+ /* '#' starts a comment after a blank or at span start */
803
+ if (at == s.start || (at > s.start && (p[at - 1] == ' ' || p[at - 1] == '\t'))) {
804
+ i = at;
805
+ s.term = YEP_TERM_COMMENT;
806
+ break;
807
+ }
808
+ i = at + 1;
809
+ continue;
810
+ }
811
+ /* flow indicator (flow context only) */
812
+ i = at;
813
+ s.term = YEP_TERM_FLOW;
814
+ break;
815
+ }
816
+
817
+ /* Trim trailing spaces/tabs from the span. */
818
+ size_t e = i;
819
+ while (e > s.start && (p[e - 1] == ' ' || p[e - 1] == '\t')) {
820
+ e--;
821
+ }
822
+ s.end = (uint32_t)e;
823
+ if (e == s.start && s.term == YEP_TERM_EOF) {
824
+ s.term = YEP_TERM_EOF;
825
+ }
826
+ return s;
827
+ }
828
+
829
+ yep_span yep_scan_quoted(const char* p, size_t len, size_t pos, int* has_escape) {
830
+ const yep_text_kernels* k = yep_text_active();
831
+ unsigned char q = (unsigned char)p[pos];
832
+ int esc = 0;
833
+ ptrdiff_t r = k->quote_scan(p + pos + 1, len - pos - 1, (char)q, &esc);
834
+ if (has_escape != NULL) {
835
+ *has_escape = esc;
836
+ }
837
+ yep_span s;
838
+ s.start = (uint32_t)(pos + 1);
839
+ if (r < 0) {
840
+ s.end = (uint32_t)len;
841
+ s.term = YEP_TERM_EOL; /* unterminated — caller reports the error */
842
+ } else {
843
+ s.end = (uint32_t)(pos + 1 + (size_t)r);
844
+ s.term = YEP_TERM_EOF;
845
+ }
846
+ return s;
847
+ }
848
+
849
+ int yep_scan_is_key_start(unsigned char c) {
850
+ /* Quotes and flow openers always start a potential key; plain-first
851
+ * excludes most indicators. */
852
+ if (c == '\'' || c == '"' || c == '[' || c == '{' || c == '?') {
853
+ return 1;
854
+ }
855
+ if (c == '&' || c == '!' || c == '*') {
856
+ return 1; /* properties or an alias may open a key node */
857
+ }
858
+ if (yep_ct_is(c, YEP_CT_INDICATOR)) {
859
+ return 0; /* the remaining indicators cannot start a plain scalar */
860
+ }
861
+ return yep_ct_is_ns(c);
862
+ }