yeptris 0.6.92.0 → 0.6.93.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9418de3ea924d761ba96ad1107b42ddc10e073bd1c09e85edc415a956b632079
4
- data.tar.gz: 9a109c6295ec4450ee5a805078a5529fd3bea6c2aa8367f2b3a74178be67be60
3
+ metadata.gz: ee20a929e13fd845944b219f2aeabd74364f7f978de60828de494639252af0bd
4
+ data.tar.gz: 63be5b9753533d46a765dfae918a75c1491579268d72f0e5e419b4788bf9f931
5
5
  SHA512:
6
- metadata.gz: a934ef6e78620f4e692858b59a4a9f5bafce01683a62331a32fead37a4e7ab6453e7708c1e1fa8bde5e47ebf224dfc127f672f031093779fc910442dacd72c43
7
- data.tar.gz: a16e3245c0cc48af33c2ae34ecdeb274c11cdda913f38101fdc3eefa00105b0d13898a7f7b2cebcf5640f866b61ca49a1a085236e855dc542b22ae3721102a8b
6
+ metadata.gz: 68a51cc552ea5696c3a0981ad6271a754805f0a321baf4dd385cda8f9b170e1ec22efc5d88e1f55e6ac8c18e037b0c92b4a3d6d57825bf4221636f6bdc9d338b
7
+ data.tar.gz: da3499bc792666fdf364e0f847e19f3a436f45103c66985b2a3c0a5833d263839eac14e5b65b6fe5986afd676f7f35388203457599c34e0263696d02fa1d939f
data/lib/yeptris.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module Yeptris
4
4
  # The gem's version lives in the parent namespace's file — the last
5
5
  # internal require (yeptris/version) retired with it.
6
- VERSION = "0.6.92.0".freeze
6
+ VERSION = "0.6.93.0".freeze
7
7
 
8
8
  # Informational notices are OPT-IN (yeptris-ruby#217): consumers
9
9
  # embed yeptris inside CLIs that assert clean stderr, and a
@@ -3,7 +3,7 @@
3
3
  cmake_minimum_required(VERSION 3.20)
4
4
 
5
5
  project(yeptris
6
- VERSION 0.6.92
6
+ VERSION 0.6.93
7
7
  DESCRIPTION "Ultra-fast YAML 1.2 parser, emitter and streamer in C"
8
8
  LANGUAGES C CXX
9
9
  )
@@ -55,18 +55,26 @@ YEPTRIS_API size_t yeptris_plan_column_count(const yeptris_plan* plan);
55
55
 
56
56
  /* Applies the plan to a tape (from yeptris_parse_json_tape; the
57
57
  * LENIENT tape also works — NUM records convert at extraction).
58
- * Every row of the collection fills one slot per column; missing or
59
- * null leaves mark the slot null. Returns NULL with *st on
60
- * PARSE (document shape disagreement) or MEMORY. */
58
+ * The rows container's shape decides the rows: a SEQUENCE rows its
59
+ * mapping children; a MAPPING rows its mapping values (the
60
+ * map-of-records form) — unless one of the mapping's OWN keys names
61
+ * a planned leaf, which makes the mapping itself ONE record (the
62
+ * scalar-map leaf: rows = 1, the pairs fill the columns). An empty
63
+ * container rows nothing. Every row fills one slot per column;
64
+ * missing, null, mistyped, or container-valued leaves mark the slot
65
+ * null. Returns NULL with *st on PARSE (document shape
66
+ * disagreement) or MEMORY. */
61
67
  YEPTRIS_API yeptris_plan_result*
62
68
  yeptris_tape_plan_walk(const yeptris_json_tape* tape, const yeptris_plan* plan, YeptrisStatus* st);
63
69
 
64
70
  /* The YAML/DOM leg: the same compiled plan applied to a parsed
65
- * yeptris document (yeptris_parse — any schema). Typed extraction
66
- * rides the parse-time tag ids; string columns expose (ptr,len)
67
- * views into the document's regions (input or string arena), so the
68
- * RESULT BORROWS the document — free the result first. Same status
69
- * contract as the tape walk. */
71
+ * yeptris document (yeptris_parse — any schema), with the same row
72
+ * semantics as the tape walk (sequence children; mapping values; a
73
+ * mapping whose own key names a planned leaf is ONE record). Typed
74
+ * extraction rides the parse-time tag ids; string columns expose
75
+ * (ptr,len) views into the document's regions (input or string
76
+ * arena), so the RESULT BORROWS the document — free the result
77
+ * first. Same status contract as the tape walk. */
70
78
  YEPTRIS_API yeptris_plan_result*
71
79
  yeptris_document_plan_walk(YeptrisDocument doc, const yeptris_plan* plan, YeptrisStatus* st);
72
80
 
@@ -285,6 +285,18 @@ YEPTRIS_API size_t yeptris_plan_column_count(const yeptris_plan* plan) {
285
285
  return plan == NULL ? 0 : plan->ncols;
286
286
  }
287
287
 
288
+ /* The planned column the tape STR record at +i+ names, or -1. */
289
+ static int tape_leaf_index(const yeptris_json_tape* t, const yeptris_plan* plan, size_t i) {
290
+ const char* src = (const char*)t->_src;
291
+ for (size_t c = 0; c < plan->ncols; c++) {
292
+ if (t->lens[i] == plan->cols[c].name_len &&
293
+ memcmp(src + t->offs[i], plan->cols[c].name, plan->cols[c].name_len) == 0) {
294
+ return (int)c;
295
+ }
296
+ }
297
+ return -1;
298
+ }
299
+
288
300
  /* Finds the rows container's OPEN record: the root OPEN's child
289
301
  * matching each path segment in turn (a map root), or the root OPEN
290
302
  * itself (a seq root). Returns the record index of the container
@@ -447,35 +459,69 @@ yeptris_tape_plan_walk(const yeptris_json_tape* tape, const yeptris_plan* plan,
447
459
  }
448
460
  size_t rows_close = tape->offs[rows_open];
449
461
 
450
- /* pass one: count the row MAP_OPENs directly inside the container */
462
+ /* pass one: classify the container + count the rows. A sequence
463
+ * container rows its mapping children. A mapping container rows
464
+ * its mapping values (the map-of-records form) — unless one of
465
+ * its OWN keys names a planned leaf, which makes the mapping
466
+ * itself ONE record (the scalar-map leaf, yeptris-ruby#430: its
467
+ * pairs are the record's fields). An empty container rows
468
+ * nothing. */
469
+ int record_mode = 0;
451
470
  size_t rows = 0;
452
- {
471
+ if (rows_kind == YEP_T_SEQ_OPEN) {
453
472
  int depth = 0;
454
473
  for (size_t i = rows_open + 1; i < rows_close; i++) {
455
474
  uint8_t k = tape->kinds[i];
456
- if (depth == 0 && k == YEP_T_MAP_OPEN) {
457
- rows++;
458
- }
459
- if (k == YEP_T_MAP_OPEN || k == YEP_T_SEQ_OPEN) {
475
+ if (k == YEP_T_MAP_OPEN) {
476
+ if (depth == 0) {
477
+ rows++;
478
+ }
479
+ depth++;
480
+ } else if (k == YEP_T_SEQ_OPEN) {
460
481
  depth++;
461
482
  } else if (k == YEP_T_CLOSE) {
462
483
  depth--;
463
484
  }
464
485
  }
486
+ } else {
487
+ /* the mapping container: a depth-0 pair walk — containers
488
+ * skip whole at their CLOSE, so no depth counter is needed */
489
+ int expect_key = 1;
490
+ for (size_t i = rows_open + 1; i < rows_close; i++) {
491
+ uint8_t k = tape->kinds[i];
492
+ if (expect_key) {
493
+ if (k == YEP_T_STR && tape_leaf_index(tape, plan, i) >= 0) {
494
+ record_mode = 1;
495
+ }
496
+ expect_key = 0;
497
+ continue;
498
+ }
499
+ expect_key = 1;
500
+ if (k == YEP_T_MAP_OPEN || k == YEP_T_SEQ_OPEN) {
501
+ if (k == YEP_T_MAP_OPEN) {
502
+ rows++; /* a mapping value: one row of the records form */
503
+ }
504
+ i = tape->offs[i]; /* the row (or record field) ends at its CLOSE */
505
+ }
506
+ }
507
+ if (record_mode) {
508
+ rows = 1;
509
+ }
465
510
  }
466
511
 
467
- size_t ncols = plan->ncols;
468
512
  yeptris_plan_result* r = plan_result_carve(plan, rows, 8, st);
469
513
  if (r == NULL) {
470
514
  return NULL;
471
515
  }
472
516
 
473
517
  /* pass two: fill. Rows are MAP_OPEN..CLOSE at container depth 0;
474
- * each pair's key span matches a planned leaf name. */
518
+ * each pair's key span matches a planned leaf name. Record mode:
519
+ * the container itself is the one row — its pairs sit one level
520
+ * in, so the walk enters it already "inside a row". */
475
521
  const char* src = (const char*)tape->_src;
476
522
  size_t row = 0;
477
- int depth = 0;
478
- int row_start = 0;
523
+ int depth = record_mode ? 1 : 0;
524
+ int row_start = record_mode;
479
525
  for (size_t i = rows_open + 1; i < rows_close && row < rows; i++) {
480
526
  uint8_t k = tape->kinds[i];
481
527
  if (k == YEP_T_MAP_OPEN || k == YEP_T_SEQ_OPEN) {
@@ -497,14 +543,7 @@ yeptris_tape_plan_walk(const yeptris_json_tape* tape, const yeptris_plan* plan,
497
543
  continue; /* not a key position inside a row map */
498
544
  }
499
545
  /* the key: match against the plan leaves */
500
- int col_idx = -1;
501
- for (size_t c = 0; c < ncols; c++) {
502
- if (tape->lens[i] == plan->cols[c].name_len &&
503
- memcmp(src + tape->offs[i], plan->cols[c].name, plan->cols[c].name_len) == 0) {
504
- col_idx = (int)c;
505
- break;
506
- }
507
- }
546
+ int col_idx = tape_leaf_index(tape, plan, i);
508
547
  if (col_idx < 0) {
509
548
  continue; /* not a planned leaf: skip its value below */
510
549
  }
@@ -565,6 +604,10 @@ yeptris_tape_plan_walk(const yeptris_json_tape* tape, const yeptris_plan* plan,
565
604
  break;
566
605
  }
567
606
  i = v; /* the value record is consumed */
607
+ if (vk == YEP_T_MAP_OPEN || vk == YEP_T_SEQ_OPEN) {
608
+ i = tape->offs[v]; /* a container at a planned leaf ends at
609
+ * its CLOSE — its keys are NOT row keys */
610
+ }
568
611
  continue;
569
612
  bad_row_value:
570
613
  i = v;
@@ -656,6 +699,106 @@ static uint32_t dom_rows_next(const yep_dom* d, const yep_dnode* container, uint
656
699
  return v->next_sibling;
657
700
  }
658
701
 
702
+ /* The single-record form (yeptris-ruby#430): a MAPPING container one
703
+ * of whose OWN keys names a planned leaf IS the record — its pairs
704
+ * are the fields. Returns the container, or NULL (rows come from the
705
+ * mapping values / sequence children instead). */
706
+ static const yep_dnode* dom_single_record(const yep_dom* d, const yep_dnode* container,
707
+ const yeptris_plan* plan) {
708
+ if (container->kind != YEP_DOM_MAPPING) {
709
+ return NULL;
710
+ }
711
+ for (uint32_t cn = container->first_child; cn != UINT32_MAX;) {
712
+ const yep_dnode* k = yep_dom_node(d, cn);
713
+ const yep_dnode* v = yep_dom_node(d, k->next_sibling);
714
+ yep_view kv = sv_view(d, k->value);
715
+ if (k->kind == YEP_DOM_SCALAR) {
716
+ for (size_t c = 0; c < plan->ncols; c++) {
717
+ if (kv.len == plan->cols[c].name_len &&
718
+ memcmp(kv.p, plan->cols[c].name, plan->cols[c].name_len) == 0) {
719
+ return container;
720
+ }
721
+ }
722
+ }
723
+ cn = v->next_sibling;
724
+ }
725
+ return NULL;
726
+ }
727
+
728
+ /* Fills row +row_i+ of +r+ from +row+'s pairs: each scalar key is
729
+ * matched against the planned leaves, and the value lands in its
730
+ * column when the tag agrees. Null / missing / mistyped / container
731
+ * values leave the slot null (the carve pre-set the bitmap). */
732
+ static void dom_fill_row(const yep_dom* d, const yeptris_plan* plan, const yep_dnode* row,
733
+ size_t row_i, yeptris_plan_result* r) {
734
+ for (uint32_t cn = row->first_child; cn != UINT32_MAX;) {
735
+ const yep_dnode* k = yep_dom_node(d, cn);
736
+ const yep_dnode* v = yep_dom_node(d, k->next_sibling);
737
+ yep_view kv = sv_view(d, k->value);
738
+ int col_idx = -1;
739
+ if (k->kind == YEP_DOM_SCALAR) {
740
+ for (size_t c = 0; c < plan->ncols; c++) {
741
+ if (kv.len == plan->cols[c].name_len &&
742
+ memcmp(kv.p, plan->cols[c].name, plan->cols[c].name_len) == 0) {
743
+ col_idx = (int)c;
744
+ break;
745
+ }
746
+ }
747
+ }
748
+ if (col_idx >= 0) {
749
+ const yep_dnode* val = dom_alias_final(d, v);
750
+ yep_result_col* col = &r->cols[col_idx];
751
+ if (val != NULL && val->kind == YEP_DOM_SCALAR && val->tag_id != YEPTRIS_TAG_NULL) {
752
+ yep_view sv = sv_view(d, val->value);
753
+ int filled = 0;
754
+ switch (col->kind) {
755
+ case YEP_PLAN_STR:
756
+ col->views[row_i].p = sv.p;
757
+ col->views[row_i].len = sv.len;
758
+ filled = 1;
759
+ break;
760
+ case YEP_PLAN_INT: {
761
+ int64_t iv;
762
+ if (val->tag_id == YEPTRIS_TAG_INT && yep_num_i64(sv.p, sv.len, &iv) == 0) {
763
+ col->ints[row_i] = iv;
764
+ filled = 1;
765
+ }
766
+ break;
767
+ }
768
+ case YEP_PLAN_FLOAT: {
769
+ double dv;
770
+ if (val->tag_id == YEPTRIS_TAG_FLOAT) {
771
+ if (yep_num_f64(sv.p, sv.len, &dv) == 0) {
772
+ col->floats[row_i] = dv;
773
+ filled = 1;
774
+ }
775
+ } else if (val->tag_id == YEPTRIS_TAG_INT) {
776
+ int64_t iv;
777
+ if (yep_num_i64(sv.p, sv.len, &iv) == 0) {
778
+ col->floats[row_i] = (double)iv;
779
+ filled = 1;
780
+ }
781
+ }
782
+ break;
783
+ }
784
+ case YEP_PLAN_BOOL:
785
+ if (val->tag_id == YEPTRIS_TAG_BOOL) {
786
+ col->ints[row_i] = yep_num_bool(sv.p, sv.len);
787
+ filled = 1;
788
+ }
789
+ break;
790
+ }
791
+ if (filled) {
792
+ col->nulls[row_i] = 0;
793
+ }
794
+ }
795
+ /* null / missing / tag disagreement / a container at a
796
+ * planned leaf: the slot stays null, the walk goes on */
797
+ }
798
+ cn = v->next_sibling;
799
+ }
800
+ }
801
+
659
802
  YEPTRIS_API yeptris_plan_result*
660
803
  yeptris_document_plan_walk(YeptrisDocument doc, const yeptris_plan* plan, YeptrisStatus* st) {
661
804
  if (st != NULL) {
@@ -677,12 +820,18 @@ yeptris_document_plan_walk(YeptrisDocument doc, const yeptris_plan* plan, Yeptri
677
820
  return NULL;
678
821
  }
679
822
 
823
+ /* the single-record form wins over the mapping-values form */
824
+ const yep_dnode* single = dom_single_record(dd, container, plan);
680
825
  size_t rows = 0;
681
- for (uint32_t cur = container->first_child; cur != UINT32_MAX;) {
682
- const yep_dnode* row;
683
- cur = dom_rows_next(dd, container, cur, &row);
684
- if (row != NULL) {
685
- rows++;
826
+ if (single != NULL) {
827
+ rows = 1;
828
+ } else {
829
+ for (uint32_t cur = container->first_child; cur != UINT32_MAX;) {
830
+ const yep_dnode* row;
831
+ cur = dom_rows_next(dd, container, cur, &row);
832
+ if (row != NULL) {
833
+ rows++;
834
+ }
686
835
  }
687
836
  }
688
837
 
@@ -691,6 +840,10 @@ yeptris_document_plan_walk(YeptrisDocument doc, const yeptris_plan* plan, Yeptri
691
840
  return NULL;
692
841
  }
693
842
 
843
+ if (single != NULL) {
844
+ dom_fill_row(dd, plan, single, 0, r);
845
+ return r;
846
+ }
694
847
  size_t row_i = 0;
695
848
  for (uint32_t cur = container->first_child; cur != UINT32_MAX && row_i < rows;) {
696
849
  const yep_dnode* row;
@@ -698,73 +851,7 @@ yeptris_document_plan_walk(YeptrisDocument doc, const yeptris_plan* plan, Yeptri
698
851
  if (row == NULL) {
699
852
  continue;
700
853
  }
701
- uint32_t cn = row->first_child;
702
- while (cn != UINT32_MAX) {
703
- const yep_dnode* k = yep_dom_node(dd, cn);
704
- const yep_dnode* v = yep_dom_node(dd, k->next_sibling);
705
- yep_view kv = sv_view(dd, k->value);
706
- int col_idx = -1;
707
- if (k->kind == YEP_DOM_SCALAR) {
708
- for (size_t c = 0; c < plan->ncols; c++) {
709
- if (kv.len == plan->cols[c].name_len &&
710
- memcmp(kv.p, plan->cols[c].name, plan->cols[c].name_len) == 0) {
711
- col_idx = (int)c;
712
- break;
713
- }
714
- }
715
- }
716
- if (col_idx >= 0) {
717
- const yep_dnode* val = dom_alias_final(dd, v);
718
- yep_result_col* col = &r->cols[col_idx];
719
- if (val != NULL && val->kind == YEP_DOM_SCALAR && val->tag_id != YEPTRIS_TAG_NULL) {
720
- yep_view sv = sv_view(dd, val->value);
721
- int filled = 0;
722
- switch (col->kind) {
723
- case YEP_PLAN_STR:
724
- col->views[row_i].p = sv.p;
725
- col->views[row_i].len = sv.len;
726
- filled = 1;
727
- break;
728
- case YEP_PLAN_INT: {
729
- int64_t iv;
730
- if (val->tag_id == YEPTRIS_TAG_INT && yep_num_i64(sv.p, sv.len, &iv) == 0) {
731
- col->ints[row_i] = iv;
732
- filled = 1;
733
- }
734
- break;
735
- }
736
- case YEP_PLAN_FLOAT: {
737
- double dv;
738
- if (val->tag_id == YEPTRIS_TAG_FLOAT) {
739
- if (yep_num_f64(sv.p, sv.len, &dv) == 0) {
740
- col->floats[row_i] = dv;
741
- filled = 1;
742
- }
743
- } else if (val->tag_id == YEPTRIS_TAG_INT) {
744
- int64_t iv;
745
- if (yep_num_i64(sv.p, sv.len, &iv) == 0) {
746
- col->floats[row_i] = (double)iv;
747
- filled = 1;
748
- }
749
- }
750
- break;
751
- }
752
- case YEP_PLAN_BOOL:
753
- if (val->tag_id == YEPTRIS_TAG_BOOL) {
754
- col->ints[row_i] = yep_num_bool(sv.p, sv.len);
755
- filled = 1;
756
- }
757
- break;
758
- }
759
- if (filled) {
760
- col->nulls[row_i] = 0;
761
- }
762
- }
763
- /* null / missing / tag disagreement / a container at a
764
- * planned leaf: the slot stays null, the walk goes on */
765
- }
766
- cn = v->next_sibling;
767
- }
854
+ dom_fill_row(dd, plan, row, row_i, r);
768
855
  row_i++;
769
856
  }
770
857
  return r;
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yeptris
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.92.0
4
+ version: 0.6.93.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.