[info request]
with 1st class patterns, is it possible to submit one to the ppxlib engine outside the context of extension points? ie. I would like to do this: <...> Ast_pattern0.t -> handler-function: (... -> 'a) -> Parsetree.t -> unit
and have the handler function called as many times as the pattern appears in the parsetree. or something similar?
thanks...
I don't think it is directly supported right now.
You can register such a transformation as a whole file transformation (the impl and intf arguments of Driver.register_transformation). Ppxlib should make it not too hard to make it with helpers such as Ast_pattern.parse and the Ast_traverse module.
However, I think you should think twice before doing so:
- You would lose the fact that they can see easily what is rewritten and what is not
- you would lose the clear composability semantics
- you would lose some performace with an additional ast traversal passes.
I couldn't get it to work and reverted to parsetree matching. although I've trial and errored my way through the 1st class patterns before I could not get my head around ^:: and nil this time round. is there a note or tutorial that includes the usage of these specifically you can point me to?
I am not sure which part is still a problem: The creation of ast patterns, or the ast traversal?
In any case, unfortunately there is no more documentation on either of them than what is in the API doc. Note that the Ast_pattern module doc has been fixed recently in #365 (merged in #371), but I believe it will appear in the doc only after the next release...