Let Location::str() handle \r correctly - #127
Merged
Matthew A Johnson (matajoh) merged 12 commits intoAug 22, 2024
Merged
Conversation
Matthew A Johnson (matajoh)
suggested changes
Jul 20, 2024
\r\n and co correctly\r correctly
Contributor
Author
|
Based on meeting feedback, this new version hardens Because I was exhaustively testing and found a lot of edge cases, I rewrote most of Location::str() in order more fundamentally satisfy the testing requirements. Let me know if there are any questions/clarifications/requests. |
Matthew A Johnson (matajoh)
approved these changes
Aug 22, 2024
|
|
||
| std::string escape_string(const std::string str) | ||
| { | ||
| std::string result; |
Contributor
There was a problem hiding this comment.
Nit: this should be a string stream.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is split off from #126, because really it's an orthogonal fix.
The observed problem was that, on Windows, error messages had a strange
\rin reported source locations that was inconsistent with both other platforms, and other parts of the same output string (you would see\nonce then\r\nfurther along the same string).The trouble was traced back to
source.h, which was separating lines based on only the\ncharacter, and assuming that line breaks were only 1 char wide. This PR rewrites the 3 line/columns handling functions that did this, so that they will accept\r\n,\n, and\ras line delimiters while reporting correct line lengths (and so forth) on all platforms.The main change of substance is that the
linesfield ofSourceDefchanges from a vector ofsize_tto a vector ofpair<size_t, size_t>, because it is no longer possible to derive where a line ends from where another line begins (we might have to add/subtract either 1 or 2 chars). Rather than try to detect some file-wide line break width (and possibly have problems due to corrupted files mixing line ending types), this rewrite just looks at which line ending variant each line had and records span information to match.Additionally, this PR adds exhaustive generative testing of this changed feature.
The test code is commented to explain logically how it builds all possible permutations of line endings and line contents up to a certain length (albeit using just
aas contents since this code is not sensitive to string contents).As configured in the
CMakeLists.txt, it runs 729 test cases up to length 6 (6 chars, 6 line endings, and everything in between).This fine-grained testing should help keep this code robust if it ever needs to change again - in fact it already helped catch errors when implementing some review recommendations from the other PR this was split from.