Skip to content

Fix CRLF line-ending parsing for comments. #25219

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

Merged
merged 5 commits into from May 15, 2015
Merged

Fix CRLF line-ending parsing for comments. #25219

merged 5 commits into from May 15, 2015

Conversation

ghost
Copy link

@ghost ghost commented May 8, 2015

Fixes #25182, parser didn't account for \r\n in regular comments, only doc-comments.

@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @huonw (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see CONTRIBUTING.md for more information.

let start_bpos = self.last_pos - BytePos(2);
while !self.curr_is('\n') && !self.is_eof() { self.bump(); }
return Some(TokenAndSpan {
Some(TokenAndSpan {
tok: token::Comment,
sp: codemap::mk_sp(start_bpos, self.last_pos)
Copy link
Member

Choose a reason for hiding this comment

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

I think this start_bpos is off by one perhaps? It was originally last-BytesPos(2) but now I think it's last-BytePos(3)

@alexcrichton
Copy link
Member

Thanks! Would it be possible to add a test for this as well?

@ghost
Copy link
Author

ghost commented May 13, 2015

Ok the bytepos should now be consistent with how it was previously, and I've fixed up the error message change that broke some tests. I've also added a test to check that the newlines are stripped but not sure if this is the best way to do it.

@alexcrichton
Copy link
Member

Hm I believe though that in the first case (a doc comment) the byte pos was subtracted by 3, and in this case it's now subtracted by only two? Perhaps some more assertions could be added to the test that was added about the spans being returned as well?

@ghost
Copy link
Author

ghost commented May 14, 2015

Previously the byte pos was pos - 3 for doc comments and last_pos - 2 otherwise to account for characters wider than 1 byte in comments (e.g. starting with //<wide char>). So last_pos - 2 should be correct independent of the byte width of the current character. Correct?

@alexcrichton
Copy link
Member

The branch for doc comments has last_pos - 3 previously, and the branch for regular comments had last_pos - 2, but now both branches use last_pos - 2 which is all I'm worried about

@ghost
Copy link
Author

ghost commented May 14, 2015

It previously used pos - 3, not last_pos - 3. Seeing as the third character for doc comments is always / or !, which both have a byte width of 1, last_pos - 2 should always be equal to pos - 3 unless I'm going mad. I will make it explicit anyway to be sure.

@alexcrichton
Copy link
Member

Oh wow I totally missed the pos vs last_pos distinction, this is subtle! Anyway I think current current version looks good to me, so thanks!

@bors: r+ 2dcc200

@bors
Copy link
Collaborator

bors commented May 15, 2015

⌛ Testing commit 2dcc200 with merge b948d81...

bors added a commit that referenced this pull request May 15, 2015
Fixes #25182, parser didn't account for \r\n in regular comments, only doc-comments.
@bors
Copy link
Collaborator

bors commented May 15, 2015

@bors bors merged commit 2dcc200 into rust-lang:master May 15, 2015
@ghost ghost deleted the fix-comment-parsing branch May 17, 2015 23:13
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

Successfully merging this pull request may close these issues.

Rustdoc source code output dislikes windows line endings
5 participants