Skip to content

fix(zig): count multiline strings and character literals - #789

Merged
boyter merged 2 commits into
boyter:masterfrom
LuisFigueroaG:fix/zig-char-literals
Oct 14, 2026
Merged

boyter merged 2 commits into
boyter:masterfrom
LuisFigueroaG:fix/zig-char-literals

Conversation

@LuisFigueroaG

Copy link
Copy Markdown
Contributor

Two problems in how scc reads Zig strings. Both made comments count as code.

A multiline string line (\\...) ends at the newline, and languages.json says so (end "\n"). But stringState stops 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 regenerates processor/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.sh passes.

I explicitly license this contribution under the MIT licence.

@pr-insights pr-insights Bot added M/complexity Normal or medium complexity M/size Normal or medium sized change labels Oct 13, 2026
@boyter
boyter merged commit 36b4729 into boyter:master Oct 14, 2026
4 checks passed
@boyter

boyter commented Oct 14, 2026

Copy link
Copy Markdown
Owner

TY!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

M/complexity Normal or medium complexity M/size Normal or medium sized change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants