Refer.AlistA Refer record can be generated from an association list (alist), and a refer database can be generated from a list of alists.
Certain strings cannot be valid keys (field names): e.g. any string containing whitespace.
Certain strings cannot be valid field values: e.g. any string that contains a "blank" line, including trailing newlines.
(assemble ?(fix=false) alist) generates a valid string-representation of a refer record.
Raises Failure if any of the keys or values in the alist are invalid (see valid), unless (fix = true), in which case the invalid values will be "fixed" by converting one or more troublesome newlines into spaces. N.B. Only alist values can be fixed; invalid keys will always raise Failure (because keys are semantically meaningful in a stronger way than values). You can use valid ahead of time to be sure no exceptions will be raised, or check to repair keys and values in a custom manner.
Example: if alists is a (Refer.t list), then this will print a valid refer file to stdout:
List.iter (assemble >> print) alistsExample: (assemble [("A", "1"); ("B", "2"); ("B", "3"); ("C", "4")] |> print) prints:
%A 1 %B 2 %B 3 %C 4
val check :
(string * string) list ->
[> `K of string * string
| `KV of string * string
| `Ok of string * string
| `V of string * string ]
list(check alist) returns a syntax-checked version of the given alist, which indicates whether or not it can be converted to a valid string representation of a refer record.
(check alist) returns an element for each binding (k,v) in the alist in the original order. There are four possible forms, each carrying a binding:
(`Ok (k,v)): both the key and value are valid(`K (k,v)): the key is invalid(`V (k,v)): the value is invalid(`KV (k,v)): both the key and value are invalidInvariant: (check alist |> map (function `Ok b | `K b | `V b | `KV b -> b)) = alist)