fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: Use of Attributes

Use of Attributes 2 years 2 months ago #1433

  Meinhard's Avatar Topic Author Meinhard Offline Posts: 40
Hi guys!

I want to apply this attribute to a property :

[Option('i',"input",Required := true, HelpText := "Input file to read.")];

But I get this error:

XS0182 An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type

What am I doing wrong?

TIA
Meinhard

Please Log in or Create an account to join the conversation.

Use of Attributes 2 years 2 months ago #1434

  robert's Avatar robert Offline Posts: 994
Meinhard,

What happens if you use "i" in stead of 'i' ?

Robert
XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

Use of Attributes 2 years 2 months ago #1435

  wriedmann's Avatar wriedmann Offline Posts: 1567
Hi Meinhard,

a complete shot in the dark (before Robert gives the right answer):

I would try
[Option{'i',"input",Required := true, HelpText := "Input file to read."}]

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

Use of Attributes 2 years 2 months ago #1436

  Meinhard's Avatar Topic Author Meinhard Offline Posts: 40
Hi Robert,

same message.

Regards
Meinhard

Please Log in or Create an account to join the conversation.

Use of Attributes 2 years 2 months ago #1437

  Meinhard's Avatar Topic Author Meinhard Offline Posts: 40
Hi Wolfgang,

already tried, but accroding to the grammar this is invalid syntax anyway.

Regards
Meinhard

Please Log in or Create an account to join the conversation.

Use of Attributes 2 years 2 months ago #1438

  robert's Avatar robert Offline Posts: 994
Meinhard,

what type is the OptionAttribute ?
And what happens if you omit one or more values from the definition ?
Can you send me the assembly that defines the optionattribute class ?

Robert
XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

Use of Attributes 2 years 2 months ago #1442

  Meinhard's Avatar Topic Author Meinhard Offline Posts: 40
Hi Robert,

just sent you the complete solution (small) via email.

TIA & Regards
Meinhard

Please Log in or Create an account to join the conversation.

Use of Attributes 2 years 2 months ago #1443

  robert's Avatar robert Offline Posts: 994
For those reading :

We have found the problem with Meinhards code: there is a problem handling literal character values in Attributes and Switch statements.
In this case the OptionAttribute class expects a literal character followed by a literal string, and this is not handled properly by the compiler.

We will fix this asap.

Robert
XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

Use of Attributes 2 years 2 months ago #1444

  wriedmann's Avatar wriedmann Offline Posts: 1567
Hi,

again this fast reaction of the development team confirms my decision to use X# as my primary development tool.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

Use of Attributes 2 years 2 months ago #1445

  Meinhard's Avatar Topic Author Meinhard Offline Posts: 40
Indeed!

Please Log in or Create an account to join the conversation.

Use of Attributes 2 years 2 months ago #1446

  Frank Maraite's Avatar Frank Maraite Offline Posts: 173
Hi Robert et all,

Robert van der Hulst wrote: For those reading :

We have found the problem with Meinhards code: there is a problem handling literal character values in Attributes and Switch statements.
In this case the OptionAttribute class expects a literal character followed by a literal string, and this is not handled properly by the compiler.

We will fix this asap.

Robert


I have a discussion with Chris about a bug with chars. What's about the following for one character strings:

'A' is always System.Char
"A" is always System.String.

All other things may remain as it is.

Frank

Please Log in or Create an account to join the conversation.

Last edit: by Frank Maraite. Reason: Should read posts more careful.

Use of Attributes 2 years 2 months ago #1447

  robert's Avatar robert Offline Posts: 994
Frank,

'A' is always System.Char
"A" is always System.String.

All other things may remain as it is.


That is exactly what I have in my current build, with the exception that 'B', 'C', '0' etc. are also seen as System.Char (sorry could not resist :cheer:).

The complete Antlr lexer rule is (and as you can see it quickly becomes quite complicate):
CHAR_CONST		: '\'' ESCAPED_CHARACTER '\'';

fragment
ESCAPED_CHARACTER       : NOT_ESCAPE_SINGLE		
			| SIMPLE_ESCAPE_SEQUENCE
			| HEX_ESCAPE_SEQUENCE
			| UNICODE_ESCAPE_SEQUENCE
 			;

fragment 
NOT_ESCAPE_SINGLE	: ~( '\'' | '\\' | '\r' | '\n' )  ;

fragment 
SIMPLE_ESCAPE_SEQUENCE	: '\\\''	// Single quote
			| '\\"'		// Double quote
			| '\\\\'	// \\
			| '\\0'		// Null
			| '\\' A	// Alert
			| '\\' B	// backspace
			| '\\' F	// formfeed
			| '\\' N	// newline
			| '\\' R	// linefeed
			| '\\' T	// tab
			| '\\' V	// vertical tab


fragment
HEX_ESCAPE_SEQUENCE: '\\' X  HEX_DIGIT (HEX_DIGIT (HEX_DIGIT (HEX_DIGIT)?)?)?;	// \x+ 1 -4 digits

fragment
UNICODE_ESCAPE_SEQUENCE : '\\' U HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT (HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT)? ;	// \u 4 hex or \u 8 hex

fragment HEX_DIGIT	: [0-9a-fA-F];

fragment A	: 'a' | 'A';
fragment B	: 'b' | 'B';
fragment F	: 'f' | 'F';
fragment N	: 'n' | 'N';
fragment R	: 'r' | 'R';
fragment T	: 't' | 'T';
fragment U	: 'u' | 'U';
fragment V	: 'v' | 'V';
fragment X	: 'x' | 'X';


Robert
XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

Last edit: by robert.

Use of Attributes 2 years 2 months ago #1448

  wriedmann's Avatar wriedmann Offline Posts: 1567
Hi Frank,

in legacy code (VO dialect IMHO) there is no char literal, only literal strings.

IMHO the interpretation of the literals should depend on the dialect:
VO dialect: only string literals, delimited both with ' and "
Vulcan and Core dialect: string literals delimited with ", char delimited with '

Another possibility could be a prefix:
c'A' and c"A" are char literals, all others string literals.

But there is a compatibility issue with legacy Vulcan code: there 'A' is always a char literal.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

Last edit: by wriedmann.

Use of Attributes 2 years 2 months ago #1449

  robert's Avatar robert Offline Posts: 994
Wolfgang,

Maybe this is something that we can make different for different dialects:

VO (and probably later also for Harbour, Fox etc)
'A' = String

Vulcan and Core:
'A' = Char

And we could indeed add:
All dialects:
c'A' = Char
c"A" = Char (so you can use c"'" to indicate a single quote char)

Robert
XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

Use of Attributes 2 years 2 months ago #1450

  Frank Maraite's Avatar Frank Maraite Offline Posts: 173
Hi Wolfgang,

Chris mentioned

(Char)'A'

I prefer this over new prefix.

There seems no easy solution. I got an error with one character strings in VO-Array as a parameter to methods that expect System.Object.

Frank

Chris: sorry, I still did not manage a simple example for the bugreport.

Please Log in or Create an account to join the conversation.

Use of Attributes 2 years 2 months ago #1451

  wriedmann's Avatar wriedmann Offline Posts: 1567
Hi Robert,

yes, this could be a good idea, I think.

The dialects are very important, and I have a LOT of VO code to move over, and I'm pretty sure there are several places where I have a '"' to be used as string.
On the other side, in legacy Vulcan code, 'A' is always a char literal.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

Use of Attributes 2 years 2 months ago #1452

  robert's Avatar robert Offline Posts: 994
Frank

(Char)'A'


This moves the problem to detect the type of the constant from the lexer phase to the parser phase. I do not like that.
Decisions like this should be handled early in the compiler pipeline, in the Lexer when possible.

Robert
XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

Use of Attributes 2 years 2 months ago #1453

  wriedmann's Avatar wriedmann Offline Posts: 1567
Hi Frank,

we have already the "i", "e", "ei" and "ie" prefixes on strings, so "c" seems to be the most logical one (at least to me).
(char) "A" would be only a explicit cast.

Of course, the decision is not ours, but of the devteam.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

Use of Attributes 2 years 2 months ago #1454

  FFF's Avatar FFF Away Posts: 574
+1 for the "c" as for reasoning of cast only ;)

Please Log in or Create an account to join the conversation.

Use of Attributes 2 years 2 months ago #1455

  Frank Maraite's Avatar Frank Maraite Offline Posts: 173
Hi all,

after reading this completly (but not fully understand the consequences)

msdn.microsoft.com/de-de/library/system.char(v=vs.110).aspx

it seem that 'Ä' and "Ä" (german umlaut, but other characters too) is not always the same.

"Ä" maybe one chars or two chars.

Frank, a little bit confused now.

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
  • 2