Ppx_deriving _readers_?

ppx_deriving.show is one of my basic tools. One thing I do pretty often early in development is rig up tests for complicated code that use show to spit out printed versions of complex data structures, both so I can look at them by eye and so I can diff them against those created by earlier versions of code.

I’d like to have an inverse to it, a reader where show is a writer, so I can read back in what ppx_deriving.show writes out.

I presume no such thing exists, though? (It would require, de facto, use of a specialized version of the OCaml parser.)

(I could make do with the Jane Street s-expression stuff but I really like working with a printed representation that’s more like OCaml.)

1 Like

As you already point out yourself, s-expressions are the way to go. What don’t you like about them? I’m sure you can get used to the syntax.

I don’t like them because they’re not as readable as the internal OCaml syntax that I’m used to and don’t match it. I’m sure one can get used to almost anything of course. :slight_smile:

If I’m not mistaken, it should be possible to use the OCaml compiler libraries (specifically the Parse module) to parse a constant expression. Is there anything in the compiler library that can then be used to turn a constant expression into a value of a particular type?