-
Notifications
You must be signed in to change notification settings - Fork 592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Support for Nested Module Syntax #2012
Add Support for Nested Module Syntax #2012
Conversation
No, this is wrong. We discussed this at length for IceRPC. See icerpc/icerpc-csharp#3187. |
I don't know what you're talking about. If some Slice files are poorly formatted, we should fix them. |
Yes, I just don't want to do it in this particular PR. |
@@ -385,6 +385,75 @@ module_def | |||
$$ = nullptr; | |||
} | |||
} | |||
| ICE_MODULE ICE_SCOPED_IDENTIFIER | |||
{ | |||
auto ident = dynamic_pointer_cast<StringTok>($2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can ICE_SCOPED_IDENTIFIER start with ::
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it can, but if you type: ::Hello::There
, we'll pick up 3 modules: ["", "Hello", "There"]
.
And ""
is not a valid module identifier, so it fails.
cpp/src/Slice/Grammar.y
Outdated
// Where `N` is the number of scope separators ("::"). | ||
size_t scopePos = 0; | ||
auto ident = dynamic_pointer_cast<StringTok>($2); | ||
while ((scopePos = ident->v.find("::", scopePos + 2)) != string::npos) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the +2, does ident always start with ::
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intent was to skip over "::"
in between module identifiers...
But you're right, this won't work for something like A::B
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
After talking it over during lunch, I switch the metadata, so it now applies to the outermost module. All module metadata falls into 2 categories:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
cpp/src/Slice/SliceUtil.cpp
Outdated
// Check that the identifier isn't empty. | ||
if (name.empty()) | ||
{ | ||
currentUnit->error("missing identifier: illegal empty identifier"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currentUnit->error("missing identifier: illegal empty identifier"); | |
currentUnit->error("missing identifier: invalid empty identifier"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This message was removed entirely.
It should now be impossible for this function to ever have an empty identifier.
NestedModule.ice:9: illegal identifier `Holder': `Holder' suffix is reserved | ||
NestedModule.ice:11: illegal identifier `Holder': `Holder' suffix is reserved | ||
NestedModule.ice:15: illegal leading underscore in identifier `__Iceberg' | ||
NestedModule.ice:18: illegal identifier `Holder': `Holder' suffix is reserved | ||
NestedModule.ice:20: illegal identifier `Holder': `Holder' suffix is reserved | ||
NestedModule.ice:24: illegal identifier `APtr': `Ptr' suffix is reserved | ||
NestedModule.ice:24: illegal identifier `BPrx': `Prx' suffix is reserved | ||
NestedModule.ice:24: illegal identifier `CHelper': `Helper' suffix is reserved | ||
NestedModule.ice:27: missing identifier: illegal empty identifier | ||
NestedModule.ice:27: illegal identifier `Helper': `Helper' suffix is reserved |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will have to be updated accordingly if you implement my above suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't find "illegal empty identifier" as a good way to say "a module name must start with a letter".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The message became illegal identifier: module identifiers cannot start with '::' prefix
cpp/src/Slice/SliceUtil.cpp
Outdated
@@ -483,7 +483,15 @@ Slice::checkIdentifier(const string& id) | |||
name = id; | |||
} | |||
|
|||
// Check that the identifier isn't empty. | |||
if (name.empty()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to reach this code?
If yes, please add a test.
If not, an assert would be more appropriate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After some research, it should be impossible to hit.
So, I switched it to an assert.
I hit this by accident when I was using it to check modules, and saw that passing in ""
gets a warning of "illegal trailing underscore"...... which is obviously not true (It's a fluke of how we check for trailing underscores).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Co-authored-by: Joe George <[email protected]>
This PR adds support for 'nested module syntax' to Ice-Slice.
So now instead of:
module A { module B { ... } }
you can write:module A::B { ... }
.Note that these syntaxes are literally equivalent. Both introduce two modules, in the same order.
This is purely a syntactical shorthand.
Metadata applied to this thing is now applied to the outer-most module:
Does this seem correct to everyone?
It also updates our Slice files to use this new syntax where it was possible,
and where "having separate modules" didn't feel like it was important to the test.
For the reviewers:
Where are there other Slice files I should look through?
Yes, our Slice style is inconsistent and sometimes bad looking.
I tried not to touch it, lest this PR would take a day instead of an hour.