Skip to content

Fix module name with reserved keywords (eg. in)#301

Open
davispuh wants to merge 1 commit intojacob-carlborg:masterfrom
davispuh:in
Open

Fix module name with reserved keywords (eg. in)#301
davispuh wants to merge 1 commit intojacob-carlborg:masterfrom
davispuh:in

Conversation

@davispuh
Copy link
Copy Markdown

This PR fixes module name when it's using reserved keyword.
For example consider empty in.h file that is being converted

$ dstep --package a in.h

Without this PR that would produce:

module a.in;

Which doesn't compile:

in.d(1): Error: identifier expected following `package`
module a.in;
         ^
in.d(1): Error: declaration expected, not `in`
module a.in;

With this PR it will be:

module a.in_;

Which does compile.

Copilot AI review requested due to automatic review settings March 19, 2026 16:29
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.Identifier module.
  • Updated fullModuleName to run module names through translateIdentifier.
  • Added unittests covering the in.h module-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_");
@jacob-carlborg
Copy link
Copy Markdown
Owner

I haven't looked carefully but the comments by Copilot seems reasonable.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants