I think that for brevity reasons the AST nodes from OCaml parsetree and Cia are a bit confusing and a bit unintelligible at first. I mean, what does Pexp_apply, Pexp_construct + Pexp_tuple, Pexp_poly even mean? And a list [1, 2, 3] will be represented as a bunch Pexp_construct and Pexp_tuple what? So what I missed at first when I started writing my own PPXs or other AST consuming projects was some sort of cheat sheet to help aid this pain. ppx_tools/dumpast kinda helps and https://astexplorer.net/ too but their output doesn't map 1:1 to the actual AST nodes you end up consuming in the code. Also I wished I knew about @opam/ppx_tools_versioned earlier and the sweet ppx_metaquot.
I plan on to keep on updating this post
expressions; everything is an expression
let value; let a = 12
let function; let a = () => 12;
function labels
function body
function call or apply; a(1, 2, 3)
function call with labeled params; a(~b=12, ~c=2);
I think that for brevity reasons the AST nodes from OCaml parsetree and Cia are a bit confusing and a bit unintelligible at first. I mean, what does
Pexp_apply
,Pexp_construct
+Pexp_tuple
,Pexp_poly
even mean? And a list[1, 2, 3]
will be represented as a bunchPexp_construct
andPexp_tuple
what? So what I missed at first when I started writing my own PPXs or other AST consuming projects was some sort of cheat sheet to help aid this pain.ppx_tools/dumpast
kinda helps and https://astexplorer.net/ too but their output doesn't map 1:1 to the actual AST nodes you end up consuming in the code. Also I wished I knew about@opam/ppx_tools_versioned
earlier and the sweetppx_metaquot
.I plan on to keep on updating this post
expressions; everything is an expression
let value; let a = 12
let function; let a = () => 12;
function labels
function body
function call or apply; a(1, 2, 3)
function call with labeled params; a(~b=12, ~c=2);
jsx
switch or pattern matching; switch(a) { | true => false | false => true}
pattern matching branches
records; {a: 1, b: 2, c: 3}
modules
functors
array; let a = [|1, 2, 3|]
list; let a= [1, 2, 3]
in
out
suggested way to consume the items as a list of them:
types
record types; type r = {a: int, b: int, c: int};
module types