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

Hooks to customize interpolation #100

Open
TikhonJelvis opened this issue Jun 11, 2022 · 0 comments
Open

Hooks to customize interpolation #100

TikhonJelvis opened this issue Jun 11, 2022 · 0 comments

Comments

@TikhonJelvis
Copy link

It would be great to have a postProcess-style hook that applied to each interpolated expression. This would make it much easier to customize the exact behavior of the quasiquoter while reusing the interpolation and Haskell-expression-parsing machinery from this package.

I haven't really thought the design through yet, but it would be neat if the Python formatting DSL could be factored out as a function—that would leave people with a lot of flexibility around how to handle interpolation.

I've run into two situations where this level of flexibility would have been useful:

  1. Integrating with some class to display user-facing values (ie Display or something internal)

  2. Interpolating for code generation where it would be nice to restrict expressions to a domain-specific newtype or even automatically manage language-specific things like quoting and name resolution

Unfortunately, none of the Haskell interpolation libraries I've looked at are flexible enough for this kind of use.

Is this kind of usecase something you'd be interested in supporting in PyF? If it is, I'm happy to try my hand at writing a PR, although I'd appreciate suggestions on how to fit it into the existing design of the library. Alternatively, I could see this fitting more into a library for writing quasiquoters rather than PyF, but I'm not sure if any library like that currently exists.

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

1 participant