Thread overview | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
July 26, 2003 String literals | ||||
---|---|---|---|---|
| ||||
Currently, there are 3 kinds of string literals: 'string' : wysiwyg strings "string" : escaped strings \ : single character strings There is no character literal syntax; 1 character long strings are implicitly converted to character literals based on context. Unfortunately, this leads to ambiguities with no reasonable way out (other than crafting arbitrary and confusing rules). So, I've been thinking of going back to the C way and having ' ' for character literals. That means that wysiwyg strings are left without a lexical syntax. Any ideas for something that would look nice? How about using back quotes ` `, or is that just too hard to distinguish in certain fonts? One thing to keep in mind is that wysiwyg strings are not going to be used with nearly the same frequency as escaped strings, so the syntax can be a bit less convenient for them. I'd like to use /string/, but that leads to too may lexical ambiguities. Some possibilities are: 1) prefixing the " with a letter or a character, as in: W"string" %"string" !"string" 2) using a character not used in C, such as: `string` $string$ @string@ #string# |
July 26, 2003 Re: String literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | What about double double quotes for wysiwyg?
""string"" : wysiwyg string
I don't really like that syntax, but I think it's better than any of the other alternatives proposed so far. I like the fact that it uses a quote character to denote a string, rather than some other, arbitrarily selected character.
Walter wrote:
> Currently, there are 3 kinds of string literals:
> 'string' : wysiwyg strings
> "string" : escaped strings
> \ : single character strings
>
> There is no character literal syntax; 1 character long strings are
> implicitly converted to character literals based on context. Unfortunately,
> this leads to ambiguities with no reasonable way out (other than crafting
> arbitrary and confusing rules).
>
> So, I've been thinking of going back to the C way and having ' ' for
> character literals. That means that wysiwyg strings are left without a
> lexical syntax. Any ideas for something that would look nice? How about
> using back quotes ` `, or is that just too hard to distinguish in certain
> fonts? One thing to keep in mind is that wysiwyg strings are not going to be
> used with nearly the same frequency as escaped strings, so the syntax can be
> a bit less convenient for them.
>
> I'd like to use /string/, but that leads to too may lexical ambiguities.
>
> Some possibilities are:
> 1) prefixing the " with a letter or a character, as in:
> W"string"
> %"string"
> !"string"
> 2) using a character not used in C, such as:
> `string`
> $string$
> @string@
> #string#
>
>
|
July 26, 2003 Re: String literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russ Lewis | "Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:bfuc2b$5ck$1@digitaldaemon.com... > What about double double quotes for wysiwyg? > > ""string"" : wysiwyg string > > I don't really like that syntax, but I think it's better than any of the other alternatives proposed so far. I like the fact that it uses a quote character to denote a string, rather than some other, arbitrarily selected character. It's a good idea, but it conflicts with using "" to denote an empty string. I thought of using "'string'", but it looks too weird <g>. |
July 26, 2003 Re: String literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "Walter" <walter@digitalmars.com> wrote in news:bfu9kp$3f1$1@digitaldaemon.com: > Currently, there are 3 kinds of string literals: > 'string' : wysiwyg strings > "string" : escaped strings > \ : single character strings > > There is no character literal syntax; 1 character long strings are implicitly converted to character literals based on context. Unfortunately, this leads to ambiguities with no reasonable way out (other than crafting arbitrary and confusing rules). > > So, I've been thinking of going back to the C way and having ' ' for character literals. That means that wysiwyg strings are left without a lexical syntax. Any ideas for something that would look nice? How about using back quotes ` `, or is that just too hard to distinguish in certain fonts? One thing to keep in mind is that wysiwyg strings are not going to be used with nearly the same frequency as escaped strings, so the syntax can be a bit less convenient for them. > > I'd like to use /string/, but that leads to too may lexical ambiguities. > > Some possibilities are: > 1) prefixing the " with a letter or a character, as in: > W"string" > %"string" > !"string" These are ok. > 2) using a character not used in C, such as: > `string` > $string$ > @string@ > #string# I think you should reserve these symbols for other things. Python uses """ for multi line strings. I find it useful. a=""" Line 1 Line 2 """ |
July 26, 2003 Re: String literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | Walter wrote:
> Some possibilities are:
> 2) using a character not used in C, such as:
> `string`
> $string$
> @string@
> #string#
Using these ugly chacacters seems somewhat... ugly to me. Vote Against.
> 1) prefixing the " with a letter or a character, as in:
> W"string"
> %"string"
> !"string"
Why do you want to prefix wysisyg strings? You may also prefix a string which is to mean character literal - which seems to make more sense to me.
W"" looks too much like wide-something.
Using % would prohibit overloading % as an operator where string is a second parameter. I consider ir useful as a formatting operator or somesuch.
! seems to be OK since it's a unary opertor anyway, and as such cannot be overloaded for a built-in types.
-i.
|
July 26, 2003 Re: String literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | what about a perl-like quotation ? s (for string?) followed by any character as delimiter. s/.../ s#...# s%...% s!...! So you can choose the delimiter to avoid escaping. ok it's a bit ugly. can the lexer handle this kind of backward reference ? -- Nicolas Repiquet |
July 26, 2003 Re: String literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | I thought of that too, but it conflicts with '"' and "'". What about '' (two single quotes)? 'c' // char ''string'' // wysiwyg string "string" // escaped string I wouldn't be opposed to backquotes, either. `string` or ``string`` Unicode has some nice quotes too. Sean "Walter" <walter@digitalmars.com> wrote in message news:bfucor$64l$1@digitaldaemon.com... > > "Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:bfuc2b$5ck$1@digitaldaemon.com... > > What about double double quotes for wysiwyg? > > > > ""string"" : wysiwyg string > > > > I don't really like that syntax, but I think it's better than any of the other alternatives proposed so far. I like the fact that it uses a quote character to denote a string, rather than some other, arbitrarily selected character. > > It's a good idea, but it conflicts with using "" to denote an empty string. > I thought of using "'string'", but it looks too weird <g>. |
July 26, 2003 Re: String literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "More spectacularly" distinguishing char literals from string literals, in that they won't be surrounded by delimiters but just prefixed with something, may also be a good solution. (Char literals, after all, are totally different animals than string literals in many ways.) Then some prefix char and some simple rules to allow various (unambiguous) representations of a char need to be defined. Sz. "Walter" <walter@digitalmars.com> wrote in message news:bfu9kp$3f1$1@digitaldaemon.com... > Currently, there are 3 kinds of string literals: > 'string' : wysiwyg strings > "string" : escaped strings > \ : single character strings > > There is no character literal syntax; 1 character long strings are implicitly converted to character literals based on context. Unfortunately, this leads to ambiguities with no reasonable way out (other than crafting arbitrary and confusing rules). > > So, I've been thinking of going back to the C way and having ' ' for character literals. That means that wysiwyg strings are left without a lexical syntax. Any ideas for something that would look nice? How about using back quotes ` `, or is that just too hard to distinguish in certain fonts? One thing to keep in mind is that wysiwyg strings are not going to be used with nearly the same frequency as escaped strings, so the syntax can be a bit less convenient for them. > > I'd like to use /string/, but that leads to too may lexical ambiguities. > > Some possibilities are: > 1) prefixing the " with a letter or a character, as in: > W"string" > %"string" > !"string" > 2) using a character not used in C, such as: > `string` > $string$ > @string@ > #string# > > |
July 26, 2003 Re: String literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to Luna Kid | > simple rules to allow various (unambiguous) representations
> of a char need to be defined.
Umm, those rules are already defined as EscapeSequence. :)
So, how about this?
Strings:
'verbatim, as before'
"escaped,\x20as\x20before"
Chars:
#c <-- letter 'c'
## <-- is this problematic in D?
#\t <-- Tab
#\x20 <-- Space
#\\ <-- Backslash
Sz.
|
Copyright © 1999-2021 by the D Language Foundation