Skip to content

Improve: parse code in comments#934

Merged
gpetiot merged 14 commits intoocaml-ppx:masterfrom
gpetiot:parse-code-comments
Jul 31, 2019
Merged

Improve: parse code in comments#934
gpetiot merged 14 commits intoocaml-ppx:masterfrom
gpetiot:parse-code-comments

Conversation

@gpetiot
Copy link
Copy Markdown
Collaborator

@gpetiot gpetiot commented Jul 24, 2019

Fix #924
@diml I assumed every cinaps comment was an ocaml expression but it seems it's not always the case, I didn't see the specification on the github repo, is there more info somewhere?
Should it be allowed in .mli and .mlt files as well?

@ghost
Copy link
Copy Markdown

ghost commented Jul 24, 2019

Thanks for working on this! cinaps comments are actually structure items, and yh they should be allowed everywhere.

@gpetiot
Copy link
Copy Markdown
Collaborator Author

gpetiot commented Jul 25, 2019

Turns out it is toplevel phrases instead, this PR should be ready to be reviewed and tested now.

@gpetiot gpetiot requested a review from Julow July 25, 2019 07:18
@gpetiot gpetiot changed the title [WIP] Parse code in comments Parse code in comments Jul 25, 2019
@ghost
Copy link
Copy Markdown

ghost commented Jul 25, 2019

Ah yes. Although toplevel phrases were for the old way of using cinaps, i.e. when using it as a toplevel. When used via dune, these have to be structure items. Though I guess parsing them as toplevel phrases should be harmless.

I will test that today.

Just one thought: I grepped the dune-universe for (*$ and realised that it is used for qtest as well. Is that a concern?

@gpetiot
Copy link
Copy Markdown
Collaborator Author

gpetiot commented Jul 25, 2019

Just one thought: I grepped the dune-universe for (*$ and realised that it is used for qtest as well. Is that a concern?

I think testing whether there is a blank character after (*$ should be enough.
Edit: afterall the character there is after the opening bracket should make the parsing fail and the comment would not be formatted like OCaml code.

@ghost
Copy link
Copy Markdown

ghost commented Jul 25, 2019

I'm testing this, it seems to be working well except that a ;; is systematically inserted when the code span over multiple lines:

(*$
  ;;
  let x = 1 in
  x + 1
*)

@ghost
Copy link
Copy Markdown

ghost commented Jul 25, 2019

BTW, it's fine to restrict the parsing to structure items only. I expect that toplevel phrases support will eventually disappear given that the new method of using cinaps via dune is much more convenient.

@gpetiot
Copy link
Copy Markdown
Collaborator Author

gpetiot commented Jul 26, 2019

I reverted to using structures instead, so toplevel directives such as #use "import.cinaps";; won't be parsed anymore.

@gpetiot gpetiot requested a review from hhugo July 26, 2019 10:26
@gpetiot gpetiot changed the title Parse code in comments Improve: parse code in comments Jul 29, 2019
@ghost
Copy link
Copy Markdown

ghost commented Jul 30, 2019

Thanks, I just gave it another try and the comments are being well formatted :)

Just one last issue I found: the trailing $ in $*) is systematically removed.

@gpetiot
Copy link
Copy Markdown
Collaborator Author

gpetiot commented Jul 30, 2019

Just one last issue I found: the trailing $ in $*) is systematically removed.

This is fixed now.

@ghost
Copy link
Copy Markdown

ghost commented Jul 30, 2019

Just tested again, all good👌. Cinaps comments are all nicely formatted :)

@gpetiot
Copy link
Copy Markdown
Collaborator Author

gpetiot commented Jul 31, 2019

@Julow I guess I can submit another PR where I move parseto Parse_with_comments.ml, that should make this PR easier to read.

@Julow
Copy link
Copy Markdown
Collaborator

Julow commented Jul 31, 2019

@Julow I guess I can submit another PR where I move parseto Parse_with_comments.ml, that should make this PR easier to read.

This should not be necessary.

Copy link
Copy Markdown
Collaborator

@Julow Julow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good !

@gpetiot gpetiot merged commit aaaddf4 into ocaml-ppx:master Jul 31, 2019
@gpetiot gpetiot deleted the parse-code-comments branch July 31, 2019 10:30
bogdan2412 pushed a commit to bogdan2412/ocamlformat that referenced this pull request Mar 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Formatting cinaps comments

4 participants