Wiki

Ticket #33 (closed defect: invalid)

Opened 16 years ago

Last modified 16 years ago

Cobra doesn't support .NET Attributes

Reported by: Kurper Owned by: Kurper
Priority: medium Milestone:
Component: Cobra Compiler Version: 0.8.0
Keywords: Cc: kurper@…

Description

Apparently, attributes are a feature of .NET similar to interfaces, but different in some way. I'm not completely clear on what makes them different, but the RegexOptions enum ( http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regexoptions.aspx) uses them to allow bitwise operators to be used on objects. Presumably they have more uses, but without them, it's impossible to do this:

regex = Regex(r"long regex", RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace)

for a case-insensitive regex that's easy to read. (As a sidenote, Cobra doesn't convert enums to lowerCamelCase, which may or may not be a bug.)

The corresponding C# code would be:

Regex regex = new Regex(@"long regex", RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);

and that works just fine.

Here are some other relevant MSDN articles:
 http://msdn.microsoft.com/en-us/library/system.flagsattribute.aspx
 http://msdn.microsoft.com/en-us/library/system.attributeusageattribute.aspx

Change History

Changed 16 years ago by Chuck

  • owner set to Kurper
  • status changed from new to assigned

The syntax for combining enums in C# is:

RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace

In Cobra, it is:

RegexOptions(IgnoreCase, IgnorePatternWhitespace)

In other words, it is like creating a value of other types such as DateTime() and Font(), but the arguments are the members of the enumeration. This avoids repeating the enumeration name which gets annoying in C# when you get up to 3 or more enum combinations.

The capital member names for the enum was an intentional choice.

I will probably close this as "not a bug" unless you have further comments/questions.

Changed 16 years ago by Chuck

Perhaps the real bug is that Cobra always allows combining enums when it should be checking that it's legal.

Also, I don't know what error message you got, but Cobra already checks for certain syntaxes from C# and Python and gives good guidance. Enums are probably in need of the same thing.

Changed 16 years ago by Kurper

  • cc kurper@… added

Yeah, that's a good solution for that problem. Unfortunately, I've run across another issue relating to attributes - serialization. In order to use .NET's built-in serializers (BinarySerializer? and so on), a class needs to have the Serializable attribute.

 http://msdn.microsoft.com/en-us/library/system.serializableattribute(VS.80).aspx
 http://msdn.microsoft.com/en-us/library/4abbf6k0(VS.80).aspx

Changed 16 years ago by Chuck

Cobra supports attributes.

See  http://cobra-language.com/docs/release-notes/Cobra-0.7.0.html

Let us know if you have any problems.

Changed 16 years ago by Chuck

  • status changed from assigned to closed
  • resolution set to invalid

I'm closing this as not a bug. I'll open another ticket for "Perhaps the real bug is that Cobra always allows combining enums when it should be checking that it's legal."

Note: See TracTickets for help on using tickets.