July 26, 2003 Re: String literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | 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 like r"string", which is used in a number of languages already.
|
July 26, 2003 Re: String literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to DeadCow | "DeadCow" <deadcow-remove-this@free.fr> wrote in message news:bfuit9$bnr$1@digitaldaemon.com... > > 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. <g> > can the lexer handle this kind of backward reference ? Yes. |
July 26, 2003 Re: String literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to Patrick Down | "Patrick Down" <pat@codemoon.com> wrote in message news:Xns93C480D51FA3Dpatcodemooncom@63.105.9.61... > Python uses """ for multi line strings. I find it > useful. > > a=""" > Line 1 > Line 2 > """ That will work. But an empty string would be """""". Hmm. How about perhaps two single quotes, as in ''f''? Sadly, in a proportional font, it looks just like "f". |
July 26, 2003 Re: String literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | "Sean L. Palmer" <palmer.sean@verizon.net> wrote in message news:bfunju$g8e$1@digitaldaemon.com... > What about '' (two single quotes)? > > 'c' // char > ''string'' // wysiwyg string > "string" // escaped string In a proportional font, they are nearly indistinguishable. > I wouldn't be opposed to backquotes, either. > > `string` > > or > > ``string`` Probably ` is the current leading contender. > Unicode has some nice quotes too. I want to use something on a regular keyboard <g>. |
July 26, 2003 Re: String literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "Walter" <walter@digitalmars.com> wrote in message news:bfussh$kiq$1@digitaldaemon.com... > > "DeadCow" <deadcow-remove-this@free.fr> wrote in message news:bfuit9$bnr$1@digitaldaemon.com... > > > > 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. > > <g> > > > can the lexer handle this kind of backward reference ? > > Yes. My mistake, no it can't. s% would tokenize ambiguously. |
July 26, 2003 Re: String literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to Luna Kid | "Luna Kid" <lunakid@neuropolis.org> wrote in message news:bfuqr0$irj$1@digitaldaemon.com... > > 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 It's a good idea, but # has a problem with making it impractical to pass the source through a C preprocessor first! |
July 26, 2003 Re: String literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to Burton Radons | "Burton Radons" <loth@users.sourceforge.net> wrote in message news:bfusdh$k5e$1@digitaldaemon.com... > I like r"string", which is used in a number of languages already. Which ones? |
July 26, 2003 Re: String literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | > > Strings:
> >
> > 'verbatim, as before'
> >
> > "escaped,\x20as\x20before"
> >
> > Chars:
> >
> > #c <-- letter 'c'
> > ## <-- is this problematic in D?
> > #\t <-- Tab
> > #\x20 <-- Space
> > #\\ <-- Backslash
>
> It's a good idea, but # has a problem with making it impractical to pass the source through a C preprocessor first!
I see.
Well, for me, any other prefix would do, if not too
obscure (should be easy to type).
@ perhaps? (Familiar to the fingers from emails. ;) )
Sz.
|
July 26, 2003 Re: String literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | > 1) prefixing the " with a letter or a character, as in: > W"string" > %"string" Neither of these attract me. The % will be confusing with printf() format strings. The W ... just don't like it. > !"string" Definitely not. !"message string" is useful in asserts in C++. I've not given it any thought, but it seems that this could/would similarly in D. > 2) using a character not used in C, such as: > `string` I like this, but probably in a minority of 1 (or 2) > $string$ > @string@ > #string# Hate all of these. Here's an unpopular thought: why not use @"string" and be consistent with C#? Easier on the brain even if it doffs one's cap to M$ |
July 26, 2003 Re: String literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | Walter wrote:
> "Sean L. Palmer" <palmer.sean@verizon.net> wrote in message
> news:bfunju$g8e$1@digitaldaemon.com...
>
>>What about '' (two single quotes)?
>>
>>'c' // char
>>''string'' // wysiwyg string
>>"string" // escaped string
>
>
> In a proportional font, they are nearly indistinguishable.
I think Python uses something like triple double quotes for something.
"""This is a docstring or a preformatted string, IIRC."""
-i.
|
Copyright © 1999-2021 by the D Language Foundation