ocaml-ppx / ppx_tools

Tools for authors of ppx rewriters
MIT License
134 stars 39 forks source link

Add with_loc convenience function. #2

Closed Drup closed 10 years ago

Drup commented 10 years ago

Note: I can't remove the compilation warning, since both Location.loc and Location.error have a loc field, with the same type.

alainfrisch commented 10 years ago

Can you give some examples of how the function would typically be used?

Drup commented 10 years ago

Sure: https://github.com/ocsigen/lwt/blob/ppx/ppx/ppx_lwt.ml#L116 Here you can see that I have a variable which is a pattern and I want to make it an expression (while keeping the location). So I pattern match a bit deeper to get the actual variable and just use str.

It seems to like an idiom worth repeating.

By the way, if you want motivating examples for metaquot, you can look at the difflog. The first implementation was without and the second with it. The diff is striking.

Drup commented 10 years ago

Ping. Can you just close the PR if you don't want the function ?

alainfrisch commented 10 years ago

This seems a little bit too specific, and indeed, I think it's best left to client code to define such a helper function.