I am trying to learn more about OCaml Extension Points and I am having trouble following the representation of record types in the AST.
I am stealing the example below 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 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 parse tree pattern matching of the line
Pexp_constant Const_string("USER",None)
However, I can no longer follow what is happening when the parse tree represents record types. It seems that record fields are not represented in the same order that they appear in the type definition and not all fields are required (or shown) in the parse tree.
From parsetree.mli:
type expression = {
pexp_desc: expression_desc;
pexp_loc: Location.t;
pexp_attributes: attributes;
}
The parse tree output only seems to show the location and payload, but I am probably reading this incorrectly.
How do I correctly read the AST for record types? For type expression should it be:
(* record type declaration and pexp_loc field *)
expression (test.ml[1,0+8]..[1,0+24])
(* pexp_desc field *)
Pexp_extension "getenv"
[
...
]