For context (skip to question if you like): I am learning ocaml and started reading the Real World Ocaml.
So far, really (really!) liking the language and the book.
One thing I'm starting to not like so much is this mysterious 'ppx' stuff that is starting to show up everywhere I look when I try to 'dig a little deeper'(typically this digging involves opening some source code of a dependency and then and stumbling onto some 'magic' things like [@@deriving sexp]
).
From lots of googling / various scattered sources... this seems to be some kind of syntax extension mechanism based on AST transformations. It seems to be heavily used (at least in janestreet libs). Near I can tell this is an 'unofficial' or undocumented feature of Ocaml. For example, looking at the Ocaml manual I couldn't find any trace of it.
Now, the question. How official/supported is the ppx mechanism for extending ocaml with new syntax by means of AST transforms?
EDIT/note: It was pointed out in the answer by @octachron that there is in fact a 'trace' of the feature in the manual that I missed. The syntax for these [@@..]
bits at least is documented in the manual / ocaml grammar.
But the answer i.m.o really should address two things: syntax and semantics.
- syntax is about "how do we write these magic new things".
- semantics is about how do we attach meaning to them.
A partial answer was already given by @octachron. It is clear now that the 'syntax' is official. But it is still a bit unclear to me how 'official' the support is for attaching semantics to these syntax extensions. So I am holding out for accepting an answer that is a bit more complete/explicit about semantics).
PS: Near as I can tell, there is nothing in the manual about this, and the Ocaml compiler ostensibly does nothing with the annotations at all (except, I suppose, parsing them). So unless I missed something else in the manual, then there isn't an 'official' mechanism in the language that lets you access the data in these annotations and do anything meaningful with them. Is that correct?