Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[info request] #375

Open
progman1 opened this issue Sep 16, 2022 · 3 comments
Open

[info request] #375

progman1 opened this issue Sep 16, 2022 · 3 comments

Comments

@progman1
Copy link

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...

@panglesd
Copy link
Collaborator

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.

@progman1
Copy link
Author

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?

@panglesd
Copy link
Collaborator

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants