Repository navigation
fix(zig): count multiline strings and character literals - #789
Merged
Merged
Conversation
Owner
|
TY! |
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.
Two problems in how scc reads Zig strings. Both made comments count as code.
A multiline string line (
\\...) ends at the newline, andlanguages.jsonsays so (end"\n"). ButstringStatestops at every newline before it looks for a closer, so the closer was never matched and the string ran to the end of the file. The first commit ends a newline-terminated string when its line ends.Zig uses
'only for character literals, and it wasn't declared as a quote. So in'"'the double quote opened a string that swallowed every line up to the next". The second commit adds'as a quote and regeneratesprocessor/constants.go.On 218 files from Zig's standard library, code goes from 187,635 to 182,618 lines. The result (182,618 code, 24,399 comments, 21,732 blanks) matches a plain line-by-line classification exactly. That comparison is reliable for Zig, which has no block comments and no strings that span lines.
Tests are in
processor/workers_zig_test.go: a multiline string followed by comments, a'"'literal followed by comments, and a test that'\'','\\'and an apostrophe inside a\\line still count correctly../test-all.shpasses.I explicitly license this contribution under the MIT licence.