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.
'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
| '\' //
| '' // 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
robert@xsharp.eu
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
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
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
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
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
robert@xsharp.eu
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
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it