Skip to content

fix: count Nim block comments - #786

Merged
boyter merged 2 commits into
boyter:masterfrom
LuisFigueroaG:fix/nim-block-comments
Oct 12, 2026
Merged

boyter merged 2 commits into
boyter:masterfrom
LuisFigueroaG:fix/nim-block-comments

Conversation

@LuisFigueroaG

Copy link
Copy Markdown
Contributor

Nim has multiline comments, #[ ]#, and multiline documentation comments, ##[ ]##, and both nest. Neither was declared, so only the opening and closing lines counted as comments and everything between them counted as code. On the Nim repository this moves about 2,700 lines from code and blank to comments.

Declaring them exposed a matching bug in Trie.Match, fixed in the first commit. When a longer token doesn't complete, Match falls back to a shorter token, but only to tokens with a closing delimiter. A line comment that starts a longer token was therefore missed: a plain # note in Nim stepped into #[, and the same thing already happened with Lua's --[ note and CMake's #[ note, which were counted as code. It now falls back to the line comment too.

Tests: workers_nim_test.go (nested block and doc comments, # line comments) and workers_linecomment_prefix_test.go (Lua/CMake prefixes), plus Trie.Match cases in structs_test.go. go test ./... passes.

I explicitly license this contribution under the MIT licence.

Trie.Match falls back to a shorter token when a longer one does not
complete, but only to tokens with a closing delimiter. A line comment
that is the start of a longer token was therefore missed, so Lua's
`--[ note` and CMake's `#[ note` were counted as code because the walk
had stepped into --[[ and #[[ before failing.

Fall back to the line comment as well, reporting its length the same
way a direct match does.
Nim has multiline comments, #[ ]#, and multiline documentation
comments, ##[ ]##, and both nest. Neither was declared, so only the
opening and closing lines counted as comments and everything between
them counted as code.

On the Nim repository this moves about 2,700 lines from code and
blank to comments.
@pr-insights pr-insights Bot added M/complexity Normal or medium complexity M/size Normal or medium sized change labels Oct 9, 2026
@boyter
boyter requested a balanced review from Copilot October 12, 2026 23:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused implementation correctly handles prefix fallback and includes adequate regression coverage.

0 open findings

What changed in this PR

Adds correct counting for nested Nim block and documentation comments while fixing trie fallback for line-comment prefixes.

Changes:

  • Defines Nim multiline comment delimiters and nesting.
  • Fixes Trie.Match fallback to line comments.
  • Adds regression and integration tests.
File Description
languages.json Defines Nim nested block comments.
processor/​constants.go Updates generated Nim language constants.
processor/​structs.go Adds line-comment token fallback.
processor/​structs_test.go Tests trie fallback behavior.
processor/​workers_nim_test.go Tests Nim comment counting.
processor/​workers_linecomment_prefix_test.go Tests Lua and CMake regressions.
Files not reviewed (1)
  • processor/constants.go: Generated file

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@boyter
boyter merged commit b0a1f62 into boyter:master Oct 12, 2026
4 checks passed
@boyter

boyter commented Oct 12, 2026

Copy link
Copy Markdown
Owner

Thank you!

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.

3 participants