Hi,
While working on a ppx I found myself trying to create with Ast_pattern and a Context_free transformation what could be achieved with a file transformation instead, but still wanted to keep using Ast_pattern.
The ppx itself appends an argument to a pexp_apply:
let%label foo = apply([...])
(* picks the pattern "foo" and *)
let foo = apply [metadata "foo"; ...]
In the case of being a pexp_apply directly, that’s rather simple, but I got into the point where pexp_fun or pexp_sequence would need to add it anyway.
I endup with a pattern that looks like this, but I was wondering if there’s a way to tell Ast_pattern to match pexp_apply at any node on the parsetree?
let apply_pattern = Ast_pattern.(pexp_apply(__, pair(nolabel, __) ^:: nil));
let fun_pattern = Ast_pattern.(pexp_fun(drop, drop, drop, apply_pattern));
let seq_pattern = Ast_pattern.(pexp_sequence(drop, apply_pattern));
let vb_payload =
Ast_pattern.(
pstr(
pstr_value(
nonrecursive,
value_binding(
~pat=ppat_var(__),
~expr=
map(
~f=(capture, ident, expr) => capture(`Apply((ident, expr))),
apply_pattern,
)
||| map(
~f=
(capture, ident, expr) =>
capture(`Apply((ident, expr))),
fun_pattern,
)
||| map(
~f=
(capture, ident, expr) =>
capture(`Apply((ident, expr))),
seq_pattern,
),
)
^:: nil,
)
^:: nil,
)
);
anyway, I’m happy with my current implementation, but I would like to stretch the possibility.
PS: pardon the Reason syntax ^^