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

Be more relaxed about ppx attributes. #15

Closed
jordwalke opened this issue Aug 14, 2018 · 11 comments
Closed

Be more relaxed about ppx attributes. #15

jordwalke opened this issue Aug 14, 2018 · 11 comments
Labels
forwarded-to-js-devs This report has been forwarded to Jane Street's internal review system.

Comments

@jordwalke
Copy link

In Reason, we preserve the original string content in the AST and attach them to parsed strings (which are manipulated to some extent by the parsing process).

When you write:

let%test "literal" = ..

You effectively end up with:

let%test ("literal" [@@reason.literal_value "literal"]) = ...

And the ppx_inline_test ppx reports: "Error: Attributes not allowed here"

If we'd like to use ppx_inline_test with Reason, then we will need ppx_inline_test to be a little more relaxed about allowing attributes on the string literal. Is this possible?

reasonml/reason#2134

@jordwalke
Copy link
Author

jordwalke commented Aug 14, 2018

This is likely also an issue for ppx_expect if it uses the same logic.
Confirmed the same issue happens with ppx_expect.

@ghost
Copy link

ghost commented Aug 14, 2018

Completely removing this check would be a bit dodgy as this would mean that if the user explicitly put an attribute it would be silently ignored.

However, we could whitelist attributes generated by reason in ppxlib. We already do this for merlin for instance.

What would help is to come up with a convention for machine generated attributes that can safely be ignored. For instance using the _ prefix in attribute names.

@ghost
Copy link

ghost commented Aug 14, 2018

/cc @let-def @trefis, what do you think about using a convention for machine generated attributes?

@jordwalke
Copy link
Author

We currently use the attributes @@reason.literal_value and will likely use @@reason.* or @@refmt.* to store formatting attributes in AST nodes. We also make heavy use explicit_arity attributes which we believe may also be causing issues (with :MerlinTypeOf, but not causing problems with compilation). The explicit_arity may add one extra level of depth (Tuple) to patterns.

@ghost
Copy link

ghost commented Aug 15, 2018

Ok, are you happy to prefix the name of these attributes with _? At least we can just add a general rule to ppxlib and we will have a solution ready for the next tool that needs something like this.

@let-def
Copy link

let-def commented Aug 15, 2018

A _ prefix is fine I think.

@jordwalke
Copy link
Author

We won't be able to go retroactively update older versions of Reason already in use that use the @@reason.* prefix or @@refmt.* prefix.

@zindel
Copy link

zindel commented Aug 23, 2018

I'd like to support this request. We cannot use the ppx_expect tests written in Reason in fastpack because of it.

@rgrinberg
Copy link

How about temporarily hard coding reason. and refmt. in ppxlib until reason transitions to the _ prefix?

zindel added a commit to fastpack/fastpack that referenced this issue Aug 23, 2018
FastpackTest remains OCaml because of  this issue: janestreet/ppx_inline_test#15
@ghost
Copy link

ghost commented Aug 23, 2018

We can do both at once, it's the same amount of work to do either. I created this ticket to track this issue

@github-iron github-iron added the forwarded-to-js-devs This report has been forwarded to Jane Street's internal review system. label Sep 30, 2020
@v-gb
Copy link

v-gb commented Jan 29, 2021

Closing this, because it looks like @jeremiedimino solved this by doing both a special case for attributes starting with "reason" or "refmt" and the general thing of ignoring attribute that start with underscores.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
forwarded-to-js-devs This report has been forwarded to Jane Street's internal review system.
Projects
None yet
Development

No branches or pull requests

6 participants