Repository navigation
fix: count Nim block comments - #786
Merged
Merged
Conversation
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.
Contributor
There was a problem hiding this comment.
🟢 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.Matchfallback 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.
Owner
|
Thank you! |
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.
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,Matchfalls 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# notein Nim stepped into#[, and the same thing already happened with Lua's--[ noteand 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) andworkers_linecomment_prefix_test.go(Lua/CMake prefixes), plusTrie.Matchcases instructs_test.go.go test ./...passes.I explicitly license this contribution under the MIT licence.