Fix module name with reserved keywords (eg. in)#301
Open
davispuh wants to merge 1 commit intojacob-carlborg:masterfrom
Open
Fix module name with reserved keywords (eg. in)#301davispuh wants to merge 1 commit intojacob-carlborg:masterfrom
in)#301davispuh wants to merge 1 commit intojacob-carlborg:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses invalid generated D module declarations when the derived module name matches a D reserved keyword (e.g., in), by centralizing identifier keyword handling and applying it during module name generation.
Changes:
- Extracted D keyword detection/renaming logic into a new
dstep.translator.Identifiermodule. - Updated
fullModuleNameto run module names throughtranslateIdentifier. - Added unittests covering the
in.hmodule-name case (normalized and non-normalized).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
dstep/translator/Translator.d |
Re-exports the new Identifier module and removes the old in-file keyword helper functions. |
dstep/translator/Options.d |
Applies identifier translation when building full module names; adds tests for in.h. |
dstep/translator/Identifier.d |
New module containing isDKeyword, renameDKeyword, and translateIdentifier. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
104
to
113
| if (normalize) | ||
| { | ||
| auto segments = moduleName.split!(x => x == '.'); | ||
| auto normalized = segments.map!(x => x.toUTF8.toSnakeCase).join('.'); | ||
| return only(packageName, normalized).join('.'); | ||
| return only(packageName, translateIdentifier(normalized)).join('.'); | ||
| } | ||
| else | ||
| { | ||
| return only(packageName, moduleName.toUTF8).join('.'); | ||
| return only(packageName, translateIdentifier(moduleName.toUTF8)).join('.'); | ||
| } |
Comment on lines
+135
to
+139
| assert(fullModuleName("pkg", "in.h") == "pkg.in_"); | ||
|
|
||
| assert(fullModuleName("pkg", "FooBarBaz.ext", false) == "pkg.FooBarBaz"); | ||
| assert(fullModuleName("pkg", "FooBar.BazQux.ext", false) == "pkg.FooBar.BazQux"); | ||
| assert(fullModuleName("pkg", "in.h", false) == "pkg.in_"); |
Owner
|
I haven't looked carefully but the comments by Copilot seems reasonable. |
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.
This PR fixes module name when it's using reserved keyword.
For example consider empty
in.hfile that is being convertedWithout this PR that would produce:
Which doesn't compile:
With this PR it will be:
Which does compile.