yeptris 0.6.59.1-arm-linux-eabihf → 0.6.61.1-arm-linux-eabihf
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/yeptris_native/version.h +2 -2
- data/lib/yeptris/3.4/native.so +0 -0
- data/lib/yeptris/ffi.rb +19 -0
- data/lib/yeptris/yaml.rb +71 -0
- data/lib/yeptris.rb +1 -1
- data/libyeptris.so +0 -0
- data/vendor/libyeptris/CMakeLists.txt +1 -1
- data/vendor/libyeptris/src/CMakeLists.txt +7 -0
- data/vendor/libyeptris/src/include/yeptris/emit.h +30 -2
- data/vendor/libyeptris/src/include/yeptris/parse.h +73 -0
- data/vendor/libyeptris/src/include/yeptris/resolve.h +8 -0
- data/vendor/libyeptris/src/include/yeptris/validate.h +222 -21
- data/vendor/libyeptris/src/include/yeptris/values.h +8 -2
- data/vendor/libyeptris/src/yeptris/cbor/cbor.h +10 -0
- data/vendor/libyeptris/src/yeptris/cbor/decode.c +5 -7
- data/vendor/libyeptris/src/yeptris/cbor/encode.c +9 -9
- data/vendor/libyeptris/src/yeptris/cbor/from_marshal.c +1 -1
- data/vendor/libyeptris/src/yeptris/common/error.h +2 -0
- data/vendor/libyeptris/src/yeptris/doc.h +20 -0
- data/vendor/libyeptris/src/yeptris/dom/dom.c +12 -1
- data/vendor/libyeptris/src/yeptris/dom/ytape.c +56 -7
- data/vendor/libyeptris/src/yeptris/emit/emit.c +93 -13
- data/vendor/libyeptris/src/yeptris/emit/writer.c +243 -652
- data/vendor/libyeptris/src/yeptris/emit/writer.h +25 -8
- data/vendor/libyeptris/src/yeptris/events/push.c +28 -3
- data/vendor/libyeptris/src/yeptris/events/values.c +46 -0
- data/vendor/libyeptris/src/yeptris/marshal/to_json.c +650 -0
- data/vendor/libyeptris/src/yeptris/parse/engine.c +611 -130
- data/vendor/libyeptris/src/yeptris/parse/engine.h +5 -0
- data/vendor/libyeptris/src/yeptris/parse/stream_iter.c +358 -0
- data/vendor/libyeptris/src/yeptris/parse.c +216 -44
- data/vendor/libyeptris/src/yeptris/resolve/compat11.c +3 -6
- data/vendor/libyeptris/src/yeptris/resolve/core12.c +11 -3
- data/vendor/libyeptris/src/yeptris/resolve/full12.c +201 -0
- data/vendor/libyeptris/src/yeptris/resolve/json12.c +12 -6
- data/vendor/libyeptris/src/yeptris/resolve/resolver.h +38 -0
- data/vendor/libyeptris/src/yeptris/resolve/tags.c +192 -0
- data/vendor/libyeptris/src/yeptris/scan/scan.c +22 -7
- data/vendor/libyeptris/src/yeptris/tape.c +24 -5
- data/vendor/libyeptris/src/yeptris/validate/compile.c +39 -3
- data/vendor/libyeptris/src/yeptris/validate/internal.h +223 -7
- data/vendor/libyeptris/src/yeptris/validate/jsonschema.c +645 -115
- data/vendor/libyeptris/src/yeptris/validate/output.c +246 -0
- data/vendor/libyeptris/src/yeptris/validate/regexp.c +623 -157
- data/vendor/libyeptris/src/yeptris/validate/registry.c +118 -0
- data/vendor/libyeptris/src/yeptris/validate/resources.c +601 -0
- data/vendor/libyeptris/src/yeptris/validate/stream.c +1155 -0
- data/vendor/libyeptris/src/yeptris/validate/validate.c +288 -145
- metadata +8 -1
|
@@ -51,9 +51,16 @@ typedef enum {
|
|
|
51
51
|
typedef struct {
|
|
52
52
|
uint32_t col;
|
|
53
53
|
uint8_t kind;
|
|
54
|
-
uint8_t inline_doc; /* opened on the --- line: deeper keys only */
|
|
55
54
|
} yep_frame;
|
|
56
55
|
|
|
56
|
+
/* One repeat-alias memo slot: the name is an input-relative span
|
|
57
|
+
* (alias names are always raw input views), so at+len re-derive it. */
|
|
58
|
+
typedef struct e_alias_slot {
|
|
59
|
+
uint32_t at; /* offset of the name inside e->p */
|
|
60
|
+
uint32_t len; /* 0 = slot empty */
|
|
61
|
+
uint32_t ord; /* the ordinal the nametab answered */
|
|
62
|
+
} e_alias_slot;
|
|
63
|
+
|
|
57
64
|
struct yep_engine {
|
|
58
65
|
const yep_allocator* sys;
|
|
59
66
|
yep_pool* pool; /* finish pool: folded/escaped scalar content */
|
|
@@ -90,10 +97,13 @@ struct yep_engine {
|
|
|
90
97
|
* 38541356075) */
|
|
91
98
|
uint32_t anchor_placed_cap;
|
|
92
99
|
/* repeat-alias memo (TODO.restructure/71): offset/len/ordinal of
|
|
93
|
-
* the last alias resolved — hit
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
100
|
+
* the last alias resolved — a hit answers by an input-span word
|
|
101
|
+
* compare (yep_view_eq; no libc call), not by the table.
|
|
102
|
+
* anchor_define drops the slot when the name being (re)defined is
|
|
103
|
+
* the memo's: the table's last-definition-wins overwrite would
|
|
104
|
+
* otherwise leave the memo serving a STALE ordinal (and skip the
|
|
105
|
+
* new ordinal's unplaced check). */
|
|
106
|
+
e_alias_slot alias_memo;
|
|
97
107
|
/* the line-facts memo (TODO.restructure/76): one kernel pass per
|
|
98
108
|
* line feeds both the line info and the shape */
|
|
99
109
|
yep_line_facts facts_cache;
|
|
@@ -150,6 +160,7 @@ struct yep_engine {
|
|
|
150
160
|
uint32_t ev_buf_n, ev_buf_cap;
|
|
151
161
|
uint32_t ev_scopes; /* active entry-buffer scopes */
|
|
152
162
|
char* norm_buf;
|
|
163
|
+
size_t norm_buf_len; /* norm_buf's byte length (NULL when no copy) */
|
|
153
164
|
unsigned char* enc_buf;
|
|
154
165
|
/* owned UTF-16/32 transcode scratch (run-owned) */ /* owned input copy with exotic breaks
|
|
155
166
|
normalized */
|
|
@@ -162,7 +173,8 @@ struct yep_engine {
|
|
|
162
173
|
overflow crasher) */
|
|
163
174
|
int last_root_flow; /* a root-level flow node just completed */
|
|
164
175
|
int tag_undef; /* an unresolved !handle! was seen (QLJ7) */
|
|
165
|
-
int doc_inline;
|
|
176
|
+
int doc_inline; /* the node opens on the --- line: block collections
|
|
177
|
+
* refuse there (the marker-line law, #900) */
|
|
166
178
|
uint32_t flow_floor; /* parent column of the current block-level flow */
|
|
167
179
|
int flow_enforce; /* flow continuation lines must out-indent it */
|
|
168
180
|
int compat_grammar; /* 11-COMPAT: libyaml/psych grammar parity —
|
|
@@ -218,6 +230,14 @@ static int e_fail(yep_engine* e, yep_err_code code, size_t at) {
|
|
|
218
230
|
return -1;
|
|
219
231
|
}
|
|
220
232
|
|
|
233
|
+
/* e_fail with an explicit message: the document-boundary diagnostics
|
|
234
|
+
* spell libyaml's exact words (issue #900 — the oracle's message
|
|
235
|
+
* surface, not the generic default-arm string). */
|
|
236
|
+
static int e_fail_msg(yep_engine* e, yep_err_code code, size_t at, const char* msg) {
|
|
237
|
+
yep_error_set(&e->err, code, e->line, e_col(e, at) + 1, at, "%s", msg);
|
|
238
|
+
return -1;
|
|
239
|
+
}
|
|
240
|
+
|
|
221
241
|
/* A simple key (no explicit '?') is limited to one line and 1024
|
|
222
242
|
* characters. The span runs from the node's first byte (opening
|
|
223
243
|
* quote, alias star — not its anchor/tag properties) to the ':'. */
|
|
@@ -237,20 +257,29 @@ static void e_anchor_mark(yep_engine* e, uint32_t id);
|
|
|
237
257
|
|
|
238
258
|
static int emit_now(yep_engine* e, const yep_event* ev) {
|
|
239
259
|
e_anchor_mark(e, ev->anchor_id);
|
|
240
|
-
if (ev->
|
|
241
|
-
/*
|
|
242
|
-
*
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
260
|
+
if (ev->tag.len > 0) {
|
|
261
|
+
/* Explicit-tag resolution (the typing SSOT for SCALARS AND
|
|
262
|
+
* COLLECTIONS): an event's tag_id names the explicit tag's id,
|
|
263
|
+
* so the family walk's consistency check can tell `!!map` on a
|
|
264
|
+
* mapping, `!!seq` on a sequence and a consumer-defined custom
|
|
265
|
+
* tag (CUSTOM, no family verdict) apart — a collection event's
|
|
266
|
+
* id used to stay 0 ("str"), which made EVERY tagged collection
|
|
267
|
+
* read as `!!str` and diagnose a false mismatch (#906 slice 4's
|
|
268
|
+
* tag-driven lane needs the true id). Both routes read this
|
|
269
|
+
* field, so the DOM and event walks stay in lockstep. */
|
|
270
|
+
yep_tag_id tid = yep_tag_from_uri((const char*)ev->tag.p, ev->tag.len);
|
|
271
|
+
/* psych's own dumped form is the LOCAL !binary shorthand,
|
|
272
|
+
* and stdlib to_ruby accepts it beside the core URI (#168)
|
|
273
|
+
* — compat schemas resolve it to BINARY as well */
|
|
274
|
+
if (ev->type == YEP_EV_SCALAR && tid == YEPTRIS_TAG_CUSTOM && ev->tag.len == 7 &&
|
|
275
|
+
memcmp(ev->tag.p, "!binary", 7) == 0 && e->resolver == yep_resolver_compat11()) {
|
|
276
|
+
tid = YEPTRIS_TAG_BINARY;
|
|
277
|
+
}
|
|
278
|
+
((yep_event*)ev)->tag_id = tid;
|
|
279
|
+
} else if (ev->type == YEP_EV_SCALAR) {
|
|
280
|
+
/* implicit typing: scalars only (a collection's id stays 0,
|
|
281
|
+
* its "no tag" value) */
|
|
282
|
+
if (ev->implicit && e->resolver != NULL) {
|
|
254
283
|
((yep_event*)ev)->tag_id = e->resolver->resolve(
|
|
255
284
|
e->resolver->ctx, (const char*)ev->value.p, (uint32_t)ev->value.len);
|
|
256
285
|
} else {
|
|
@@ -408,17 +437,17 @@ static uint32_t anchor_id_of(yep_engine* e, yep_view name) {
|
|
|
408
437
|
* the same alias thousands of times in a row; the memo answers
|
|
409
438
|
* those with one input compare, skipping the hash + a likely
|
|
410
439
|
* cache-missing probe into the (multi-MB, reserved) slots table. */
|
|
411
|
-
if (e->
|
|
412
|
-
|
|
413
|
-
return e->
|
|
440
|
+
if (e->alias_memo.len == name.len && name.len != 0 &&
|
|
441
|
+
yep_view_eq((yep_view){e->p + e->alias_memo.at, name.len}, name)) {
|
|
442
|
+
return e->alias_memo.ord;
|
|
414
443
|
}
|
|
415
444
|
uint32_t id = yep_nametab_get(&e->anchors, name);
|
|
416
445
|
if (id == YEP_NAMETAB_NIL) {
|
|
417
446
|
return 0;
|
|
418
447
|
}
|
|
419
|
-
e->
|
|
420
|
-
e->
|
|
421
|
-
e->
|
|
448
|
+
e->alias_memo.at = (uint32_t)(name.p - e->p);
|
|
449
|
+
e->alias_memo.len = name.len;
|
|
450
|
+
e->alias_memo.ord = id;
|
|
422
451
|
return id;
|
|
423
452
|
}
|
|
424
453
|
|
|
@@ -430,30 +459,48 @@ static void e_anchor_mark(yep_engine* e, uint32_t id) {
|
|
|
430
459
|
}
|
|
431
460
|
}
|
|
432
461
|
|
|
462
|
+
/* Grows the per-ordinal placed flags so flags[id-1] is writable.
|
|
463
|
+
* Returns 0 only on allocation failure (table unchanged). */
|
|
464
|
+
static int anchor_placed_fit(yep_engine* e, uint32_t id) {
|
|
465
|
+
if (id <= e->anchor_placed_cap) {
|
|
466
|
+
return 1;
|
|
467
|
+
}
|
|
468
|
+
uint32_t cap = e->anchor_placed_cap ? e->anchor_placed_cap : 64;
|
|
469
|
+
while (cap < id) {
|
|
470
|
+
cap *= 2;
|
|
471
|
+
}
|
|
472
|
+
uint8_t* nb = yep_alloc(e->sys, cap);
|
|
473
|
+
if (nb == NULL) {
|
|
474
|
+
return 0;
|
|
475
|
+
}
|
|
476
|
+
if (e->anchor_placed != NULL) {
|
|
477
|
+
memcpy(nb, e->anchor_placed, e->anchor_placed_cap);
|
|
478
|
+
yep_free(e->sys, e->anchor_placed);
|
|
479
|
+
}
|
|
480
|
+
memset(nb + e->anchor_placed_cap, 0, cap - e->anchor_placed_cap);
|
|
481
|
+
e->anchor_placed = nb;
|
|
482
|
+
e->anchor_placed_cap = cap;
|
|
483
|
+
return 1;
|
|
484
|
+
}
|
|
485
|
+
|
|
433
486
|
static uint32_t anchor_define(yep_engine* e, yep_view name) {
|
|
434
487
|
/* Last definition wins (libyaml parity); OOM leaves the anchor
|
|
435
488
|
* undefined so its alias errors. The VALUE is the anchor's 1-based
|
|
436
489
|
* ordinal — sinks key on it and skip the name hash entirely. */
|
|
437
490
|
uint32_t id = ++e->anchor_serial;
|
|
438
|
-
if (id
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
cap *= 2;
|
|
442
|
-
}
|
|
443
|
-
uint8_t* nb = yep_alloc(e->sys, cap);
|
|
444
|
-
if (nb == NULL) {
|
|
445
|
-
e->anchor_serial--;
|
|
446
|
-
return 0; /* OOM: the anchor stays undefined, its alias errors */
|
|
447
|
-
}
|
|
448
|
-
if (e->anchor_placed != NULL) {
|
|
449
|
-
memcpy(nb, e->anchor_placed, e->anchor_placed_cap);
|
|
450
|
-
yep_free(e->sys, e->anchor_placed);
|
|
451
|
-
}
|
|
452
|
-
memset(nb + e->anchor_placed_cap, 0, cap - e->anchor_placed_cap);
|
|
453
|
-
e->anchor_placed = nb;
|
|
454
|
-
e->anchor_placed_cap = cap;
|
|
491
|
+
if (!anchor_placed_fit(e, id)) {
|
|
492
|
+
e->anchor_serial--;
|
|
493
|
+
return 0; /* OOM: the anchor stays undefined, its alias errors */
|
|
455
494
|
}
|
|
456
495
|
yep_nametab_set(&e->anchors, name, id);
|
|
496
|
+
/* A (re)definition changes the ordinal the table answers for THIS
|
|
497
|
+
* name: a memo still naming it would serve the OLD ordinal
|
|
498
|
+
* (violating last-definition-wins) and skip the new ordinal's
|
|
499
|
+
* unplaced check. */
|
|
500
|
+
if (e->alias_memo.len == name.len && name.len != 0 &&
|
|
501
|
+
yep_view_eq((yep_view){e->p + e->alias_memo.at, name.len}, name)) {
|
|
502
|
+
e->alias_memo.len = 0;
|
|
503
|
+
}
|
|
457
504
|
return id;
|
|
458
505
|
}
|
|
459
506
|
|
|
@@ -468,13 +515,24 @@ static int e_open_seq(yep_engine* e, uint32_t col, uint32_t line, uint32_t coln,
|
|
|
468
515
|
e->frames[e->depth - 1].col == col) {
|
|
469
516
|
return 0;
|
|
470
517
|
}
|
|
518
|
+
if (e->doc_inline) {
|
|
519
|
+
/* the marker-line law (issue #900): a block collection cannot
|
|
520
|
+
* open on the --- line. libyaml's scanner disables block
|
|
521
|
+
* entries after the document-start indicator until a line
|
|
522
|
+
* break; libyaml 0.2.5/90a56d4, Psych 5 and PyYAML (pure and
|
|
523
|
+
* C) all reject ("block sequence entries are not allowed in
|
|
524
|
+
* this context"). The suite has no seq-class pin — its
|
|
525
|
+
* 9KBC/CXX2 fail-pins cover the mapping twin in e_open_map —
|
|
526
|
+
* so the oracle's law governs here. The cursor sits at the
|
|
527
|
+
* dash, which is libyaml's problem mark. */
|
|
528
|
+
return e_fail_msg(e, YEP_ERR_DOC_BOUNDARY, e->pos,
|
|
529
|
+
"block sequence entries are not allowed in this context");
|
|
530
|
+
}
|
|
471
531
|
if (e->depth >= e->max_depth) {
|
|
472
532
|
return e_fail(e, YEP_ERR_DEPTH, e->pos);
|
|
473
533
|
}
|
|
474
534
|
e->frames[e->depth].col = col;
|
|
475
535
|
e->frames[e->depth].kind = YEP_FRAME_SEQ;
|
|
476
|
-
e->frames[e->depth].inline_doc = (uint8_t)e->doc_inline;
|
|
477
|
-
e->doc_inline = 0;
|
|
478
536
|
e->depth++;
|
|
479
537
|
yep_event ev;
|
|
480
538
|
e_event_init(&ev, YEP_EV_SEQ_START);
|
|
@@ -506,13 +564,38 @@ static int e_open_map(yep_engine* e, uint32_t col, uint32_t line, uint32_t coln,
|
|
|
506
564
|
e->frames[e->depth - 1].col == col) {
|
|
507
565
|
return 0;
|
|
508
566
|
}
|
|
567
|
+
if (e->doc_inline) {
|
|
568
|
+
/* the marker-line law (issue #900): a block mapping cannot open
|
|
569
|
+
* on the --- line. libyaml's scanner keeps simple keys disabled
|
|
570
|
+
* after the document-start indicator until a line break, so the
|
|
571
|
+
* pair separator reads as "mapping values are not allowed in
|
|
572
|
+
* this context" (the explicit-key form: "mapping keys ...");
|
|
573
|
+
* libyaml 0.2.5/90a56d4, Psych 5 and PyYAML (pure and C) all
|
|
574
|
+
* reject, and the suite pins the class INVALID (9KBC/CXX2).
|
|
575
|
+
* The mark is the pair separator itself — libyaml's problem
|
|
576
|
+
* mark ("--- a: 1" marks 1:6, the colon). */
|
|
577
|
+
size_t at = e->pos;
|
|
578
|
+
const char* msg;
|
|
579
|
+
if (at < e->len && e->p[at] == '?') {
|
|
580
|
+
msg = "mapping keys are not allowed in this context";
|
|
581
|
+
} else {
|
|
582
|
+
msg = "mapping values are not allowed in this context";
|
|
583
|
+
while (at < e->len && e->p[at] != '\n' && e->p[at] != '\r') {
|
|
584
|
+
if (e->p[at] == ':' &&
|
|
585
|
+
(at + 1 >= e->len || e->p[at + 1] == ' ' || e->p[at + 1] == '\t' ||
|
|
586
|
+
e->p[at + 1] == '\n' || e->p[at + 1] == '\r')) {
|
|
587
|
+
break;
|
|
588
|
+
}
|
|
589
|
+
at++;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
return e_fail_msg(e, YEP_ERR_DOC_BOUNDARY, at, msg);
|
|
593
|
+
}
|
|
509
594
|
if (e->depth >= e->max_depth) {
|
|
510
595
|
return e_fail(e, YEP_ERR_DEPTH, e->pos);
|
|
511
596
|
}
|
|
512
597
|
e->frames[e->depth].col = col;
|
|
513
598
|
e->frames[e->depth].kind = YEP_FRAME_MAP;
|
|
514
|
-
e->frames[e->depth].inline_doc = (uint8_t)e->doc_inline;
|
|
515
|
-
e->doc_inline = 0;
|
|
516
599
|
e->depth++;
|
|
517
600
|
if (silent) {
|
|
518
601
|
return 0;
|
|
@@ -1288,9 +1371,12 @@ static yep_view e_resolve_tag(yep_engine* e, yep_view tag) {
|
|
|
1288
1371
|
/* Parses &anchor / !tag runs at the cursor into *anchor / *tag. A node
|
|
1289
1372
|
* carries at most one of each (c-ns-properties): a second property of
|
|
1290
1373
|
* the same kind is the suite's 4JVG error. Keeping the last one let a
|
|
1291
|
-
* mutated anchor run read differently from libyaml (catch 156).
|
|
1292
|
-
|
|
1293
|
-
|
|
1374
|
+
* mutated anchor run read differently from libyaml (catch 156).
|
|
1375
|
+
* *have_anchor / *have_tag carry that across CALLS — the flow node
|
|
1376
|
+
* parse re-runs the scan when a property rides the next line, and the
|
|
1377
|
+
* duplicate law must hold across the gap. */
|
|
1378
|
+
static void e_props_ex(yep_engine* e, yep_view* anchor, yep_view* tag, int* have_anchor,
|
|
1379
|
+
int* have_tag) {
|
|
1294
1380
|
for (;;) {
|
|
1295
1381
|
e_skip_inline_space(e);
|
|
1296
1382
|
if (e->pos >= e->len) {
|
|
@@ -1298,11 +1384,11 @@ static void e_props(yep_engine* e, yep_view* anchor, yep_view* tag) {
|
|
|
1298
1384
|
}
|
|
1299
1385
|
unsigned char c = (unsigned char)e->p[e->pos];
|
|
1300
1386
|
if (c == '&') {
|
|
1301
|
-
if (have_anchor) {
|
|
1387
|
+
if (*have_anchor) {
|
|
1302
1388
|
e_fail(e, YEP_ERR_UNEXPECTED, e->pos);
|
|
1303
1389
|
return;
|
|
1304
1390
|
}
|
|
1305
|
-
have_anchor = 1;
|
|
1391
|
+
*have_anchor = 1;
|
|
1306
1392
|
size_t start = e->pos + 1;
|
|
1307
1393
|
e->pos = yep_scan_prop_end(e->p, e->len, start);
|
|
1308
1394
|
anchor->p = e->p + start;
|
|
@@ -1327,7 +1413,24 @@ static void e_props(yep_engine* e, yep_view* anchor, yep_view* tag) {
|
|
|
1327
1413
|
* keep it (libyaml rejects those: "&a: key: v", W5VH's
|
|
1328
1414
|
* value position — suite-VALID, ledgered). The colon
|
|
1329
1415
|
* re-lexes as the key indicator and the existing colon
|
|
1330
|
-
* arm builds the anchored null key.
|
|
1416
|
+
* arm builds the anchored null key.
|
|
1417
|
+
*
|
|
1418
|
+
* The r228 nightly (run 42645063770, crash-8100227a)
|
|
1419
|
+
* caught the PROPS-LED follower: "&k2: ! {\n}" — the run
|
|
1420
|
+
* between the separator and the collection is the VALUE's
|
|
1421
|
+
* own properties, so libyaml still reads the anchored null
|
|
1422
|
+
* key (tag "<!>" on the flow map); yeptris instead rode
|
|
1423
|
+
* the colon into the name and stamped "k2:" + tag on the
|
|
1424
|
+
* map itself, and the anchor-led twin "&k2: &v {...}"
|
|
1425
|
+
* outright REJECTED (duplicate anchor) where libyaml
|
|
1426
|
+
* accepts. The follower scan now crosses ONE props run
|
|
1427
|
+
* ("!tag" / "&anch", verbatim "!<!..>" included —
|
|
1428
|
+
* scan_prop_end ends at a blank/break like the name scan)
|
|
1429
|
+
* before the indicator check, and a crossed run
|
|
1430
|
+
* un-consumes regardless of what follows: the tag/plain
|
|
1431
|
+
* member "&k2: ! t" reads the same pair in libyaml. The
|
|
1432
|
+
* plain-led twins (no props run — "&a: key", W5VH) never
|
|
1433
|
+
* cross one and keep riding. */
|
|
1331
1434
|
if (e->p[e->pos - 1] == ':') {
|
|
1332
1435
|
/* the follower scan crosses blanks, breaks AND
|
|
1333
1436
|
* comments: the pair separator at line end still opens
|
|
@@ -1340,6 +1443,7 @@ static void e_props(yep_engine* e, yep_view* anchor, yep_view* tag) {
|
|
|
1340
1443
|
* blank-equivalent here: skip it to its break and keep
|
|
1341
1444
|
* scanning. */
|
|
1342
1445
|
size_t t = e->pos;
|
|
1446
|
+
int rode_props = 0;
|
|
1343
1447
|
for (;;) {
|
|
1344
1448
|
while (t < e->len && (e->p[t] == ' ' || e->p[t] == '\t' || e->p[t] == '\n' ||
|
|
1345
1449
|
e->p[t] == '\r')) {
|
|
@@ -1351,12 +1455,28 @@ static void e_props(yep_engine* e, yep_view* anchor, yep_view* tag) {
|
|
|
1351
1455
|
}
|
|
1352
1456
|
continue;
|
|
1353
1457
|
}
|
|
1458
|
+
/* the r228 props-led law: one props run between
|
|
1459
|
+
* the separator and the follower belongs to the
|
|
1460
|
+
* VALUE node — a second keeps the first's verdict
|
|
1461
|
+
* ("&k2: !t &a {" still un-consumes on the "!") */
|
|
1462
|
+
if (!rode_props && t < e->len && (e->p[t] == '!' || e->p[t] == '&')) {
|
|
1463
|
+
t = yep_scan_prop_end(e->p, e->len, t + 1);
|
|
1464
|
+
rode_props = 1;
|
|
1465
|
+
continue;
|
|
1466
|
+
}
|
|
1354
1467
|
break;
|
|
1355
1468
|
}
|
|
1356
1469
|
if (t < e->len &&
|
|
1357
1470
|
(e->p[t] == '[' || e->p[t] == '{' || e->p[t] == '|' || e->p[t] == '>')) {
|
|
1358
1471
|
anchor->len -= 1;
|
|
1359
1472
|
e->pos -= 1;
|
|
1473
|
+
} else if (rode_props) {
|
|
1474
|
+
/* a crossed props run is the value's own: libyaml
|
|
1475
|
+
* reads the pair whatever follows the run — the
|
|
1476
|
+
* tag-led plain ("&k2: ! t") and the bare-tag/EOF
|
|
1477
|
+
* tail ("&k2: !") included */
|
|
1478
|
+
anchor->len -= 1;
|
|
1479
|
+
e->pos -= 1;
|
|
1360
1480
|
}
|
|
1361
1481
|
}
|
|
1362
1482
|
if (e->pos < e->len && e->p[e->pos] == '#') {
|
|
@@ -1371,11 +1491,11 @@ static void e_props(yep_engine* e, yep_view* anchor, yep_view* tag) {
|
|
|
1371
1491
|
return;
|
|
1372
1492
|
}
|
|
1373
1493
|
} else if (c == '!') {
|
|
1374
|
-
if (have_tag) {
|
|
1494
|
+
if (*have_tag) {
|
|
1375
1495
|
e_fail(e, YEP_ERR_UNEXPECTED, e->pos);
|
|
1376
1496
|
return;
|
|
1377
1497
|
}
|
|
1378
|
-
have_tag = 1;
|
|
1498
|
+
*have_tag = 1;
|
|
1379
1499
|
size_t start = e->pos;
|
|
1380
1500
|
e->pos++;
|
|
1381
1501
|
if (e->pos < e->len && e->p[e->pos] == '<') {
|
|
@@ -1423,6 +1543,13 @@ static void e_props(yep_engine* e, yep_view* anchor, yep_view* tag) {
|
|
|
1423
1543
|
}
|
|
1424
1544
|
}
|
|
1425
1545
|
|
|
1546
|
+
/* The one-call form: fresh duplicate state (the block node parse
|
|
1547
|
+
* consumes the whole run in a single scan). */
|
|
1548
|
+
static void e_props(yep_engine* e, yep_view* anchor, yep_view* tag) {
|
|
1549
|
+
int have_anchor = 0, have_tag = 0;
|
|
1550
|
+
e_props_ex(e, anchor, tag, &have_anchor, &have_tag);
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1426
1553
|
/* ------------------------------------------------------------- aliases */
|
|
1427
1554
|
|
|
1428
1555
|
static int e_alias(yep_engine* e, yep_event* ev) {
|
|
@@ -1684,7 +1811,8 @@ static int e_flow_node(yep_engine* e, yep_event* ev, int keyish) {
|
|
|
1684
1811
|
ev->line = e->line;
|
|
1685
1812
|
ev->col = e_col(e, e->pos) + 1;
|
|
1686
1813
|
yep_view anchor = {0}, tag = {0};
|
|
1687
|
-
|
|
1814
|
+
int have_anchor = 0, have_tag = 0;
|
|
1815
|
+
e_props_ex(e, &anchor, &tag, &have_anchor, &have_tag);
|
|
1688
1816
|
if (e->err.code != YEP_ERR_NONE) {
|
|
1689
1817
|
return -1; /* e_props failed (empty anchor name, unresolved tag) */
|
|
1690
1818
|
}
|
|
@@ -1711,6 +1839,38 @@ static int e_flow_node(yep_engine* e, yep_event* ev, int keyish) {
|
|
|
1711
1839
|
return e_fail(e, YEP_ERR_UNEXPECTED, e->pos);
|
|
1712
1840
|
}
|
|
1713
1841
|
c = (unsigned char)e->p[e->pos];
|
|
1842
|
+
/* Properties may span line breaks in flow (libyaml scans the
|
|
1843
|
+
* anchor/tag run across breaks: "&a\n!!t v" carries the tag with
|
|
1844
|
+
* value v; "!t\n&a x" carries the anchor). The run above skips
|
|
1845
|
+
* INLINE space only, so the cursor stopped at the break and the
|
|
1846
|
+
* property byte led the plain branch instead — a plain scalar
|
|
1847
|
+
* glued from tag/anchor bytes (the nightly's round 211,
|
|
1848
|
+
* crash-925daa54, "&anchor\n !!312 3123]"). Re-lex the riding
|
|
1849
|
+
* run with the have_* state threaded so a second property of one
|
|
1850
|
+
* kind still errors (the 4JVG law). Each iteration consumes at
|
|
1851
|
+
* least one byte or fails, so the loop is bounded. */
|
|
1852
|
+
while (c == '&' || c == '!') {
|
|
1853
|
+
e_props_ex(e, &anchor, &tag, &have_anchor, &have_tag);
|
|
1854
|
+
if (e->err.code != YEP_ERR_NONE) {
|
|
1855
|
+
return -1;
|
|
1856
|
+
}
|
|
1857
|
+
if (!yep_view_is_empty(anchor) && (memchr(anchor.p, '"', anchor.len) != NULL ||
|
|
1858
|
+
memchr(anchor.p, '\'', anchor.len) != NULL)) {
|
|
1859
|
+
return (int)e_fail(e, YEP_ERR_UNEXPECTED, e->pos);
|
|
1860
|
+
}
|
|
1861
|
+
ev->anchor = anchor;
|
|
1862
|
+
ev->tag = tag;
|
|
1863
|
+
if (!yep_view_is_empty(anchor)) {
|
|
1864
|
+
ev->anchor_id = anchor_define(e, anchor);
|
|
1865
|
+
}
|
|
1866
|
+
if (e_flow_ws(e) != 0) {
|
|
1867
|
+
return -1;
|
|
1868
|
+
}
|
|
1869
|
+
if (e->pos >= e->len) {
|
|
1870
|
+
return e_fail(e, YEP_ERR_UNEXPECTED, e->pos);
|
|
1871
|
+
}
|
|
1872
|
+
c = (unsigned char)e->p[e->pos];
|
|
1873
|
+
}
|
|
1714
1874
|
if ((c == ',' || c == ']' || c == '}' || c == ':') &&
|
|
1715
1875
|
(!yep_view_is_empty(anchor) || !yep_view_is_empty(tag))) {
|
|
1716
1876
|
ev->implicit = 1; /* properties with no node: a tagged null */
|
|
@@ -3496,7 +3656,7 @@ static int e_node(yep_engine* e, yep_ctx ctx, uint32_t floor_col) {
|
|
|
3496
3656
|
}
|
|
3497
3657
|
if (c == '-' && (e->pos + 1 >= e->len || e->p[e->pos + 1] == ' ' || e->p[e->pos + 1] == '\t' ||
|
|
3498
3658
|
e->p[e->pos + 1] == '\n' || e->p[e->pos + 1] == '\r')) {
|
|
3499
|
-
if (e->pos > 0 && e->p[e->pos - 1] == '\t') {
|
|
3659
|
+
if (e->pos > 0 && e->p[e->pos - 1] == '\t' && !e->doc_inline) {
|
|
3500
3660
|
return e_fail(e, YEP_ERR_UNEXPECTED, e->pos); /* "-\t-" (Y79Y) */
|
|
3501
3661
|
}
|
|
3502
3662
|
if (!yep_view_is_empty(anchor) || !yep_view_is_empty(tag)) {
|
|
@@ -3532,7 +3692,7 @@ static int e_node(yep_engine* e, yep_ctx ctx, uint32_t floor_col) {
|
|
|
3532
3692
|
* reference (the nightly's run 38355778230). */
|
|
3533
3693
|
return e_fail(e, YEP_ERR_UNEXPECTED, e->pos);
|
|
3534
3694
|
}
|
|
3535
|
-
if (e->pos > 0 && e->p[e->pos - 1] == '\t') {
|
|
3695
|
+
if (e->pos > 0 && e->p[e->pos - 1] == '\t' && !e->doc_inline) {
|
|
3536
3696
|
return e_fail(e, YEP_ERR_UNEXPECTED, e->pos); /* "?\t-" (Y79Y) */
|
|
3537
3697
|
}
|
|
3538
3698
|
uint32_t col = e_col(e, e->pos);
|
|
@@ -3788,15 +3948,17 @@ static int e_node(yep_engine* e, yep_ctx ctx, uint32_t floor_col) {
|
|
|
3788
3948
|
if (ctx == YEP_CTX_AFTER_COLON) {
|
|
3789
3949
|
return e_fail(e, YEP_ERR_UNEXPECTED, s.end);
|
|
3790
3950
|
}
|
|
3791
|
-
if (node_at > 0 && e->p[node_at - 1] == '\t') {
|
|
3951
|
+
if (node_at > 0 && e->p[node_at - 1] == '\t' && !e->doc_inline) {
|
|
3952
|
+
/* (on the --- line the marker-line gate names the same
|
|
3953
|
+
* refusal with libyaml's words — #900) */
|
|
3792
3954
|
return e_fail(e, YEP_ERR_UNEXPECTED, node_at); /* ":\tkey:" */
|
|
3793
3955
|
}
|
|
3794
3956
|
if (e_simple_key_ok(e, s.start, s.end) != 0) {
|
|
3795
3957
|
return -1;
|
|
3796
3958
|
}
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
|
|
3959
|
+
/* ("--- &a k: v" rides the e_open_map gate — the marker-line
|
|
3960
|
+
* law has one home now; the propped form used to fail here
|
|
3961
|
+
* with the generic default-arm diagnostic.) */
|
|
3800
3962
|
uint32_t key_col = e_col(e, node_at);
|
|
3801
3963
|
int rc = e_open_map(e, key_col, e->line, key_col + 1, pend_a, pend_t, pend_aid, 0);
|
|
3802
3964
|
if (rc != 0) {
|
|
@@ -4180,12 +4342,35 @@ yep_pool* yep_engine_detach_pool(yep_engine* e) {
|
|
|
4180
4342
|
return p;
|
|
4181
4343
|
}
|
|
4182
4344
|
|
|
4345
|
+
char* yep_engine_detach_norm_buf(yep_engine* e, size_t* len_out) {
|
|
4346
|
+
if (e == NULL) {
|
|
4347
|
+
if (len_out != NULL) {
|
|
4348
|
+
*len_out = 0;
|
|
4349
|
+
}
|
|
4350
|
+
return NULL;
|
|
4351
|
+
}
|
|
4352
|
+
char* b = e->norm_buf;
|
|
4353
|
+
if (len_out != NULL) {
|
|
4354
|
+
*len_out = e->norm_buf_len;
|
|
4355
|
+
}
|
|
4356
|
+
e->norm_buf = NULL;
|
|
4357
|
+
e->norm_buf_len = 0;
|
|
4358
|
+
return b;
|
|
4359
|
+
}
|
|
4360
|
+
|
|
4183
4361
|
void yep_engine_prepare(yep_engine* e, const yep_text_stats* st) {
|
|
4184
4362
|
if (e == NULL || st == NULL) {
|
|
4185
4363
|
return;
|
|
4186
4364
|
}
|
|
4187
4365
|
if (st->amp > 0) {
|
|
4188
4366
|
yep_nametab_reserve(&e->anchors, (uint32_t)st->amp);
|
|
4367
|
+
/* every definition bumps the serial exactly once and '&' marks
|
|
4368
|
+
* every definition, so amp is the serial's exact ceiling: the
|
|
4369
|
+
* placed flags pre-fit here and the parse never pays the
|
|
4370
|
+
* doubling chain (alloc + copy + memset per growth). Best
|
|
4371
|
+
* effort — anchor_define's growth stays as the fallback for
|
|
4372
|
+
* engines driven without prepare. */
|
|
4373
|
+
anchor_placed_fit(e, (uint32_t)st->amp + 1);
|
|
4189
4374
|
}
|
|
4190
4375
|
}
|
|
4191
4376
|
|
|
@@ -4260,6 +4445,7 @@ const yep_stopset yep_norm_break_leads = {
|
|
|
4260
4445
|
* headers). Verified against libyaml by the NormLsPs pins and the
|
|
4261
4446
|
* fuzz-diff LS/PS comparator. */
|
|
4262
4447
|
static int step_bs_header(const char* p, size_t len, size_t i);
|
|
4448
|
+
static size_t norm_next_fold_break(const char* p, size_t len, size_t i, size_t* br_len);
|
|
4263
4449
|
|
|
4264
4450
|
typedef struct yep_norm_ctx {
|
|
4265
4451
|
int quote; /* 0 none, else the opening quote char */
|
|
@@ -4271,15 +4457,44 @@ typedef struct yep_norm_ctx {
|
|
|
4271
4457
|
int at_break;
|
|
4272
4458
|
int bs_open;
|
|
4273
4459
|
int bs_content;
|
|
4274
|
-
uint32_t bs_indent;
|
|
4275
|
-
|
|
4276
|
-
uint8_t started;
|
|
4277
|
-
|
|
4278
|
-
|
|
4279
|
-
|
|
4280
|
-
unsigned char prev;
|
|
4281
|
-
|
|
4282
|
-
|
|
4460
|
+
uint32_t bs_indent; /* the header line's indent; (uint32_t)-1 = the
|
|
4461
|
+
* doc-inline root rule (markers only) */
|
|
4462
|
+
uint8_t started; /* at least one byte consumed: the walk's i == 0
|
|
4463
|
+
* clauses are stream-start, not buffer-start —
|
|
4464
|
+
* the chunked route resumes mid-stream at a ---
|
|
4465
|
+
* cut, and the carried context must say so */
|
|
4466
|
+
unsigned char prev; /* the last consumed byte (valid when started):
|
|
4467
|
+
* the '#' and line-start tests peek p[i - 1],
|
|
4468
|
+
* which at a resumed buffer is carried state */
|
|
4469
|
+
unsigned char bb; /* the byte immediately before the last FOLDED
|
|
4470
|
+
* break (0 = not armed): the r133 law — a
|
|
4471
|
+
* tok_start armed by a fold whose before-break
|
|
4472
|
+
* byte was plain content is a continuation
|
|
4473
|
+
* line, and its "!<" must not open a verbatim
|
|
4474
|
+
* tag (cleared wherever an indicator arms the
|
|
4475
|
+
* slot instead) */
|
|
4476
|
+
unsigned char plain_open; /* a plain scalar VALUE word is in
|
|
4477
|
+
* progress (set by every non-indicator content
|
|
4478
|
+
* byte, preserved across breaks): the r147
|
|
4479
|
+
* law — the bb gate's single-byte slice misses
|
|
4480
|
+
* the run-tail shapes ("- \n<NEL>!" arms
|
|
4481
|
+
* bb='\n', in the indicator set), so the open
|
|
4482
|
+
* keys on the value-in-progress fact: a
|
|
4483
|
+
* fold-armed tok_start over an open plain is a
|
|
4484
|
+
* continuation line whose "!<" is content,
|
|
4485
|
+
* never props */
|
|
4486
|
+
int phantom_flow; /* openers armed by the glued ':'-twin
|
|
4487
|
+
* ("a:{b]" — the #836-accepted prev==':'
|
|
4488
|
+
* clause) alone: libyaml keeps those bytes
|
|
4489
|
+
* INTERIOR to the plain (no flow collection
|
|
4490
|
+
* exists), so their depth must never arm the
|
|
4491
|
+
* r155 real-flow clear on ']' / '}' — the
|
|
4492
|
+
* walk's in_flow is monotone and the phantom
|
|
4493
|
+
* opens inflate it, which defeated the
|
|
4494
|
+
* "block context keeps the fact" law (the
|
|
4495
|
+
* r169 nightly: the ']' cleared plain_open
|
|
4496
|
+
* through the phantom and the next fold's
|
|
4497
|
+
* "!<" opened a never-closed verbatim) */
|
|
4283
4498
|
} yep_norm_ctx;
|
|
4284
4499
|
|
|
4285
4500
|
typedef struct yep_norm_tok {
|
|
@@ -4427,6 +4642,7 @@ static yep_norm_tok norm_step(yep_norm_ctx* c, const char* p, size_t len, size_t
|
|
|
4427
4642
|
t.n = 2;
|
|
4428
4643
|
t.fold_off = 0;
|
|
4429
4644
|
t.fold_len = 2;
|
|
4645
|
+
c->bb = (i > 0) ? (unsigned char)p[i - 1] : '\n';
|
|
4430
4646
|
norm_break_arms(c);
|
|
4431
4647
|
return t;
|
|
4432
4648
|
}
|
|
@@ -4434,6 +4650,7 @@ static yep_norm_tok norm_step(yep_norm_ctx* c, const char* p, size_t len, size_t
|
|
|
4434
4650
|
t.n = 3;
|
|
4435
4651
|
t.fold_off = 0;
|
|
4436
4652
|
t.fold_len = 3;
|
|
4653
|
+
c->bb = (i > 0) ? (unsigned char)p[i - 1] : '\n';
|
|
4437
4654
|
norm_break_arms(c);
|
|
4438
4655
|
return t;
|
|
4439
4656
|
}
|
|
@@ -4447,19 +4664,22 @@ static yep_norm_tok norm_step(yep_norm_ctx* c, const char* p, size_t len, size_t
|
|
|
4447
4664
|
c->at_break = 0;
|
|
4448
4665
|
return t;
|
|
4449
4666
|
}
|
|
4450
|
-
if (ch == ' ' || ch == '\t') {
|
|
4451
|
-
/* a value position survives spaces in block context ("k: 'x'"
|
|
4452
|
-
* opens; the plain continuation "a 'b'" does not — its word
|
|
4453
|
-
* did not begin with an indicator) */
|
|
4454
|
-
c->tok_start = (c->in_flow > 0) ? 1 : (c->word_led || c->tok_start);
|
|
4455
|
-
return t;
|
|
4456
|
-
}
|
|
4457
|
-
|
|
4458
4667
|
int line_start = (!c->started || c->at_break || c->prev == '\n' || c->prev == '\r');
|
|
4459
4668
|
|
|
4460
4669
|
/* block scalars: inside the fold no quote opens and every break
|
|
4461
4670
|
* keeps its fold; the region ends at a col-0 marker, a %-line
|
|
4462
|
-
* after content, or a dedent to the header line's indent
|
|
4671
|
+
* after content, or a dedent to the header line's indent. It runs
|
|
4672
|
+
* BEFORE the token-space arm: a fold line's leading spaces are its
|
|
4673
|
+
* INDENT, and the space arm consumed them one byte at a time (the
|
|
4674
|
+
* at_break stays armed) so the indent walk below counted from the
|
|
4675
|
+
* FIRST NON-SPACE byte — a one-space-indented content line read
|
|
4676
|
+
* ind=0, the dedent rule (ind <= bs_indent) ended the fold
|
|
4677
|
+
* mid-content, and the byte lexed as a token: "!<" armed a phantom
|
|
4678
|
+
* verbatim whose breaks-ride-raw law left the whole tail
|
|
4679
|
+
* unnormalized, the raw NEL run classified as one content line,
|
|
4680
|
+
* and the framing walk spawned a phantom empty plain second
|
|
4681
|
+
* document libyaml never emits (the r194 nightly,
|
|
4682
|
+
* ">\n ! \n !<aaa: bbb\n...\n<NEL><NEL>"). */
|
|
4463
4683
|
if (line_start && c->in_flow == 0 && c->bs_open) {
|
|
4464
4684
|
size_t k = i;
|
|
4465
4685
|
uint32_t ind = 0;
|
|
@@ -4473,12 +4693,52 @@ static yep_norm_tok norm_step(yep_norm_ctx* c, const char* p, size_t len, size_t
|
|
|
4473
4693
|
return t; /* a final line without its break */
|
|
4474
4694
|
}
|
|
4475
4695
|
if (p[k] == '\n' || p[k] == '\r' || p[k] == '#') {
|
|
4696
|
+
/* the line ends at ANY break spelling: a multibyte break
|
|
4697
|
+
* (NEL/LS/PS) FOLDS at the token tail, exactly like the
|
|
4698
|
+
* '#' comment arm ends its line (the pre-r194 path: the
|
|
4699
|
+
* token-space arm consumed the leading spaces one byte at
|
|
4700
|
+
* a time and the line's '#' hit the comment arm, whose
|
|
4701
|
+
* nel/lps case folds). Riding the break raw inside the
|
|
4702
|
+
* wholesale token leaked it to the engine's verbatim
|
|
4703
|
+
* block-scalar reader, and the r19-family indent
|
|
4704
|
+
* transform's verify (sub ">\n #ML<NEL>\n") stopped
|
|
4705
|
+
* flipping to parity — the r195 nightly ">\n#ML<NEL>". */
|
|
4476
4706
|
size_t e = k;
|
|
4477
|
-
|
|
4707
|
+
size_t bs = 0;
|
|
4708
|
+
size_t br = 0;
|
|
4709
|
+
while (e < len) {
|
|
4710
|
+
if (p[e] == '\n') {
|
|
4711
|
+
bs = e;
|
|
4712
|
+
br = 1;
|
|
4713
|
+
e++;
|
|
4714
|
+
break;
|
|
4715
|
+
}
|
|
4716
|
+
if (p[e] == '\r') {
|
|
4717
|
+
bs = e;
|
|
4718
|
+
br = (e + 1 < len && p[e + 1] == '\n') ? 2 : 1;
|
|
4719
|
+
e += br;
|
|
4720
|
+
break;
|
|
4721
|
+
}
|
|
4722
|
+
size_t mb = yep_scan_mb_break_len(p, len, e);
|
|
4723
|
+
if (mb > 0) {
|
|
4724
|
+
bs = e;
|
|
4725
|
+
br = mb;
|
|
4726
|
+
e += mb;
|
|
4727
|
+
break;
|
|
4728
|
+
}
|
|
4478
4729
|
e++;
|
|
4479
4730
|
}
|
|
4480
|
-
|
|
4481
|
-
|
|
4731
|
+
if (br == 0) {
|
|
4732
|
+
t.n = len - i;
|
|
4733
|
+
c->at_break = 0;
|
|
4734
|
+
return t; /* the tail rides the line to EOF */
|
|
4735
|
+
}
|
|
4736
|
+
t.n = e - i;
|
|
4737
|
+
if (p[bs] != '\n' && p[bs] != '\r') {
|
|
4738
|
+
t.fold_off = (int)(bs - i);
|
|
4739
|
+
t.fold_len = (int)br;
|
|
4740
|
+
}
|
|
4741
|
+
c->at_break = 1;
|
|
4482
4742
|
return t; /* blank or comment-content line */
|
|
4483
4743
|
}
|
|
4484
4744
|
int marker = (ind == 0 && k + 2 < len &&
|
|
@@ -4506,6 +4766,14 @@ static yep_norm_tok norm_step(yep_norm_ctx* c, const char* p, size_t len, size_t
|
|
|
4506
4766
|
}
|
|
4507
4767
|
}
|
|
4508
4768
|
|
|
4769
|
+
if (ch == ' ' || ch == '\t') {
|
|
4770
|
+
/* a value position survives spaces in block context ("k: 'x'"
|
|
4771
|
+
* opens; the plain continuation "a 'b'" does not — its word
|
|
4772
|
+
* did not begin with an indicator) */
|
|
4773
|
+
c->tok_start = (c->in_flow > 0) ? 1 : (c->word_led || c->tok_start);
|
|
4774
|
+
return t;
|
|
4775
|
+
}
|
|
4776
|
+
|
|
4509
4777
|
/* the header: a '>' / '|' at a value position with a valid
|
|
4510
4778
|
* follower opens the fold (the engine's own floor is the parent's
|
|
4511
4779
|
* column, which the walk cannot know — the header LINE's indent
|
|
@@ -4530,12 +4798,29 @@ static yep_norm_tok norm_step(yep_norm_ctx* c, const char* p, size_t len, size_t
|
|
|
4530
4798
|
c->bs_open = 1;
|
|
4531
4799
|
c->bs_indent = ind;
|
|
4532
4800
|
c->bs_content = 0;
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
|
|
4801
|
+
/* the header line ends at ANY fold break: the tail past
|
|
4802
|
+
* the indicators (usually the comment) is OUTSIDE the
|
|
4803
|
+
* block-content area, so the #638 fold law governs it — a
|
|
4804
|
+
* NEL/LS/PS there ends the header line and the next line
|
|
4805
|
+
* rides the bs branch from its own indent (the r171
|
|
4806
|
+
* nightly: the '\n'-only scan swallowed " #<"+NEL+" t"
|
|
4807
|
+
* whole, the NEL rode unnormalized to the engine, whose
|
|
4808
|
+
* comment skip then ate the content line — empty where
|
|
4809
|
+
* libyaml's IS_BREAKZ comment law reads "t") */
|
|
4810
|
+
size_t br_len = 0;
|
|
4811
|
+
size_t e = norm_next_fold_break(p, len, i, &br_len);
|
|
4812
|
+
if (br_len > 0) {
|
|
4813
|
+
t.n = (e + br_len) - i;
|
|
4814
|
+
t.fold_off = (int)(e - i); /* the break FOLDS: the copy
|
|
4815
|
+
* splices the '\n' (a
|
|
4816
|
+
* plain-consumed multibyte
|
|
4817
|
+
* break would ride raw) */
|
|
4818
|
+
t.fold_len = (int)br_len;
|
|
4819
|
+
c->at_break = 1;
|
|
4820
|
+
} else {
|
|
4821
|
+
t.n = len - i;
|
|
4822
|
+
c->at_break = 0;
|
|
4536
4823
|
}
|
|
4537
|
-
t.n = (e < len) ? (e - i + 1) : (len - i);
|
|
4538
|
-
c->at_break = (e < len);
|
|
4539
4824
|
return t;
|
|
4540
4825
|
}
|
|
4541
4826
|
/* not a header ("| : [" is a mapping key): fall through */
|
|
@@ -4561,24 +4846,55 @@ static yep_norm_tok norm_step(yep_norm_ctx* c, const char* p, size_t len, size_t
|
|
|
4561
4846
|
c->bs_open = 1;
|
|
4562
4847
|
c->bs_indent = (uint32_t)-1;
|
|
4563
4848
|
c->bs_content = 0;
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
|
|
4849
|
+
c->plain_open = 0; /* the marker is a document boundary */
|
|
4850
|
+
/* the marker line's tail ends at any fold break (the same
|
|
4851
|
+
* law as the plain header above -- the comment tail is
|
|
4852
|
+
* outside the content area) */
|
|
4853
|
+
size_t br_len = 0;
|
|
4854
|
+
size_t e = norm_next_fold_break(p, len, i, &br_len);
|
|
4855
|
+
if (br_len > 0) {
|
|
4856
|
+
t.n = (e + br_len) - i;
|
|
4857
|
+
t.fold_off = (int)(e - i); /* the break folds (the header twin) */
|
|
4858
|
+
t.fold_len = (int)br_len;
|
|
4859
|
+
c->at_break = 1;
|
|
4860
|
+
} else {
|
|
4861
|
+
t.n = len - i;
|
|
4862
|
+
c->at_break = 0;
|
|
4567
4863
|
}
|
|
4568
|
-
t.n = (e < len) ? (e - i + 1) : (len - i);
|
|
4569
|
-
c->at_break = (e < len);
|
|
4570
4864
|
return t;
|
|
4571
4865
|
}
|
|
4572
|
-
t.n = 3;
|
|
4866
|
+
t.n = 3; /* the marker rides; the line's tail processes normally */
|
|
4867
|
+
c->plain_open = 0; /* a document boundary: the next node's
|
|
4868
|
+
* props position must not inherit the
|
|
4869
|
+
* previous document's open plain */
|
|
4573
4870
|
return t;
|
|
4574
4871
|
}
|
|
4575
4872
|
|
|
4576
4873
|
if (c->tok_start) {
|
|
4577
4874
|
c->at_break = 0; /* any content byte ends the line-start state */
|
|
4578
4875
|
if (ch == '!' && i + 1 < len && p[i + 1] == '<') {
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4876
|
+
/* the r133 law: a tok_start armed by a FOLDED break whose
|
|
4877
|
+
* before-break byte was plain content is a continuation
|
|
4878
|
+
* line — its "!<" is plain content, not props; only a
|
|
4879
|
+
* new-node position (an indicator like ':' armed the slot)
|
|
4880
|
+
* opens a verbatim tag. Unconditioned, the continuation's
|
|
4881
|
+
* "!<" opened a phantom verbatim that swallowed the rest
|
|
4882
|
+
* of the input: later NELs rode unnormalized and the plain
|
|
4883
|
+
* fold emitted raw lead-stripped 0x85 into the value. The
|
|
4884
|
+
* r147 law extends the gate to the run-tail shapes the
|
|
4885
|
+
* single-byte bb probe misses ("- \n<NEL>!" arms bb='\n',
|
|
4886
|
+
* in the indicator set; "key: <NEL><NEL>!" arms bb=0x85,
|
|
4887
|
+
* outside it — both while a plain VALUE is in progress,
|
|
4888
|
+
* which plain_open carries): a plain value word open
|
|
4889
|
+
* across the fold means the line is a continuation, and
|
|
4890
|
+
* libyaml's 1.1 read folds the same NELs to newlines
|
|
4891
|
+
* (READ_LINE spells NEL -> LF, the fold law joins). */
|
|
4892
|
+
int bb_plain = c->bb != 0 && !strchr("&*!-?:,[]{}#%'\"|> \t\n\r", c->bb);
|
|
4893
|
+
if (!bb_plain && !c->plain_open) {
|
|
4894
|
+
c->in_verbatim = 1;
|
|
4895
|
+
t.n = 2;
|
|
4896
|
+
return t;
|
|
4897
|
+
}
|
|
4582
4898
|
}
|
|
4583
4899
|
c->word_led = (ch == '&' || ch == '*' || ch == '!' || ch == '-' || ch == '?' || ch == ':' ||
|
|
4584
4900
|
ch == ',' || ch == '[' || ch == '{' || ch == ']' || ch == '}');
|
|
@@ -4600,10 +4916,29 @@ static yep_norm_tok norm_step(yep_norm_ctx* c, const char* p, size_t len, size_t
|
|
|
4600
4916
|
* fold rendered one fold-SPACE per break instead of the n-1
|
|
4601
4917
|
* newline tally (the r98 nightly — the #836 phantom's flow
|
|
4602
4918
|
* half; the comma half landed in #836 itself). */
|
|
4919
|
+
int phantom = !c->tok_start; /* the glued ':'-twin alone (the
|
|
4920
|
+
* #836-accepted prev==':' state):
|
|
4921
|
+
* libyaml keeps the opener interior
|
|
4922
|
+
* to the plain, so its depth rides
|
|
4923
|
+
* phantom_flow, never the real count */
|
|
4603
4924
|
c->tok_start = 1;
|
|
4925
|
+
if (phantom) {
|
|
4926
|
+
c->phantom_flow++;
|
|
4927
|
+
/* the phantom opener is INTERIOR to the open plain VALUE
|
|
4928
|
+
* word (libyaml's read keeps the bytes content) — the fact
|
|
4929
|
+
* must survive it, or the r147 gate dies two shapes later:
|
|
4930
|
+
* the slot the opener armed says "new node" while the plain
|
|
4931
|
+
* is still open, and a following "!<" opened a phantom
|
|
4932
|
+
* verbatim that swallowed the rest of the input (the r217
|
|
4933
|
+
* nightly: "a:{!<x>"+NEL — "k:{" armed by the ':' indicator
|
|
4934
|
+
* clears a live plain_open). The r155/r169 law's opener
|
|
4935
|
+
* twin: block context keeps the fact. */
|
|
4936
|
+
} else {
|
|
4937
|
+
c->plain_open = 0; /* the slot was armed by an indicator */
|
|
4938
|
+
}
|
|
4604
4939
|
c->in_flow++;
|
|
4605
4940
|
} else if (ch == ',') {
|
|
4606
|
-
/* flow separators glue the next token — THE COMMA IN FLOW
|
|
4941
|
+
/* flow separators glue the next token — THE COMMA IN REAL FLOW
|
|
4607
4942
|
* ONLY. The unconditioned arm let a BLOCK plain's interior
|
|
4608
4943
|
* comma arm tok_start, a following "!<" opened a phantom
|
|
4609
4944
|
* verbatim tag that swallowed the rest of the input (breaks
|
|
@@ -4612,22 +4947,66 @@ static yep_norm_tok norm_step(yep_norm_ctx* c, const char* p, size_t len, size_t
|
|
|
4612
4947
|
* fold's blank-line tally lost them (the r96 nightly,
|
|
4613
4948
|
* yeptris#836, "b,,,!<!<"+NEL^3). ':' stays unconditioned:
|
|
4614
4949
|
* the BLOCK value position rides it ("k: 'x'" opens the
|
|
4615
|
-
* quote, the NormLsPs pins).
|
|
4616
|
-
|
|
4950
|
+
* quote, the NormLsPs pins). The r217 law: "in flow" means
|
|
4951
|
+
* REAL flow depth (the r155/r169 gate) — the glued ':'-twin's
|
|
4952
|
+
* phantom opens inflate in_flow without any flow collection
|
|
4953
|
+
* existing in libyaml's read, so their commas are INTERIOR
|
|
4954
|
+
* plain content ("o&a-:{*,,,!<!<"+NEL^3: the phantom '{'
|
|
4955
|
+
* inflated in_flow, the interior ','s armed a props slot, and
|
|
4956
|
+
* the "!<" opened the phantom verbatim again). */
|
|
4957
|
+
if (c->in_flow > c->phantom_flow) {
|
|
4617
4958
|
c->tok_start = 1;
|
|
4959
|
+
c->bb = 0; /* the slot was armed by an indicator, not a fold */
|
|
4960
|
+
c->plain_open = 0;
|
|
4618
4961
|
}
|
|
4619
4962
|
} else if (ch == ':') {
|
|
4620
4963
|
/* the separator law (#833's own predicate): a ':' arms the
|
|
4621
4964
|
* next token slot only before a blank/EOL/EOF — "k: 'x'"
|
|
4622
4965
|
* opens the value quote (the NormLsPs pins) while an
|
|
4623
4966
|
* interior "x:!<" of a block plain does NOT (the phantom
|
|
4624
|
-
* verbatim again, the #836 colon-led twin)
|
|
4967
|
+
* verbatim again, the #836 colon-led twin). The r217 law for
|
|
4968
|
+
* the DECLINED ':': a ':' before a non-blank byte is interior
|
|
4969
|
+
* to a plain, or the plain's own LEAD ("k:\t:{!<" — the
|
|
4970
|
+
* separating ':'+tab left plain_open dead, the value plain's
|
|
4971
|
+
* lead ':' declines, and the phantom '{' behind it armed a
|
|
4972
|
+
* props slot both of whose gates were dead — the "!<" opened
|
|
4973
|
+
* the phantom verbatim and the NEL run rode raw). The decline
|
|
4974
|
+
* IS the plain-context fact: arm the value word here. */
|
|
4625
4975
|
if (i + 1 >= len || p[i + 1] == ' ' || p[i + 1] == '\t' || p[i + 1] == '\n' ||
|
|
4626
4976
|
p[i + 1] == '\r') {
|
|
4627
4977
|
c->tok_start = 1;
|
|
4978
|
+
c->bb = 0; /* the slot was armed by an indicator, not a fold */
|
|
4979
|
+
c->plain_open = 0;
|
|
4980
|
+
} else {
|
|
4981
|
+
c->plain_open = 1;
|
|
4628
4982
|
}
|
|
4629
4983
|
} else if (ch == ']' || ch == '}') {
|
|
4630
4984
|
c->tok_start = 1;
|
|
4985
|
+
c->bb = 0; /* the slot was armed by an indicator, not a fold */
|
|
4986
|
+
if (c->in_flow > c->phantom_flow) {
|
|
4987
|
+
c->plain_open = 0;
|
|
4988
|
+
}
|
|
4989
|
+
/* block context keeps the fact: a plain cannot start with
|
|
4990
|
+
* ']' / '}' (c-indicator), so reaching this byte with the value
|
|
4991
|
+
* word open means it is INTERIOR content (the catch-85 law's
|
|
4992
|
+
* indicator twin) — the r155 law. The unconditional clear let
|
|
4993
|
+
* the next fold-armed "!<" open a phantom verbatim (the r147
|
|
4994
|
+
* gate's blind-spot twin: the ']' byte also blanks bb_plain —
|
|
4995
|
+
* it is in the bb indicator set — so both gate inputs said
|
|
4996
|
+
* "new node") and the NELs after it rode unnormalized raw into
|
|
4997
|
+
* the plain fold ("(999999;!<1]" +NEL+ "!<" +NEL+ "¥" +NEL^2).
|
|
4998
|
+
* The clear keys on REAL flow (in_flow above the phantom
|
|
4999
|
+
* depth): the glued ':'-twin's phantom opens inflate in_flow
|
|
5000
|
+
* without any flow collection existing in libyaml's read, and
|
|
5001
|
+
* the inflated count defeated the law on a plain's interior ']'
|
|
5002
|
+
* ("a:{b]" +NEL — the r169 nightly's fifth arming shape). */
|
|
5003
|
+
}
|
|
5004
|
+
/* the r147 law: a non-indicator content byte begins/continues a
|
|
5005
|
+
* plain scalar VALUE word — the fact survives breaks (breaks only
|
|
5006
|
+
* arm tok_start), so a later fold-armed "!<" reads it (indicator
|
|
5007
|
+
* bytes leave the fact to their own arm above) */
|
|
5008
|
+
if (!strchr("&*!-?:,[]{}#%'\"|>", ch)) {
|
|
5009
|
+
c->plain_open = 1;
|
|
4631
5010
|
}
|
|
4632
5011
|
return t;
|
|
4633
5012
|
}
|
|
@@ -4743,6 +5122,24 @@ static char* norm_breaks_run(const yep_allocator* sys, const char* p, size_t len
|
|
|
4743
5122
|
} else {
|
|
4744
5123
|
memcpy(out + o, p + j, (size_t)t.fold_off);
|
|
4745
5124
|
o += (size_t)t.fold_off;
|
|
5125
|
+
/* A raw CR copied just before this rewrite must not pair
|
|
5126
|
+
* with the replacement '\n' into a phantom CRLF: the byte
|
|
5127
|
+
* readers count CR LF as ONE break (SKIP_LINE's pair law)
|
|
5128
|
+
* while the input's CR + NEL/LS/PS were TWO — the rewrite
|
|
5129
|
+
* silently halved the fold's break tally (";!\r<NEL>\r;\r"
|
|
5130
|
+
* read ";!\\n;" where the (n-1) newline law says
|
|
5131
|
+
* ";!\\n\\n;", the r188 nightly). Rewrite the WHOLE
|
|
5132
|
+
* trailing run of raw CRs to '\n' — one CR is one break,
|
|
5133
|
+
* and only the run's last byte could ever touch the
|
|
5134
|
+
* replacement, but a shallower rewrite would just move the
|
|
5135
|
+
* phantom pair one byte left ("a\r\r<NEL>" -> "a\r\n\n"
|
|
5136
|
+
* re-pairs on the first CR; the run makes it "a\n\n\n",
|
|
5137
|
+
* four breaks in, four breaks out). LFs never pair with
|
|
5138
|
+
* each other, so the run's count survives everywhere the
|
|
5139
|
+
* fold law counts breaks. */
|
|
5140
|
+
for (size_t t2 = o; t2 > 0 && out[t2 - 1] == '\r'; t2--) {
|
|
5141
|
+
out[t2 - 1] = '\n';
|
|
5142
|
+
}
|
|
4746
5143
|
out[o++] = '\n';
|
|
4747
5144
|
memcpy(out + o, p + j + t.fold_off + t.fold_len,
|
|
4748
5145
|
t.n - (size_t)t.fold_off - (size_t)t.fold_len);
|
|
@@ -4767,6 +5164,7 @@ static const char* e_normalize_breaks(yep_engine* e, const char* p, size_t len,
|
|
|
4767
5164
|
return p;
|
|
4768
5165
|
}
|
|
4769
5166
|
e->norm_buf = out;
|
|
5167
|
+
e->norm_buf_len = out ? *out_len : 0;
|
|
4770
5168
|
return out;
|
|
4771
5169
|
}
|
|
4772
5170
|
|
|
@@ -4886,8 +5284,8 @@ void yep_engine_destroy(yep_engine* e) {
|
|
|
4886
5284
|
}
|
|
4887
5285
|
if (e->step != NULL) {
|
|
4888
5286
|
yep_stepstate* st = e->step;
|
|
4889
|
-
|
|
4890
|
-
|
|
5287
|
+
yep_free(e->sys, st->buf);
|
|
5288
|
+
yep_free(e->sys, st);
|
|
4891
5289
|
e->step = NULL;
|
|
4892
5290
|
}
|
|
4893
5291
|
yep_nametab_free(&e->anchors);
|
|
@@ -4926,6 +5324,41 @@ void yep_engine_destroy(yep_engine* e) {
|
|
|
4926
5324
|
* that flow to the depth cap, chunked cut and errored at 2:1).
|
|
4927
5325
|
* Returns 1 valid, 0 definitely not a header, -1 truncated (the tail
|
|
4928
5326
|
* may still complete a valid header). */
|
|
5327
|
+
|
|
5328
|
+
/* The next FOLD break at or after i under the #638 fold law outside
|
|
5329
|
+
* quotes ('\n', lone '\r' / CRLF, NEL, LS/PS): returns its start
|
|
5330
|
+
* offset and stores its consumed length, or returns 0 with *br_len 0
|
|
5331
|
+
* when the tail holds none. A truncated multibyte lead at the end
|
|
5332
|
+
* reads as "none": the one-shot walk runs on validated complete input
|
|
5333
|
+
* (a dangling lead never arrives), and the streaming scanner holds the
|
|
5334
|
+
* header line for the bytes that may still complete it. */
|
|
5335
|
+
static size_t norm_next_fold_break(const char* p, size_t len, size_t i, size_t* br_len) {
|
|
5336
|
+
size_t e = i;
|
|
5337
|
+
*br_len = 0;
|
|
5338
|
+
while (e < len) {
|
|
5339
|
+
unsigned char ec = (unsigned char)p[e];
|
|
5340
|
+
if (ec == '\n') {
|
|
5341
|
+
*br_len = 1;
|
|
5342
|
+
return e;
|
|
5343
|
+
}
|
|
5344
|
+
if (ec == '\r') {
|
|
5345
|
+
*br_len = (e + 1 < len && p[e + 1] == '\n') ? 2 : 1;
|
|
5346
|
+
return e;
|
|
5347
|
+
}
|
|
5348
|
+
if (ec == 0xC2 && e + 1 < len && (unsigned char)p[e + 1] == 0x85) {
|
|
5349
|
+
*br_len = 2;
|
|
5350
|
+
return e;
|
|
5351
|
+
}
|
|
5352
|
+
if (ec == 0xE2 && e + 2 < len && (unsigned char)p[e + 1] == 0x80 &&
|
|
5353
|
+
((unsigned char)p[e + 2] & 0xFE) == 0xA8) {
|
|
5354
|
+
*br_len = 3;
|
|
5355
|
+
return e;
|
|
5356
|
+
}
|
|
5357
|
+
e++;
|
|
5358
|
+
}
|
|
5359
|
+
return 0;
|
|
5360
|
+
}
|
|
5361
|
+
|
|
4929
5362
|
static int step_bs_header(const char* p, size_t len, size_t i) {
|
|
4930
5363
|
size_t k = i + 1;
|
|
4931
5364
|
int chomp = 0, indent = 0, space = 0;
|
|
@@ -5119,6 +5552,12 @@ static size_t step_scan(yep_stepstate* st) {
|
|
|
5119
5552
|
* ate the '---' marker, chunked errored on the unterminated
|
|
5120
5553
|
* prefix — the nightly's run 38534965021) */
|
|
5121
5554
|
st->tok_start = (st->in_flow > 0) ? 1 : st->word_led;
|
|
5555
|
+
/* the one-shot walk's law: the first post-break byte
|
|
5556
|
+
* clears the line-start fact — spaces included, or an
|
|
5557
|
+
* INDENTED " ---" (a plain/seq position) read as a
|
|
5558
|
+
* col-0 marker through the line-start gate and the cut
|
|
5559
|
+
* landed inside the line (the r171 gate twin) */
|
|
5560
|
+
st->at_break = 0;
|
|
5122
5561
|
continue;
|
|
5123
5562
|
}
|
|
5124
5563
|
if (st->tok_start) {
|
|
@@ -5195,7 +5634,11 @@ static size_t step_scan(yep_stepstate* st) {
|
|
|
5195
5634
|
}
|
|
5196
5635
|
if (st->in_flow == 0) {
|
|
5197
5636
|
char prev = i > 0 ? p[i - 1] : '\n';
|
|
5198
|
-
if (prev != '\n' && prev != '\r') {
|
|
5637
|
+
if (prev != '\n' && prev != '\r' && !st->at_break) {
|
|
5638
|
+
/* the one-shot walk's line_start law honors at_break
|
|
5639
|
+
* (-- the mb-break arms arm it); the prev-only check
|
|
5640
|
+
* missed every line that opens after a NEL/LS/PS, so
|
|
5641
|
+
* the ride-along never fired there (the r171 twin) */
|
|
5199
5642
|
continue;
|
|
5200
5643
|
}
|
|
5201
5644
|
/* Block scalars: once a '>' / '|' header is seen, its
|
|
@@ -5271,15 +5714,26 @@ static size_t step_scan(yep_stepstate* st) {
|
|
|
5271
5714
|
}
|
|
5272
5715
|
st->bs_open = 1;
|
|
5273
5716
|
st->bs_indent = ind;
|
|
5274
|
-
|
|
5275
|
-
|
|
5276
|
-
|
|
5277
|
-
|
|
5278
|
-
|
|
5717
|
+
/* the header line ends at ANY fold break (the
|
|
5718
|
+
* one-shot walk's law, norm_next_fold_break): the
|
|
5719
|
+
* tail past the indicators is outside the
|
|
5720
|
+
* block-content area, so the #638 fold law
|
|
5721
|
+
* governs it. The break arms' state rides here
|
|
5722
|
+
* too — at_break opens the content line's
|
|
5723
|
+
* ride-along through the line-start gate (the
|
|
5724
|
+
* r171 nightly: the '\n'-only scan never
|
|
5725
|
+
* completed a NEL-terminated header line and
|
|
5726
|
+
* held the window at the '>' forever) */
|
|
5727
|
+
size_t br_len = 0;
|
|
5728
|
+
size_t e = norm_next_fold_break(p, st->len, i, &br_len);
|
|
5729
|
+
if (br_len == 0) {
|
|
5279
5730
|
hold = i; /* an incomplete header line */
|
|
5280
5731
|
break;
|
|
5281
5732
|
}
|
|
5282
|
-
|
|
5733
|
+
st->tok_start = 1;
|
|
5734
|
+
st->word_led = 0;
|
|
5735
|
+
st->at_break = 1;
|
|
5736
|
+
i = e + br_len - 1; /* the loop's i++ lands past the break */
|
|
5283
5737
|
continue;
|
|
5284
5738
|
}
|
|
5285
5739
|
/* Not a header ("| : [" is a mapping key): fall through
|
|
@@ -5349,10 +5803,17 @@ int yep_engine_step(yep_engine* e, const char* chunk, size_t len, int final, con
|
|
|
5349
5803
|
return -1;
|
|
5350
5804
|
}
|
|
5351
5805
|
if (e->step == NULL) {
|
|
5352
|
-
|
|
5806
|
+
/* the step state rides the ENGINE's allocator (#904 item 3):
|
|
5807
|
+
* the raw calloc bypassed e->sys, so the fail-injection harness
|
|
5808
|
+
* (test_alloc_fail's counting allocator) could never reach the
|
|
5809
|
+
* streaming route's allocations — and the memory law
|
|
5810
|
+
* (allocator.h: nothing outside memory/ calls malloc directly)
|
|
5811
|
+
* does not stop at the engine's own struct */
|
|
5812
|
+
e->step = yep_alloc(e->sys, sizeof(yep_stepstate));
|
|
5353
5813
|
if (e->step == NULL) {
|
|
5354
5814
|
return -1;
|
|
5355
5815
|
}
|
|
5816
|
+
memset(e->step, 0, sizeof(yep_stepstate));
|
|
5356
5817
|
}
|
|
5357
5818
|
yep_stepstate* st = e->step;
|
|
5358
5819
|
st->tok_start = 1; /* the buffer starts at a line start */
|
|
@@ -5366,10 +5827,17 @@ int yep_engine_step(yep_engine* e, const char* chunk, size_t len, int final, con
|
|
|
5366
5827
|
while (cap < st->len + len) {
|
|
5367
5828
|
cap *= 2;
|
|
5368
5829
|
}
|
|
5369
|
-
|
|
5830
|
+
/* the pending buffer grows through e->sys too: the
|
|
5831
|
+
* allocator has no realloc, so growth is alloc + copy +
|
|
5832
|
+
* free (the arena.c pattern) */
|
|
5833
|
+
char* nb = yep_alloc(e->sys, cap);
|
|
5370
5834
|
if (nb == NULL) {
|
|
5371
5835
|
return -1;
|
|
5372
5836
|
}
|
|
5837
|
+
if (st->buf != NULL) {
|
|
5838
|
+
memcpy(nb, st->buf, st->len);
|
|
5839
|
+
yep_free(e->sys, st->buf);
|
|
5840
|
+
}
|
|
5373
5841
|
st->buf = nb;
|
|
5374
5842
|
st->cap = cap;
|
|
5375
5843
|
}
|
|
@@ -5429,8 +5897,8 @@ int yep_engine_step(yep_engine* e, const char* chunk, size_t len, int final, con
|
|
|
5429
5897
|
/* final: parse everything that remains and close the stream */
|
|
5430
5898
|
e->line_base = st->line_base;
|
|
5431
5899
|
int rc = engine_run_impl(e, st->buf, st->len, sink, !st->started, 1);
|
|
5432
|
-
|
|
5433
|
-
|
|
5900
|
+
yep_free(e->sys, st->buf);
|
|
5901
|
+
yep_free(e->sys, st);
|
|
5434
5902
|
e->step = NULL;
|
|
5435
5903
|
e->line_base = 0;
|
|
5436
5904
|
return rc;
|
|
@@ -5443,6 +5911,7 @@ static int engine_run_impl(yep_engine* e, const char* buf, size_t len, const yep
|
|
|
5443
5911
|
}
|
|
5444
5912
|
yep_free(e->sys, e->norm_buf);
|
|
5445
5913
|
e->norm_buf = NULL;
|
|
5914
|
+
e->norm_buf_len = 0;
|
|
5446
5915
|
/* enc_buf is NOT reset here: yep_engine_run's front-end may have
|
|
5447
5916
|
* transcoded THIS call's input into it microseconds ago -- buf
|
|
5448
5917
|
* points into it, and freeing it before the break-normalize scan
|
|
@@ -5467,7 +5936,7 @@ static int engine_run_impl(yep_engine* e, const char* buf, size_t len, const yep
|
|
|
5467
5936
|
if (e->anchor_placed != NULL) {
|
|
5468
5937
|
memset(e->anchor_placed, 0, e->anchor_placed_cap);
|
|
5469
5938
|
}
|
|
5470
|
-
e->
|
|
5939
|
+
e->alias_memo.len = 0;
|
|
5471
5940
|
e->tagmap_n = 0;
|
|
5472
5941
|
e->saw_yaml = 0;
|
|
5473
5942
|
e->doc_begin = (size_t)-1;
|
|
@@ -5702,11 +6171,11 @@ static int engine_run_impl(yep_engine* e, const char* buf, size_t len, const yep
|
|
|
5702
6171
|
if (e->anchor_placed != NULL) {
|
|
5703
6172
|
memset(e->anchor_placed, 0, e->anchor_placed_cap);
|
|
5704
6173
|
}
|
|
5705
|
-
|
|
5706
|
-
|
|
5707
|
-
|
|
5708
|
-
|
|
5709
|
-
|
|
6174
|
+
/* so are anchors — and the repeat-alias memo: doc 1's
|
|
6175
|
+
* "*ORIGIN" memoized the ordinal and doc 2's identical
|
|
6176
|
+
* name answered from it ACROSS the boundary (the
|
|
6177
|
+
* nightly's run 38266487549) */
|
|
6178
|
+
e->alias_memo.len = 0;
|
|
5710
6179
|
}
|
|
5711
6180
|
e_event_init(&ev, YEP_EV_DOCUMENT_START);
|
|
5712
6181
|
ev.style = 1; /* explicit marker */
|
|
@@ -5793,7 +6262,7 @@ static int engine_run_impl(yep_engine* e, const char* buf, size_t len, const yep
|
|
|
5793
6262
|
if (e->anchor_placed != NULL) {
|
|
5794
6263
|
memset(e->anchor_placed, 0, e->anchor_placed_cap);
|
|
5795
6264
|
}
|
|
5796
|
-
e->
|
|
6265
|
+
e->alias_memo.len = 0;
|
|
5797
6266
|
if (emit_now(e, &ev) != 0) {
|
|
5798
6267
|
return -2;
|
|
5799
6268
|
}
|
|
@@ -5837,6 +6306,9 @@ static int engine_run_impl(yep_engine* e, const char* buf, size_t len, const yep
|
|
|
5837
6306
|
(li.offset + li.indent + 1 >= e->len || e->p[li.offset + li.indent + 1] == ' ' ||
|
|
5838
6307
|
e->p[li.offset + li.indent + 1] == '\t' || e->p[li.offset + li.indent + 1] == '\n' ||
|
|
5839
6308
|
e->p[li.offset + li.indent + 1] == '\r');
|
|
6309
|
+
int map_closed_on_dash = 0; /* the root map closed because this line is a
|
|
6310
|
+
* seq entry — libyaml's parser-state name is
|
|
6311
|
+
* "did not find expected key" */
|
|
5840
6312
|
while (e->depth > 0) {
|
|
5841
6313
|
const yep_frame* fr = &e->frames[e->depth - 1];
|
|
5842
6314
|
if (fr->col > c) {
|
|
@@ -5850,11 +6322,12 @@ static int engine_run_impl(yep_engine* e, const char* buf, size_t len, const yep
|
|
|
5850
6322
|
int continues;
|
|
5851
6323
|
if (fr->kind == YEP_FRAME_SEQ) {
|
|
5852
6324
|
continues = dash_blank;
|
|
5853
|
-
} else if (fr->inline_doc) {
|
|
5854
|
-
continues = 0; /* "--- k: v" maps take deeper keys only */
|
|
5855
6325
|
} else {
|
|
5856
6326
|
continues = yep_scan_is_key_start(li.first) || li.first == ':' ||
|
|
5857
6327
|
li.first == '?' || (li.first == '-' && !dash_blank);
|
|
6328
|
+
if (!continues && dash_blank && e->depth == 1) {
|
|
6329
|
+
map_closed_on_dash = 1;
|
|
6330
|
+
}
|
|
5858
6331
|
}
|
|
5859
6332
|
if (!continues) {
|
|
5860
6333
|
int rc = e_close_to(e, e->depth - 1);
|
|
@@ -5868,10 +6341,19 @@ static int engine_run_impl(yep_engine* e, const char* buf, size_t len, const yep
|
|
|
5868
6341
|
}
|
|
5869
6342
|
|
|
5870
6343
|
if (e->depth == 0 && e->doc_content) {
|
|
5871
|
-
/* a completed root
|
|
5872
|
-
* root
|
|
5873
|
-
|
|
5874
|
-
|
|
6344
|
+
/* a completed root node followed by more content: a second
|
|
6345
|
+
* root in the same document ("word1 # c\nword2",
|
|
6346
|
+
* "---\n[1]\n[2]"). The oracle law is libyaml's parser
|
|
6347
|
+
* error — the stream wants a document marker and finds a
|
|
6348
|
+
* node ("did not find expected <document start>" at the
|
|
6349
|
+
* offending line's first byte; libyaml marks 2:1/3:1). A
|
|
6350
|
+
* seq entry where the just-closed root map wanted a key is
|
|
6351
|
+
* libyaml's "did not find expected key". Issue #900's
|
|
6352
|
+
* inline-map rows never reach this arm: they die at the
|
|
6353
|
+
* marker-line gate in e_open_map/e_open_seq. */
|
|
6354
|
+
return e_fail_msg(e, YEP_ERR_DOC_BOUNDARY, e->pos + li.indent,
|
|
6355
|
+
map_closed_on_dash ? "did not find expected key"
|
|
6356
|
+
: "did not find expected <document start>");
|
|
5875
6357
|
}
|
|
5876
6358
|
if (e->depth > 0 && e->frames[e->depth - 1].col < c) {
|
|
5877
6359
|
/* deeper than any open container at main dispatch: nested
|
|
@@ -5953,8 +6435,7 @@ static int engine_run_impl(yep_engine* e, const char* buf, size_t len, const yep
|
|
|
5953
6435
|
* the chain below unchanged. */
|
|
5954
6436
|
if (e->depth > 0 && e->pend_anchor.p == NULL && e->pend_tag.p == NULL &&
|
|
5955
6437
|
e->pend_anchor_id == 0 && !e->q_key_pending && !e->q_value_pending &&
|
|
5956
|
-
((e->frames[e->depth - 1].kind == YEP_FRAME_MAP && e->frames[e->depth - 1].col == c
|
|
5957
|
-
!e->frames[e->depth - 1].inline_doc) ||
|
|
6438
|
+
((e->frames[e->depth - 1].kind == YEP_FRAME_MAP && e->frames[e->depth - 1].col == c) ||
|
|
5958
6439
|
(e->frames[e->depth - 1].kind == YEP_FRAME_SEQ && e->frames[e->depth - 1].col == c &&
|
|
5959
6440
|
dash_blank))) {
|
|
5960
6441
|
int frc = e_classified(e, e->frames[e->depth - 1].col);
|
|
@@ -6020,7 +6501,7 @@ static int engine_run_impl(yep_engine* e, const char* buf, size_t len, const yep
|
|
|
6020
6501
|
if (e->anchor_placed != NULL) {
|
|
6021
6502
|
memset(e->anchor_placed, 0, e->anchor_placed_cap);
|
|
6022
6503
|
}
|
|
6023
|
-
e->
|
|
6504
|
+
e->alias_memo.len = 0;
|
|
6024
6505
|
}
|
|
6025
6506
|
if (emit_end) {
|
|
6026
6507
|
e_event_init(&ev, YEP_EV_STREAM_END);
|