I'm trying to learn more about OCaml extension points, and I'm having trouble representing record types in AST.
I stole an example from this blog post:
http://whitequark.org/blog/2014/04/16/a-guide-to-extension-points-in-ocaml/
Using the source file (foo.ml):
let _ = [%getenv "USER"]
And the output of ocamlc -dparsetree fool.ml:
[ structure_item (test.ml[1,0+0]..[1,0+24]) Pstr_eval expression (test.ml[1,0+8]..[1,0+24]) Pexp_extension "getenv" [ structure_item (test.ml[1,0+17]..[1,0+23]) Pstr_eval expression (test.ml[1,0+17]..[1,0+23]) Pexp_constant Const_string("USER",None) ] ]
From asttypes.mli and parsetree.mli, I can follow the pattern matching of the parsing tree
Pexp_constant Const_string("USER",None)
However, I can no longer keep track of what happens when the parse tree represents record types. It looks like the record fields are not presented in the same order as in the type definition, and not all fields are required (or shown) in the parsing tree.
From parsetree.mli:
type expression = { pexp_desc: expression_desc; pexp_loc: Location.t; pexp_attributes: attributes; }
Only the output of the parsing tree shows the location and payload, but I'm probably reading it wrong.
How to read AST for record types? For a type expression, it should be:
(* record type declaration and pexp_loc field *) expression (test.ml[1,0+8]..[1,0+24]) (* pexp_desc field *) Pexp_extension "getenv" [ ... ]