Skip to content
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

Allow struct to contain member with same name #133

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -*- jsonc -*-
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
Copy link
Contributor

Choose a reason for hiding this comment

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

accidentally committed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it's from a vscode update that hasn't gone through yet for this repo. studio has this as well.

},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.detectIndentation": false,
Expand Down
8 changes: 4 additions & 4 deletions packages/omgidl-parser/src/IDLNodes/IDLNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,18 @@ function resolveScopedOrLocalNodeReference({
// If using local un-scoped identifier, it will not be found in the definitions map
// In this case we try by building up the namespace prefix until we find a match
let referencedNode = undefined;
const namespacePrefixes = [...scopeOfUsage];
const currPrefix: string[] = [];
// start with most specific scope and work upwards
const currPrefix: string[] = [...scopeOfUsage];
for (;;) {
const identifierToTry = toScopedIdentifier([...currPrefix, usedIdentifier]);
referencedNode = definitionMap.get(identifierToTry);
if (referencedNode != undefined) {
break;
}
if (namespacePrefixes.length === 0) {
if (currPrefix.length === 0) {
break;
}
currPrefix.push(namespacePrefixes.shift()!);
currPrefix.pop();
}

return referencedNode;
Expand Down
24 changes: 23 additions & 1 deletion packages/omgidl-parser/src/parseIDL.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseIDL as parse } from "./parseIDL";
import { parseIDL as parse, parseIDL } from "./parseIDL";

describe("omgidl parser tests", () => {
it("parses a struct", () => {
Expand Down Expand Up @@ -2597,6 +2597,28 @@ module rosidl_parser {
},
]);
});
it("can parse struct with member of the same name", () => {
const msgDef = `
struct ColorSettings {
uint8 ColorSettings;
};
`;

const ast = parseIDL(msgDef);
expect(ast).toEqual([
{
name: "ColorSettings",
aggregatedKind: "struct",
definitions: [
{
name: "ColorSettings",
isComplex: false,
type: "uint8",
},
],
},
]);
});
// **************** Not supported in our implementation yet
it("cannot compose variable size arrays (no serialization support)", () => {
const msgDef = `
Expand Down
22 changes: 22 additions & 0 deletions packages/omgidl-parser/src/parseIDLToAST.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1775,7 +1775,29 @@ module idl_parser {
},
]);
});
it("can parse struct with member of the same name", () => {
const msgDef = `
struct ColorSettings {
uint8 ColorSettings;
};
`;

const ast = parseIDLToAST(msgDef);
expect(ast).toEqual([
{
name: "ColorSettings",
declarator: "struct",
definitions: [
{
name: "ColorSettings",
isComplex: false,
declarator: "struct-member",
type: "uint8",
},
],
},
]);
});
/**************** Not supported by IDL (as far as I can tell) */
it("cannot parse constants that reference other constants", () => {
const msgDef = `
Expand Down