[I’ll leave this up, but after some thinking I realized I could just -very rapidly- write an alternative parser for s-expressions (that supported raw-strings) and solve my problem. It worked, and I’m moving along with writing test-cases (which was the original problem).]
Does anybody know of a file-format that meets this criterion ( (1) raw-strings) ? I know that there’s (of course) YAML, but what I didn’t mention in the title is that it also needs to support (2) recursive data-structures.
(a) JSON supports (2), but not (1)
(b) YAML supports (1) but not (not really) (2). And it’s ugggggly besides.
(c) s-expressions are like JSON.
and I can’t think of anything else.
Unstated is that it’d be nice if there were a PPX deriver to de/serialize the format from/to OCaml types, but really, that’s the easy part. Anybody got any pointers?
Why do I want it?
Imagine you want to put the type harness_t on a text-file, so that you can edit it. The field groupfile is a pair of a filename and its contents. You want those contents to be easily-editable, and you don’t want to be futzing around with escaping all the time. Meanwhile, the field attributes is an “environment” of a sort, mapping variable-names to values. So we need both raw-strings (for groupfile) and hierarchical data (for attributes).
module Value = struct
type t =
STRING of string
| BOOL of bool
| DICT of (string * t) list
| LIST of t list
| NULL
[@@deriving show,yojson]
end
module Environ = struct
type frame_t = (string * Value.t) list
[@@deriving show,yojson]
type t = frame_t list
[@@deriving show,yojson]
end
type harness_t =
{
name : string
; template_s : string
; attributes : Environ.frame_t
; groupfile : (string * string) option
}
[@@deriving show,yojson]
P.S. what’s it for? I’m implementing an OCaml version of StringTemplate4 (a Java thingie), and I want to be able to define a test-case in this format, and -emit- the Java version of the test-case (as well as drive the OCaml version), then compare the results of the two. And of course, I want the source to be in OCaml, with Java code only transiently existing during test-runs.
P.P.S. obvs. I can implement such a format. Indeed, I have two available as part of pa_ppx: JSON and sexp, both with locations, and both with PPX derivers to/from OCaml data-types. The parsers today don’t support OCaml raw-strings, but that’s a minor change. So failing anything else, I’ll do that. But I figured I’d ask, b/c maybe I was unaware of some file-format that meets the spec.