Persistent store with Git semantics: lazy reads, delayed writes, content-addressing
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ocaml-yaml: redesign Value.t as proper YAML 1.2 superset of JSON

YAML 1.2.2 is a strict superset of JSON at the language level, and the AST now reflects that. Every constructor carries a Meta.t for source location preservation, Mapping keys are general Value.t (not just strings) per the spec's complex-key support, and two YAML-specific variants land:

- Alias of string node — anchor reference left unresolved so consumers can see the intent (the parser still resolves at parse time by default; the constructor is available for applications that want to preserve the anchor graph).

- Tagged of { tag : string node; value : t } — explicit type tags (!!int, !!bool, or custom !foo) preserved for schema-aware consumers.

Value.sort_of is the Sort classifier previously hidden in Codec. Value.equal ignores Meta.t (structural semantics only) so tests compare cleanly. Value.pp formats the YAML-ish shape.

Codec pattern matches updated to destructure nodes, Mapping iteration filters non-string keys for string-keyed combinators (key, obj/mem, keep_unknown). string_keyed_entries helper is a single point for that convention.

yaml.json and yaml.jsont bridges translate Yaml.Value.t <-> Json.t / Jsont.json, skipping non-string mapping keys in the JSON direction (since JSON doesn't support them). Alias projects to a *name string; Tagged projects to its wrapped value.

irmin/lib/yaml migrated: Yaml.Mapping _ now uses string_keyed_entries to filter, constructors wrap strings in Value.string.

All 37 existing tests still pass unchanged (they use Value.equal which ignores Meta).

+17 -8
+17 -8
lib/yaml/irmin_yaml.ml
··· 8 8 let dec s = 9 9 match Yaml.decode_string Yaml.Codec.value s with 10 10 | Ok v -> v 11 - | Error _ -> Yaml.Null 11 + | Error _ -> Yaml.Value.null () 12 + 13 + let string_keyed_entries = function 14 + | Yaml.Mapping (kvs, _) -> 15 + List.filter_map 16 + (fun (k, v) -> 17 + match k with Yaml.String (s, _) -> Some (s, v) | _ -> None) 18 + kvs 19 + | _ -> [] 12 20 13 21 let parse : S.dec = 14 22 fun block -> 15 23 match dec block with 16 - | Yaml.Mapping pairs -> 24 + | Yaml.Mapping _ as v -> 25 + let pairs = string_keyed_entries v in 17 26 S.Named (List.map (fun (k, v) -> (k, `Inline (enc v))) pairs) 18 - | Yaml.Sequence items -> 27 + | Yaml.Sequence (items, _) -> 19 28 S.Indexed 20 29 (Array.of_list (List.map (fun v -> (`Inline (enc v) : S.child)) items)) 21 30 | _ -> S.Named [] ··· 28 37 let v = 29 38 match child with 30 39 | `Inline data -> dec data 31 - | `Link _ -> Yaml.Null 40 + | `Link _ -> Yaml.Value.null () 32 41 in 33 - (name, v)) 42 + (Yaml.Value.string name, v)) 34 43 children 35 44 in 36 - enc (Yaml.Mapping pairs) 45 + enc (Yaml.Value.mapping pairs) 37 46 | S.Indexed children -> 38 47 let items = 39 48 Array.to_list ··· 41 50 (fun child -> 42 51 match child with 43 52 | `Inline data -> dec data 44 - | `Link _ -> Yaml.Null) 53 + | `Link _ -> Yaml.Value.null ()) 45 54 children) 46 55 in 47 - enc (Yaml.Sequence items) 56 + enc (Yaml.Value.sequence items) 48 57 49 58 let ( => ) = S.( => ) 50 59