yeptris 0.6.65.0-riscv64-linux-gnu → 0.6.66.1-riscv64-linux-gnu
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/yeptris_native/version.h +2 -2
- data/lib/yeptris/ffi.rb +4 -0
- data/lib/yeptris/materializer.rb +38 -13
- data/lib/yeptris/node.rb +1 -1
- data/lib/yeptris/psych/visitors.rb +71 -5
- data/lib/yeptris/psych.rb +178 -88
- data/lib/yeptris/yaml.rb +62 -18
- data/lib/yeptris.rb +1 -1
- data/libyeptris.so +0 -0
- data/vendor/libyeptris/CMakeLists.txt +1 -1
- data/vendor/libyeptris/src/yeptris/cbor/decode.c +43 -7
- data/vendor/libyeptris/src/yeptris/dom/dom.c +18 -0
- data/vendor/libyeptris/src/yeptris/dom/dom.h +24 -16
- data/vendor/libyeptris/src/yeptris/emit/writer.c +375 -29
- data/vendor/libyeptris/src/yeptris/emit/writer.h +6 -0
- data/vendor/libyeptris/src/yeptris/encoding/utf8_validate.c +362 -0
- data/vendor/libyeptris/src/yeptris/parse/engine.c +36 -40
- data/vendor/libyeptris/src/yeptris/scan/scan.c +10 -0
- data/vendor/libyeptris/src/yeptris/scan/scan.h +7 -0
- data/vendor/libyeptris/src/yeptris/tape.c +21 -13
- metadata +1 -1
|
@@ -61,6 +61,9 @@ static void wr_maybe_flush(yep_writer* w) {
|
|
|
61
61
|
* (marshal/to_json.c) writes through the same engine (#904 item 5's
|
|
62
62
|
* move kept ONE writer). */
|
|
63
63
|
void wr_col_update(yep_writer* w, const char* p, uint32_t n) {
|
|
64
|
+
if (w->skip_col) {
|
|
65
|
+
return; /* the non-pretty JSON lanes never read col (#739) */
|
|
66
|
+
}
|
|
64
67
|
for (uint32_t i = n; i > 0; i--) { /* last newline wins */
|
|
65
68
|
if (p[i - 1] == '\n') {
|
|
66
69
|
w->col = (int)(n - i);
|
|
@@ -193,10 +196,12 @@ void wr_reserve(yep_writer* w, size_t need) {
|
|
|
193
196
|
|
|
194
197
|
void wr_byte(yep_writer* w, char c) {
|
|
195
198
|
w->last = c;
|
|
196
|
-
if (
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
199
|
+
if (!w->skip_col) {
|
|
200
|
+
if (c == '\n') {
|
|
201
|
+
w->col = 0;
|
|
202
|
+
} else {
|
|
203
|
+
w->col++;
|
|
204
|
+
}
|
|
200
205
|
}
|
|
201
206
|
if (w->dry) {
|
|
202
207
|
w->len++;
|
|
@@ -541,6 +546,63 @@ void emit_dq_json(yep_writer* w, const char* p, uint32_t n) {
|
|
|
541
546
|
wr_byte(w, '"');
|
|
542
547
|
}
|
|
543
548
|
|
|
549
|
+
/* The fused quote + verbatim + quote write for a string the parse-time
|
|
550
|
+
* fact bit proved JSON-clean (no '"', no '\', no C0 — the #352 law's
|
|
551
|
+
* JSON twin, yeptris#739): the escape loop's per-byte dispatch and the
|
|
552
|
+
* per-run wr_put bookkeeping collapse into one reservation and two
|
|
553
|
+
* memcpys (the quotes sandwich one span). The fixed-window streaming
|
|
554
|
+
* route declines when the whole token cannot fit the window — the
|
|
555
|
+
* general loop chunks it safely (the block specialist's decline law).
|
|
556
|
+
* The trust-the-count routes (grow=0, cap==0) keep wr_put's exact
|
|
557
|
+
* write contract: memcpy at p+len with no capacity reasoning. */
|
|
558
|
+
static void emit_dq_json_raw(yep_writer* w, const char* p, uint32_t n) {
|
|
559
|
+
size_t total = (size_t)n + 2;
|
|
560
|
+
w->last = '"';
|
|
561
|
+
if (!w->skip_col) {
|
|
562
|
+
w->col += (int)total;
|
|
563
|
+
}
|
|
564
|
+
if (w->dry) {
|
|
565
|
+
w->len += total;
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
if (w->oom) {
|
|
569
|
+
w->len += total; /* a failed growth already stopped the writes */
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
if (w->grow && w->bounded) {
|
|
573
|
+
/* the caller-buffer route: oversized is oom, counting goes on */
|
|
574
|
+
if (w->len + total + 1 > w->cap) {
|
|
575
|
+
w->oom = 1;
|
|
576
|
+
w->len += total;
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
} else if (w->grow) {
|
|
580
|
+
if (w->len + total + 1 > w->cap) {
|
|
581
|
+
wr_grow(w, total);
|
|
582
|
+
if (w->oom) {
|
|
583
|
+
w->len += total; /* keep counting: the caller fails on oom */
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
w->reserve = w->cap - w->len - 1;
|
|
587
|
+
}
|
|
588
|
+
} else if (w->cap != 0 && w->len + total + 1 > w->cap) {
|
|
589
|
+
emit_dq_json(w, p, n); /* the window cannot hold the token */
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
if (w->p == NULL) {
|
|
593
|
+
w->len += total; /* the oom'd growable buffer: keep counting */
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
w->reserve = (size_t)total <= w->reserve ? w->reserve - total : 0;
|
|
597
|
+
w->p[w->len++] = '"';
|
|
598
|
+
if (n > 0) {
|
|
599
|
+
memcpy(w->p + w->len, p, n);
|
|
600
|
+
w->len += n;
|
|
601
|
+
}
|
|
602
|
+
w->p[w->len++] = '"';
|
|
603
|
+
wr_maybe_flush(w);
|
|
604
|
+
}
|
|
605
|
+
|
|
544
606
|
/* Literal block: header at the cursor, body lines at parent_col+indent.
|
|
545
607
|
* The explicit indicator spells the pad when it is ambiguous because
|
|
546
608
|
* the pad is defined as parent_col+indent everywhere (the contract
|
|
@@ -649,7 +711,9 @@ static void emit_canonical_scalar(yep_writer* w, const yep_dnode* n) {
|
|
|
649
711
|
if (word != NULL) {
|
|
650
712
|
uint32_t wl = (uint32_t)strlen(word);
|
|
651
713
|
if (w->json) {
|
|
652
|
-
|
|
714
|
+
/* the inf/nan words are punctuation-only constants:
|
|
715
|
+
* the fused raw write is safe without any scan */
|
|
716
|
+
emit_dq_json_raw(w, word, wl);
|
|
653
717
|
} else {
|
|
654
718
|
wr_put(w, word, wl);
|
|
655
719
|
}
|
|
@@ -695,7 +759,15 @@ static void emit_canonical_scalar(yep_writer* w, const yep_dnode* n) {
|
|
|
695
759
|
}
|
|
696
760
|
}
|
|
697
761
|
if (w->json) {
|
|
698
|
-
|
|
762
|
+
/* the parse-time fact bit (#739): a JSON builder-proven clean
|
|
763
|
+
* span skips the escape loop for the fused quote+memcpy+quote
|
|
764
|
+
* write; 0 (YAML-built, mutation-built, tape-decoded-dirty)
|
|
765
|
+
* keeps the byte loop — derive means derive */
|
|
766
|
+
if (n->json_clean) {
|
|
767
|
+
emit_dq_json_raw(w, p, len);
|
|
768
|
+
} else {
|
|
769
|
+
emit_dq_json(w, p, len);
|
|
770
|
+
}
|
|
699
771
|
} else {
|
|
700
772
|
emit_dq(w, p, len);
|
|
701
773
|
}
|
|
@@ -725,6 +797,17 @@ enum { YEP_SC_NOTHING = 0, YEP_SC_PLAIN, YEP_SC_SQ, YEP_SC_DQ, YEP_SC_LITERAL, Y
|
|
|
725
797
|
* machine. PERF-LEDGER carries the numbers. */
|
|
726
798
|
static uint8_t sc_route(yep_writer* w, const char* p, uint32_t len, int as_key, uint8_t sty_in,
|
|
727
799
|
int has_tag, int no_exotic, int plain_fact) {
|
|
800
|
+
/* DQ-preservation rides the recorded style (#352 tail cell): a
|
|
801
|
+
* scalar recorded double-quoted at parse stays double-quoted at
|
|
802
|
+
* emit, and ANY rides the switch's default arm — for sty_in 3 and
|
|
803
|
+
* 0 every route below returns YEP_SC_DQ (the dq-forced check, the
|
|
804
|
+
* flow indicator arm, the switch's default), so the body's walks
|
|
805
|
+
* (the dq-forced rescan, the per-scalar flow indicator loop, the
|
|
806
|
+
* multiline memchr + blockable walk) are dead work on the
|
|
807
|
+
* DQ-heavy cells. Recorded style answers; no re-scan. */
|
|
808
|
+
if (sty_in == 3 || sty_in == 0) {
|
|
809
|
+
return YEP_SC_DQ;
|
|
810
|
+
}
|
|
728
811
|
/* the parse-time fact bits (#352 lanes 2-3): a dnode verified clean
|
|
729
812
|
* of the dq-forced set skips that rescan, and a verified plain-safe
|
|
730
813
|
* span skips the safety walk — 0 (mutation-built or JSON classes)
|
|
@@ -1783,18 +1866,230 @@ static void emit_node(yep_emitter* em, uint32_t id, int parent_col, int as_key)
|
|
|
1783
1866
|
* pretty depth) never fires — yet the generic emit_node ->
|
|
1784
1867
|
* emit_flow path re-tests all of it per node and looks every
|
|
1785
1868
|
* child up twice. This walk emits the same bytes with one
|
|
1786
|
-
* dispatch per node and two per map pair
|
|
1787
|
-
*
|
|
1788
|
-
*
|
|
1869
|
+
* dispatch per node and two per map pair, and carries the node
|
|
1870
|
+
* POINTERS down the recursion (the DOM is const during emit; the
|
|
1871
|
+
* id re-lookups were 5% of the lane's samples). Pretty output
|
|
1872
|
+
* keeps the generic path: its depth/indent bookkeeping is the
|
|
1873
|
+
* point there.
|
|
1874
|
+
*
|
|
1875
|
+
* The pair/item specialists (#739): an unpropertied scalar key whose
|
|
1876
|
+
* value is an unpropertied clean STRING (the json_clean fact) writes
|
|
1877
|
+
* as one fused token — separator, "key", ':', "value" — through one
|
|
1878
|
+
* reservation; a clean string seq item likewise. The general path
|
|
1879
|
+
* writes byte-identical output for the same members (the consult is
|
|
1880
|
+
* strictly narrower than the general arms), so a declined member
|
|
1881
|
+
* changes nothing.
|
|
1789
1882
|
* ============================================================ */
|
|
1790
|
-
static void
|
|
1883
|
+
static void emit_json_node_p(yep_emitter* em, const yep_dnode* n);
|
|
1884
|
+
|
|
1885
|
+
/* The JSON-clean string scalar the specialists take: no tag, no
|
|
1886
|
+
* anchor, no alias, default tag (str), the fact bit set. */
|
|
1887
|
+
static int json_plain_clean_str(const yep_dnode* n) {
|
|
1888
|
+
return n->kind == 0 && n->tag.len == 0 && n->anchor.len == 0 && n->tag_id == 0 && n->json_clean;
|
|
1889
|
+
}
|
|
1890
|
+
|
|
1891
|
+
/* The typed-simple scalars the specialists take as VALUES/items: an
|
|
1892
|
+
* unpropertied null/bool/int/float. Tags decline (JSON quotes tagged
|
|
1893
|
+
* scalars — the default arm), anchors decline (the general path's
|
|
1894
|
+
* wr_anchor_check unserializable law must stay reachable). */
|
|
1895
|
+
static int json_pair_value_ok(const yep_dnode* n) {
|
|
1896
|
+
if (json_plain_clean_str(n)) {
|
|
1897
|
+
return 1;
|
|
1898
|
+
}
|
|
1899
|
+
return n->kind == 0 && n->tag.len == 0 && n->anchor.len == 0 &&
|
|
1900
|
+
(n->tag_id == YEPTRIS_TAG_NULL || n->tag_id == YEPTRIS_TAG_BOOL ||
|
|
1901
|
+
n->tag_id == YEPTRIS_TAG_INT || n->tag_id == YEPTRIS_TAG_FLOAT);
|
|
1902
|
+
}
|
|
1903
|
+
|
|
1904
|
+
/* The fused map pair (#739 cut 4): an unpropertied clean-string key
|
|
1905
|
+
* whose value is any SIMPLE scalar — clean string, null, bool,
|
|
1906
|
+
* JSON-number int, float — writes as one assembled token: separators,
|
|
1907
|
+
* "key", ':', value. The typed spellings are exactly
|
|
1908
|
+
* emit_canonical_scalar's (the same predicates, the same printer);
|
|
1909
|
+
* anything the specialist cannot prove declines to the general path,
|
|
1910
|
+
* so the bytes cannot drift. Short pairs cross in ONE stack-buffer
|
|
1911
|
+
* memcpy; longer ones ride the same piecewise writes. The
|
|
1912
|
+
* fixed-window streaming route never assembles past the window — the
|
|
1913
|
+
* piecewise arm declines per piece like emit_dq_json_raw does. */
|
|
1914
|
+
static int json_pair_value_token(yep_writer* w, const yep_dnode* vn, char* numbuf, const char** tp,
|
|
1915
|
+
uint32_t* tl, int* quoted) {
|
|
1916
|
+
yep_view vv = wv(w, vn->value);
|
|
1917
|
+
const char* p = vv.p;
|
|
1918
|
+
uint32_t len = vv.len;
|
|
1919
|
+
*quoted = 0;
|
|
1920
|
+
switch (vn->tag_id) {
|
|
1921
|
+
case YEPTRIS_TAG_NULL:
|
|
1922
|
+
*tp = "null";
|
|
1923
|
+
*tl = 4;
|
|
1924
|
+
return 1;
|
|
1925
|
+
case YEPTRIS_TAG_BOOL: {
|
|
1926
|
+
int bv = yep_tag_bool_value(p, len);
|
|
1927
|
+
if (bv < 0) {
|
|
1928
|
+
return 0; /* not a bool word: the general path quotes it */
|
|
1929
|
+
}
|
|
1930
|
+
*tp = bv ? "true" : "false";
|
|
1931
|
+
*tl = bv ? 4u : 5u;
|
|
1932
|
+
return 1;
|
|
1933
|
+
}
|
|
1934
|
+
case YEPTRIS_TAG_INT:
|
|
1935
|
+
if (json_int_token(p, len)) {
|
|
1936
|
+
*tp = p;
|
|
1937
|
+
*tl = len;
|
|
1938
|
+
return 1;
|
|
1939
|
+
}
|
|
1940
|
+
return 0; /* decode-and-respell ints stay on the general path */
|
|
1941
|
+
case YEPTRIS_TAG_FLOAT: {
|
|
1942
|
+
const char* word = yep_tag_float_word(p, len);
|
|
1943
|
+
if (word != NULL) {
|
|
1944
|
+
/* the inf/nan words ride QUOTED in JSON (no JSON infinity):
|
|
1945
|
+
* punctuation-only constants, safe to assemble raw */
|
|
1946
|
+
*tp = word;
|
|
1947
|
+
*tl = (uint32_t)strlen(word);
|
|
1948
|
+
*quoted = 1;
|
|
1949
|
+
return 1;
|
|
1950
|
+
}
|
|
1951
|
+
char* end = NULL;
|
|
1952
|
+
/* the SAME 39-byte truncation the general arm strtod's through
|
|
1953
|
+
* (emit_canonical_scalar's tmp[40]): a longer numeric token
|
|
1954
|
+
* must accept/parse identically or the d2s bytes would drift */
|
|
1955
|
+
uint32_t copy = len < 39u ? len : 39u;
|
|
1956
|
+
memcpy(numbuf, p, copy);
|
|
1957
|
+
numbuf[copy] = '\0';
|
|
1958
|
+
double d = strtod(numbuf, &end);
|
|
1959
|
+
if (end == NULL || *end != '\0' || end == numbuf) {
|
|
1960
|
+
return 0; /* unparseable view: the general path quotes it */
|
|
1961
|
+
}
|
|
1962
|
+
*tl = (uint32_t)yep_d2s_json(d, numbuf);
|
|
1963
|
+
*tp = numbuf;
|
|
1964
|
+
return 1;
|
|
1965
|
+
}
|
|
1966
|
+
default:
|
|
1967
|
+
return 0;
|
|
1968
|
+
}
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1971
|
+
/* Returns 1 = wrote (dry counts too), 0 = declined (no bytes
|
|
1972
|
+
* written — the caller takes the general path). */
|
|
1973
|
+
static int emit_json_pair_fused(yep_writer* w, const yep_dnode* kn, const yep_dnode* vn, int sep) {
|
|
1974
|
+
yep_view kv = wv(w, kn->value);
|
|
1975
|
+
yep_view vv = wv(w, vn->value);
|
|
1976
|
+
int vstr = json_plain_clean_str(vn);
|
|
1977
|
+
char numbuf[48];
|
|
1978
|
+
const char* vt = NULL;
|
|
1979
|
+
uint32_t vtl = 0;
|
|
1980
|
+
int vquoted = 0;
|
|
1981
|
+
int typed = vstr ? 0 : json_pair_value_token(w, vn, numbuf, &vt, &vtl, &vquoted);
|
|
1982
|
+
if (!vstr && !typed) {
|
|
1983
|
+
return 0; /* a typed token the general path must respell/quote */
|
|
1984
|
+
}
|
|
1985
|
+
uint32_t sep_len = 0;
|
|
1986
|
+
if (sep) {
|
|
1987
|
+
sep_len = w->json_compact ? 1u : 2u;
|
|
1988
|
+
}
|
|
1989
|
+
uint32_t colon_len = w->json_compact ? 1u : 2u;
|
|
1990
|
+
uint32_t total =
|
|
1991
|
+
sep_len + kv.len + 2u + colon_len + (typed ? (vquoted ? 2u : 0u) + vtl : 2u + vv.len);
|
|
1992
|
+
/* the run-end law reads w->last for the root newline: spell the
|
|
1993
|
+
* byte that actually lands last (a digit tail for plain tokens) */
|
|
1994
|
+
w->last = (typed && !vquoted && vtl > 0) ? vt[vtl - 1] : '"';
|
|
1995
|
+
if (!w->skip_col) {
|
|
1996
|
+
w->col += (int)total;
|
|
1997
|
+
}
|
|
1998
|
+
if (w->dry) {
|
|
1999
|
+
w->len += total;
|
|
2000
|
+
return 1;
|
|
2001
|
+
}
|
|
2002
|
+
/* the assembled fast form: short pairs only, and only where the
|
|
2003
|
+
* write lands whole (the streaming window declines to piecewise) */
|
|
2004
|
+
int can_assemble = total <= 128u;
|
|
2005
|
+
if (can_assemble && !w->grow && w->cap != 0 && w->len + (size_t)total + 1 > w->cap) {
|
|
2006
|
+
can_assemble = 0; /* the window cannot hold the token */
|
|
2007
|
+
}
|
|
2008
|
+
if (can_assemble && !w->oom) {
|
|
2009
|
+
if (w->grow && !w->bounded && w->len + (size_t)total + 1 > w->cap) {
|
|
2010
|
+
wr_grow(w, total);
|
|
2011
|
+
if (w->oom) {
|
|
2012
|
+
w->len += total; /* keep counting: the caller fails on oom */
|
|
2013
|
+
return 1;
|
|
2014
|
+
}
|
|
2015
|
+
w->reserve = w->cap - w->len - 1;
|
|
2016
|
+
} else if (w->grow && w->bounded && w->len + (size_t)total + 1 > w->cap) {
|
|
2017
|
+
w->oom = 1;
|
|
2018
|
+
w->len += total;
|
|
2019
|
+
return 1;
|
|
2020
|
+
}
|
|
2021
|
+
char* q = w->p + w->len;
|
|
2022
|
+
w->reserve = (size_t)total <= w->reserve ? w->reserve - total : 0;
|
|
2023
|
+
if (sep_len == 1u) {
|
|
2024
|
+
*q++ = ',';
|
|
2025
|
+
} else if (sep_len == 2u) {
|
|
2026
|
+
memcpy(q, ", ", 2);
|
|
2027
|
+
q += 2;
|
|
2028
|
+
}
|
|
2029
|
+
*q++ = '"';
|
|
2030
|
+
if (kv.len > 0) {
|
|
2031
|
+
memcpy(q, kv.p, kv.len);
|
|
2032
|
+
q += kv.len;
|
|
2033
|
+
}
|
|
2034
|
+
*q++ = '"';
|
|
2035
|
+
if (colon_len == 1u) {
|
|
2036
|
+
*q++ = ':';
|
|
2037
|
+
} else {
|
|
2038
|
+
memcpy(q, ": ", 2);
|
|
2039
|
+
q += 2;
|
|
2040
|
+
}
|
|
2041
|
+
if (typed) {
|
|
2042
|
+
if (vquoted) {
|
|
2043
|
+
*q++ = '"';
|
|
2044
|
+
}
|
|
2045
|
+
if (vtl > 0) {
|
|
2046
|
+
memcpy(q, vt, vtl);
|
|
2047
|
+
q += vtl;
|
|
2048
|
+
}
|
|
2049
|
+
if (vquoted) {
|
|
2050
|
+
*q++ = '"';
|
|
2051
|
+
}
|
|
2052
|
+
} else {
|
|
2053
|
+
*q++ = '"';
|
|
2054
|
+
if (vv.len > 0) {
|
|
2055
|
+
memcpy(q, vv.p, vv.len);
|
|
2056
|
+
q += vv.len;
|
|
2057
|
+
}
|
|
2058
|
+
*q++ = '"';
|
|
2059
|
+
}
|
|
2060
|
+
w->len += total;
|
|
2061
|
+
wr_maybe_flush(w);
|
|
2062
|
+
return 1;
|
|
2063
|
+
}
|
|
2064
|
+
/* piecewise: same bytes, each piece carries its own decline law */
|
|
2065
|
+
if (sep) {
|
|
2066
|
+
if (w->json_compact) {
|
|
2067
|
+
wr_byte(w, ',');
|
|
2068
|
+
} else {
|
|
2069
|
+
wr_put(w, ", ", 2);
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2072
|
+
emit_dq_json_raw(w, kv.p, kv.len);
|
|
2073
|
+
if (w->json_compact) {
|
|
2074
|
+
wr_byte(w, ':');
|
|
2075
|
+
} else {
|
|
2076
|
+
wr_put(w, ": ", 2);
|
|
2077
|
+
}
|
|
2078
|
+
if (vstr) {
|
|
2079
|
+
emit_dq_json_raw(w, vv.p, vv.len);
|
|
2080
|
+
} else if (vquoted) {
|
|
2081
|
+
emit_dq_json_raw(w, vt, vtl);
|
|
2082
|
+
} else {
|
|
2083
|
+
wr_put(w, vt, vtl);
|
|
2084
|
+
}
|
|
2085
|
+
return 1;
|
|
2086
|
+
}
|
|
1791
2087
|
|
|
1792
|
-
static void
|
|
2088
|
+
static void emit_json_flow_p(yep_emitter* em, const yep_dnode* n) {
|
|
1793
2089
|
yep_writer* w = &em->w;
|
|
1794
2090
|
int saved_flow = w->in_flow;
|
|
1795
2091
|
w->in_flow = 1;
|
|
1796
2092
|
const yep_dom* d = em->doc->dom;
|
|
1797
|
-
const yep_dnode* n = yep_dom_node(d, id);
|
|
1798
2093
|
if (n->tag.len > 0) {
|
|
1799
2094
|
emit_tag(w, n);
|
|
1800
2095
|
}
|
|
@@ -1807,36 +2102,83 @@ static void emit_json_flow(yep_emitter* em, uint32_t id) {
|
|
|
1807
2102
|
uint32_t idx = 0;
|
|
1808
2103
|
while (child != UINT32_MAX) {
|
|
1809
2104
|
const yep_dnode* cn = yep_dom_node(d, child);
|
|
1810
|
-
if (
|
|
1811
|
-
|
|
1812
|
-
wr_byte(w, ',');
|
|
1813
|
-
} else {
|
|
1814
|
-
wr_put(w, ", ", 2);
|
|
1815
|
-
}
|
|
2105
|
+
if (cn == NULL) {
|
|
2106
|
+
break;
|
|
1816
2107
|
}
|
|
1817
2108
|
if (map) {
|
|
2109
|
+
const yep_dnode* vn = yep_dom_node(d, cn->next_sibling);
|
|
2110
|
+
/* the specialist: clean string key + simple scalar value */
|
|
2111
|
+
if (vn != NULL && json_plain_clean_str(cn) && json_pair_value_ok(vn)) {
|
|
2112
|
+
if (emit_json_pair_fused(w, cn, vn, idx > 0)) {
|
|
2113
|
+
child = vn->next_sibling;
|
|
2114
|
+
idx++;
|
|
2115
|
+
continue;
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
2118
|
+
if (idx > 0) {
|
|
2119
|
+
if (w->json_compact) {
|
|
2120
|
+
wr_byte(w, ',');
|
|
2121
|
+
} else {
|
|
2122
|
+
wr_put(w, ", ", 2);
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
1818
2125
|
/* the one generic-path rule JSON keeps: a non-scalar key
|
|
1819
2126
|
* rides the explicit "? key : " form — same bytes emit_flow
|
|
1820
2127
|
* writes. (Propertied scalar keys used to join it; JSON
|
|
1821
2128
|
* drops properties, so they ride the plain quoted form.) */
|
|
1822
2129
|
if (cn->kind != 0) {
|
|
1823
2130
|
wr_put(w, "? ", 2);
|
|
1824
|
-
|
|
2131
|
+
emit_json_node_p(em, cn);
|
|
1825
2132
|
wr_put(w, " : ", 3);
|
|
1826
2133
|
} else {
|
|
1827
|
-
|
|
2134
|
+
emit_json_node_p(em, cn);
|
|
1828
2135
|
if (w->json_compact) {
|
|
1829
2136
|
wr_byte(w, ':');
|
|
1830
2137
|
} else {
|
|
1831
2138
|
wr_put(w, ": ", 2);
|
|
1832
2139
|
}
|
|
1833
2140
|
}
|
|
1834
|
-
|
|
1835
|
-
emit_json_node(em, val);
|
|
1836
|
-
const yep_dnode* vn = yep_dom_node(d, val);
|
|
2141
|
+
emit_json_node_p(em, vn);
|
|
1837
2142
|
child = vn != NULL ? vn->next_sibling : UINT32_MAX;
|
|
1838
2143
|
} else {
|
|
1839
|
-
|
|
2144
|
+
/* the item specialist: a clean string or simple scalar item;
|
|
2145
|
+
* the token resolve runs before any byte is written, so a
|
|
2146
|
+
* decline reaches the general path untouched */
|
|
2147
|
+
char numbuf[48];
|
|
2148
|
+
const char* vt = NULL;
|
|
2149
|
+
uint32_t vtl = 0;
|
|
2150
|
+
int vquoted = 0;
|
|
2151
|
+
int fused = json_pair_value_ok(cn) &&
|
|
2152
|
+
(json_plain_clean_str(cn) ||
|
|
2153
|
+
json_pair_value_token(w, cn, numbuf, &vt, &vtl, &vquoted));
|
|
2154
|
+
if (fused) {
|
|
2155
|
+
if (idx > 0) {
|
|
2156
|
+
if (w->json_compact) {
|
|
2157
|
+
wr_byte(w, ',');
|
|
2158
|
+
} else {
|
|
2159
|
+
wr_put(w, ", ", 2);
|
|
2160
|
+
}
|
|
2161
|
+
}
|
|
2162
|
+
if (json_plain_clean_str(cn)) {
|
|
2163
|
+
yep_view cv = wv(w, cn->value);
|
|
2164
|
+
emit_dq_json_raw(w, cv.p, cv.len);
|
|
2165
|
+
} else if (vquoted) {
|
|
2166
|
+
emit_dq_json_raw(w, vt, vtl);
|
|
2167
|
+
} else {
|
|
2168
|
+
wr_put(w, vt, vtl);
|
|
2169
|
+
}
|
|
2170
|
+
child = cn->next_sibling;
|
|
2171
|
+
idx++;
|
|
2172
|
+
continue;
|
|
2173
|
+
}
|
|
2174
|
+
if (idx > 0) {
|
|
2175
|
+
if (w->json_compact) {
|
|
2176
|
+
wr_byte(w, ',');
|
|
2177
|
+
} else {
|
|
2178
|
+
wr_put(w, ", ", 2);
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
emit_json_node_p(em, cn);
|
|
1840
2182
|
child = cn->next_sibling;
|
|
1841
2183
|
}
|
|
1842
2184
|
idx++;
|
|
@@ -1845,10 +2187,8 @@ static void emit_json_flow(yep_emitter* em, uint32_t id) {
|
|
|
1845
2187
|
w->in_flow = saved_flow;
|
|
1846
2188
|
}
|
|
1847
2189
|
|
|
1848
|
-
static void
|
|
2190
|
+
static void emit_json_node_p(yep_emitter* em, const yep_dnode* n) {
|
|
1849
2191
|
yep_writer* w = &em->w;
|
|
1850
|
-
const yep_dom* d = em->doc->dom;
|
|
1851
|
-
const yep_dnode* n = yep_dom_node(d, id);
|
|
1852
2192
|
if (n == NULL) {
|
|
1853
2193
|
return;
|
|
1854
2194
|
}
|
|
@@ -1857,7 +2197,7 @@ static void emit_json_node(yep_emitter* em, uint32_t id) {
|
|
|
1857
2197
|
return;
|
|
1858
2198
|
}
|
|
1859
2199
|
if (n->kind == 1 || n->kind == 2) {
|
|
1860
|
-
|
|
2200
|
+
emit_json_flow_p(em, n);
|
|
1861
2201
|
return;
|
|
1862
2202
|
}
|
|
1863
2203
|
if (n->tag.len > 0) {
|
|
@@ -1881,6 +2221,12 @@ size_t yep_emit_run(yep_emitter* em, int dry) {
|
|
|
1881
2221
|
w->sink_aborted = 0;
|
|
1882
2222
|
w->col = 0;
|
|
1883
2223
|
w->sc_i = 0;
|
|
2224
|
+
/* #739: the JSON lanes that never fold set skip_col — the fold
|
|
2225
|
+
* machinery (plain-fold column, flow wrap, pretty depth) is the
|
|
2226
|
+
* only col reader, and none of it arms without json_pretty. One
|
|
2227
|
+
* assignment per run covers every em.w init site (the ledger's
|
|
2228
|
+
* zero-every-field law). */
|
|
2229
|
+
w->skip_col = w->json && !w->json_pretty;
|
|
1884
2230
|
yep_nametab_clear(&em->canon_names);
|
|
1885
2231
|
if (w->json) {
|
|
1886
2232
|
/* JSON has no multi-document streams and no document marker */
|
|
@@ -1889,7 +2235,7 @@ size_t yep_emit_run(yep_emitter* em, int dry) {
|
|
|
1889
2235
|
if (w->json_pretty) {
|
|
1890
2236
|
emit_node(em, d->docs[0], -2, 0);
|
|
1891
2237
|
} else {
|
|
1892
|
-
|
|
2238
|
+
emit_json_node_p(em, root);
|
|
1893
2239
|
}
|
|
1894
2240
|
if (root != NULL && root->kind != 0 && w->last != '\n') {
|
|
1895
2241
|
wr_byte(w, '\n');
|
|
@@ -45,6 +45,12 @@ typedef struct yep_writer {
|
|
|
45
45
|
int block_fold; /* #903: plain/quoted block scalars fold at
|
|
46
46
|
* best_width (libyaml's plain-fold walk) */
|
|
47
47
|
int col; /* current output column (wr_* maintains) */
|
|
48
|
+
int skip_col; /* #739: the column is the YAML fold machinery's
|
|
49
|
+
input — the non-pretty JSON lanes never read it,
|
|
50
|
+
so wr_byte/wr_put skip the maintenance (wr_put's
|
|
51
|
+
per-span '\n' scan was 25% of the json write
|
|
52
|
+
lane's samples). Set per run in yep_emit_run
|
|
53
|
+
(json && !json_pretty); 0 everywhere else. */
|
|
48
54
|
const char* sv_input; /* compact-view decode bases (dom regions) */
|
|
49
55
|
const char* sv_arena;
|
|
50
56
|
/* #352: per-scalar route decisions, derived once in the dry
|