MPR#7701: avoid dropping docstrings in otherwise empty files#1562
MPR#7701: avoid dropping docstrings in otherwise empty files#1562Octachron wants to merge 3 commits intoocaml:trunkfrom
Conversation
4aba7ab to
31aa3c1
Compare
trefis
left a comment
There was a problem hiding this comment.
Surprisingly simple fix, I like it.
parsing/lexer.mll
Outdated
| | Before(a, f, b), BlankLine -> Before(a, b @ f, [doc]) | ||
| in | ||
| loop NoLine docs' lexbuf | ||
| loop !docs_initial_newline_state docs' lexbuf |
There was a problem hiding this comment.
Wouldn't it make more sense to pass NoLine explicitly here?
With the current implementation that is (I believe) the only possible value for !docs_initial_newline_state at this point.
parsing/lexer.mll
Outdated
| set_pre_extra_docstrings pre_pos (List.rev a) | ||
| in | ||
| let rec loop lines docs lexbuf = | ||
| docs_initial_newline_state := NoLine; |
There was a problem hiding this comment.
Could you lift that write out of the loop?
Changes
Outdated
| to ill-typed columns | ||
| (Thomas Refis, with help from Gabriel Scherer and Luc Maranget) | ||
|
|
||
| - MPR#7701,GPR#1561: do not drop documentation comments in (otherwise) empty |
There was a problem hiding this comment.
I missed that 7701 was a duplicate. Fixed.
|
Can you guys wait to merge this until I've had time to have a proper look? (May be a few weeks). This code is quite subtle and I want to make sure that we are not just fixing a symptom of a deeper bug. |
|
Certainly. |
|
This was indeed a symptom of a deeper bug. #1693 is my attempt to fix that. |
|
Good, do you want me to review #1693 ? |
|
That'd be great |
As stated in MPR#7701, documentation comments in otherwise empty files can be silently dropped by the parser.
More precisely, the first documentation comment is dropped if it is not preceded by two empty lines. This happens due to the lexer trying to attach these documentation comments to the non-existing previous token.
This PR proposes to fix this issue by making the lexer considers that any documentation comment is always preceded by a blank line in the begining of a file.