antlr / antlr4

ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.
http://antlr.org
BSD 3-Clause "New" or "Revised" License
17.3k stars 3.3k forks source link

C# target should be CLSCompliant (ANTLR 4.7.2) #2614

Open OrbintSoft opened 5 years ago

OrbintSoft commented 5 years ago

As in Documentation, it says:

The C# runtime is CLS compliant, and only requires a corresponding 3.5 .Net framework.

but with ANTLR 4.7.2, the generated code contains [System.CLSCompliant(false)] and the generated code is not absolutely CLS compliant.

There is a way to generate CLS compliant code?

I attach a generated code sample: UserAgentLexer.zip

sharwell commented 5 years ago

CLS compliance is a legacy concept which I've never seen provide meaningful value for a large software system. It was intended to improve the ability for different languages to interoperate, but the largest active multi-language .NET software system I'm aware of (the compilers for F#, C#, and Visual Basic, each written in its own language and which all run together inside Visual Studio) are not CLS compliant and still don't have a problem in this space.

It might be possible to make the runtime and generated code CLS compliant, but I can't see how it would be a good use of time. If you know of a system that needs to be CLS compliant for reasons that have improved the value of the software, I'd be interested to learn more about them.

OrbintSoft commented 5 years ago

I have .NET library deployed on .nuget and I want make it compatible with Visual Basic and F#. I just migrated from https://github.com/tunnelvisionlabs/antlr4cs to official Java generated because documentation said to be CLSCompliant, bu that was not true.

What you are saying is true for end applications, there is no purpose to make an application CLS Compliant, it's not a common nor a good practice to mix different languages in same application.

But it's different for libraries, if you develop a .NET library, you should think to interoperability, because your library can be consumed in different languages.

sharwell commented 5 years ago

I'm saying even if you use multiple languages, like we do on Roslyn, you do not need to make the code CLS compliant. The languages will still work together just fine.

OrbintSoft commented 5 years ago

If I have a non CLS compliant C# class with 2 public properties, for example:

public class Foo { public int fooP {get; set;} public int FooP {get; set;} }

when I try to consume it in Visual Basic (that is not case sensitive) I'll have some troubles, yes it will work but I need reflection to access to that property. That's why it's important to make libraries CLS compliant and to follow naming conventions.

OrbintSoft commented 4 years ago

If you don't plan to make CLS compliant (bad in my opinion because it's a regression) at least update the documentation. It's misleading to say that its CSL complian when in fact it's not.

ericvergnaud commented 4 years ago

Would you be willing to help?

Le 25 mars 2020 à 04:52, Stefano Balzarotti notifications@github.com a écrit :

If you don't plan to make CLS compliant (bad in my opinion because it's a regression) at least update the documentation. It's misleading to say that its CSL complian when in fact it's not.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/antlr/antlr4/issues/2614#issuecomment-603498343, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZNQJD53ZRCQVDWPXFAIBLRJEMQJANCNFSM4IIHFQ2Q.