forked from dagger/dagger
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle comment parsing with windows line endings (dagger#8217)
Our comment parsing code was previously very inflexible, and didn't handle carriage returns in the comment. This is because of this helpful little note in go's comment ast struct declaration: // The Text field contains the comment text without carriage returns (\r) that // may have been present in the source. Because a comment's end position is // computed using len(Text), the position reported by [Comment.End] does not match the // true source end position for comments containing carriage returns. So calling `.End()` on a comment essentially returns absolutely nonsense when there are carriage returns - there is no good way of recovering these. Instead, we switch to another approach of detecting comment doc+line comments - instead of attempting to look for the last element of the line in the comment, we perform an entirely line-based approach, by checking if the comment starts/ends on the correct line. This is relatively fiddly, and is a bit fragile, so added some more tests as well. Also, handling block comments `/* */` becomes a bit trickier, so extended tests to handle those as well. Signed-off-by: Justin Chadwell <[email protected]>
- Loading branch information
Showing
4 changed files
with
224 additions
and
145 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.