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

Avoid printing comments from AST. #282

Closed
jordwalke opened this issue Apr 6, 2016 · 18 comments
Closed

Avoid printing comments from AST. #282

jordwalke opened this issue Apr 6, 2016 · 18 comments

Comments

@jordwalke
Copy link
Member

Cristiano upgraded his compiler to 4.02.3, so this began storing comments in the AST. We print some of these, so we need to strip these attributes out and not print them (we already print comments so this is redundant).

@jordwalke
Copy link
Member Author

cc @yunxing

@yunxing
Copy link
Contributor

yunxing commented Apr 6, 2016

I can reproduce this issue by:

image

@yunxing
Copy link
Contributor

yunxing commented Apr 6, 2016

The intermediate solution should be filter out all the attributes with "ocaml.text" until we can store comments into attributes. @dxu

@dxu
Copy link
Contributor

dxu commented Apr 6, 2016

cool, I can look into it. if my understanding is correct, I should be stripping out all the current comment code (including the interleaving), and just checking the actual structure item?

@dxu
Copy link
Contributor

dxu commented Apr 6, 2016

on second thought, i'll probably need to reuse some of the logic to handle inline comments. i'll have to look into it more

@dxu
Copy link
Contributor

dxu commented Apr 7, 2016

I tried modifying the matching on floating attributes to play with this, but I'm not sure if it's my lack of understanding or something else, but I can't seem to consistently reproduce this.

After taking out yunxing's preprocessor, I tested an ml file in different cases:
screen shot 2016-04-06 at 10 28 38 pm
screen shot 2016-04-06 at 10 29 01 pm
screen shot 2016-04-06 at 10 29 18 pm

My understanding is that these are the AST's that are fed into the pretty printer - is this correct? Does anyone know why there are these inconsistencies? Is this a problem on ocaml's end?

@jordwalke
Copy link
Member Author

The OCaml .ml parser stores comments in the AST as attributes (Reason doesn't yet). It looks like it's not storing the first comment in the AST. Perhaps that's because it treats the first docblock specially? Also, you don't need the -pp reasonfmt argument because there's nothing Reason about that file or the compilation command.
(Note OCaml only started parsing comments into the AST in version 4.02.3).

@dxu
Copy link
Contributor

dxu commented Apr 8, 2016

Ah, thanks for that, I probably should've noticed that.
Yeah, I'm not sure, I'd need to look more into what exactly is stored in 4.02.3. I also noticed that multiline comments don't seem to be stored.

I feel like there might be some issues if we try to convert over the reason parser to storing all comments in our AST, since there'd be inconsistencies between upgrading ocaml -> reason and just compiling reason, if the ocaml compiler doesn't store all comments in the AST.

@yunxing
Copy link
Contributor

yunxing commented Apr 8, 2016

image

It also looks to me that only part of the comments are stored in the AST. It looks like my previous understanding of how ocaml stores comments in AST is not solid.

I would be interested to see why do they want to store comments in the AST at the first place and what's the current status.

@jordwalke
Copy link
Member Author

Perhaps it only stores comments that it can associate with a particular AST node? If so, it's not really intuitive or clear what's currently happening. It's a good thing we have the current fallback.

@jordwalke
Copy link
Member Author

@cristianoc I pushed a fix last night to ReasonSyntax which should fix the remaining issues with this. I haven't tested thoroughly, and I plan to spend the rest of the weekend finding edge cases in development. But if you were to rebase and re-run the converter, the comments should all be fixed.

@cristianoc
Copy link
Contributor

@jordwalke looks like this fixes .re files but not .rei files for me.

@jordwalke
Copy link
Member Author

I'll get a fix. I just missed one AST node type.

@jberdine
Copy link
Contributor

4.03 is supposed to parse all ** comments into attributes. I think that 4.02.2 and 4.02.3 are in some intermediate situation. It the association rules trigger, then they are ocaml.doc attributes, otherwise they are ocaml.text attributes. The point of these attributes is for enabling documentation generation/browsing/etc tools to work from the cmt files. It seems to me that this also the right path for reason.

There is a warning (50) that identifies ** comments that could not be unambiguously associated with ast nodes. So it seems that the right plan for ocaml to reason conversions is to first enable warning 50, fix all of the warnings in the ocaml source, and then proceed with the conversion. This could be done with just a one off use of 4.03 before a full upgrade of a project. That ought to keep the conversion from being lossy wrt documentation comments. How to print them could vary or wait once the association in the ast is right. Thoughts?

@jordwalke
Copy link
Member Author

jordwalke commented Apr 28, 2016

We will definitely want to parse comments into the AST just as 4.03 does so that we get codoc support. We currently do a pretty good job of printing comments without storing them in the AST, however. We want to maintain full support for printing comments that couldn't be parsed into the AST (if someone choses not to enable warning 50), so we might need to always support that anyways. We can still also parse them into the AST solely for the purpose of doc generation.

@jberdine
Copy link
Contributor

jberdine commented Apr 28, 2016 via email

@jordwalke
Copy link
Member Author

Sorry, I did not answer the question you asked. I answered it in depth here, but in short, the AST attributes will mostly be good for documentation generation, and warning 50 will be great for ensuring that your project is Reason clean, although we need to do more work to make that true.
Warning 50 will not make your project Reason clean due to the comments being stored in AST attributes, but rather due to just always being able to attribute comments to the right AST node.

@jaredly
Copy link
Contributor

jaredly commented Jun 14, 2018

this is pretty stale. feed free to reopen if more discussion is needed

@jaredly jaredly closed this as completed Jun 14, 2018
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

6 participants