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

Import Aliasing #480

Open
Tracked by #19
dselman opened this issue Aug 9, 2022 · 9 comments
Open
Tracked by #19

Import Aliasing #480

dselman opened this issue Aug 9, 2022 · 9 comments

Comments

@dselman
Copy link
Sponsor Contributor

dselman commented Aug 9, 2022

Feature Request 🛍️

Allow imported types to be aliased to prevent name collisions.

Use Case

Allows a namespace X to import types from namespace Y that have the same names as types already present (or imported) into namespace X.

Possible Solution

import { Document as AccordDocument } from org.accordproject.commonmark

Context

In general as models become larger and edited by distributed teams it is impossible to ensure name conflicts do not occur across namespaces.

Detailed Description

Allow name aliasing during imports. Alternatively we could support using fully-qualified names for properties.

@kailash360
Copy link

@dselman @mttrbrts

I went through this issue, and it looks like we can create a separate field in the JSON schema as alias to define the alias name for the property. We will always give priority to the alias over the actual considering that it will prevent the conflicting behavior. In the parser we can add the feature to check for the as <alias> and use that value globally in the file. Let me know if this sounds to be a good approach to start with.

@kailash360
Copy link

Also, considering that it is one of the GSoC ideas, I would love to work on it.

@salujajaskeerat
Copy link
Contributor

salujajaskeerat commented May 28, 2024

To implement the alias import, I am thinking of implementing the syntax suggested by @dselman above.

Syntax : import org.accordproject.address@1.0.0.{ Type as t ,...}

  • Allowing optional aliases for types in import statements.
  • Example
    import org.accordproject.commonmark.{ document as doc1 , cmk }
    import org.accord project.utilities.{ document as doc2 , utl }

In the above types, cmk, utl are not aliased.

@mttrbrts
Copy link
Sponsor Member

mttrbrts commented May 29, 2024

This looks like a strong design to me and should be familiar to TypeScript / JavaScript / Python developers.

A more C#-style approach would use namespace aliasing, although this could become confusing if users tried to use it to alias types too. It's likely that this would also force us to allow fully-qualified references to types throughout CML, rather than using short-names as we do today.

Are there any other alternatives that we should consider?

@salujajaskeerat
Copy link
Contributor

Yes the approach we are looking for is close to the typescript syntax.

A more C#/C++ style approach , i think is more relevant for aliasing namespaces . Do we want to alias namespaces also ?

using alias=namespace

I believe this approach would require more syntax changes compared to the above design.

@ekarademir
Copy link
Contributor

ekarademir commented May 29, 2024

Some test cases to consider

import com.example.foo.{as as as}
import com.example.foo.{As as as}
import com.example.foo.{Document as Doc1, Doc2}
import com.example.bax.{Document as Doc2}

@sanketshevkar
Copy link
Member

sanketshevkar commented May 29, 2024

Another option, would be : instead of as similar to what JS does with aliasing deconstructed object properties.
import com.example.foo.{Document: Doc1, Doc2}

@salujajaskeerat
Copy link
Contributor

salujajaskeerat commented Jun 5, 2024

Since we don't have the keyword 'as' already defined in the concerto, using 'as' for aliasing types would cause breaking changes and require extra handling at the parser level of the code.

I think @sanketshevkar's recommendation to use ':' would solve the above issue, as ':' is already a reserved keyword in concerto and hence won't be matched with an identifier. Other options could be '='.

updated Syntax : import ns.{ Type : t ,...} where ns:QualifiedNameSpaceDeclaration.

@salujajaskeerat
Copy link
Contributor

In the Technology-wg, as discussed with @mttrbrts, aliasing with the keyword as is more readable compared to : or =, so the decision is to make as a local reserved key-word in the import statement and not a global reserved key-word. It would still be backwards-compatible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Next 3 Months
Development

No branches or pull requests

6 participants