Jump to page: 1 2
Thread overview
Putting quotes in wysiwyg strings
Nov 22, 2006
Bill Baxter
Nov 22, 2006
Lionello Lunesu
Nov 22, 2006
Bill Baxter
Nov 22, 2006
Lionello Lunesu
Nov 22, 2006
Bill Baxter
Nov 22, 2006
renox
Nov 22, 2006
Wolven
Nov 23, 2006
Lionello Lunesu
Nov 23, 2006
Hasan Aljudy
Nov 23, 2006
renox
Nov 23, 2006
Bill Baxter
Nov 22, 2006
John S. Skogtvedt
Nov 23, 2006
Hasan Aljudy
Nov 23, 2006
John S. Skogtvedt
Nov 23, 2006
Stewart Gordon
Nov 23, 2006
Bill Baxter
November 22, 2006
From the spec:  'There are no escape sequences inside r" ":'

Shouldn't there be an exception for the " character itself?
Right now the only way to put the quote into a wysiwyg string like
    foo"bar
is something like:
    r"foo" ~'"'~ r"bar";
or
    r"foo" "\"" r"bar";
or
    r"foo" `"` r"bar";

It would be a lot nicer if one could just do:

    r"foo\"bar";

And before you say I should just use ``, I'm writing an automatic resource wrapper that turns any text file into an embedded string, so I don't know ahead of time what's going to be in the string, and it may contain both `'s and "'s.

The goal is that the output string should look as much like the original text as possible.  One main use will be for embedding short script programs (like lua or minid) inside a D executable.

This:
    if (k & e.Shift) { ret ~= " `"` r"Shift" `"` r"; }
    if (k & e.Ctrl)  { if (ret) ret~=" `"` r"|" `"` r"; ret ~= " `"` r"Ctrl" `"` r"; }
    if (k & e.Alt)   { if (ret) ret~=" `"` r"|" `"` r"; ret ~= " `"` r"Alt" `"`
r"; }
    if (!ret) ret = " `"` r"None" `"` r";

definitely does not look very much like the original code.  :-(

But this does look reasonably close:
    if (k & e.Shift) { ret ~= \"Shift\"; }
    if (k & e.Ctrl)  { if (ret) ret~=\"|\"; ret ~= \"Ctrl\"; }
    if (k & e.Alt)   { if (ret) ret~=\"|\"; ret ~= \"Alt\"; }
    if (!ret) ret = \"None\";

--bb
November 22, 2006
Bill Baxter wrote:
>  From the spec:  'There are no escape sequences inside r" ":'
> 
> Shouldn't there be an exception for the " character itself?
> Right now the only way to put the quote into a wysiwyg string like
>     foo"bar
> is something like:
>     r"foo" ~'"'~ r"bar";
> or
>     r"foo" "\"" r"bar";
> or
>     r"foo" `"` r"bar";
> 
> It would be a lot nicer if one could just do:
> 
>     r"foo\"bar";


I'd prefer doubling the ", similar to program arguments on the command line:

r"foo""bar"

(This already compiles, but generates foobar instead of foo"bar; if you want foobar with the suggested behavior, you could add a space: r"foo" "bar")

L.
November 22, 2006
Oh, by the way:

"
    if (k & e.Shift) { ret ~= ""Shift""; }
    if (k & e.Ctrl)  { if (ret) ret~=""|""; ret ~= ""Ctrl""; }
    if (k & e.Alt)   { if (ret) ret~=""|""; ret ~= ""Alt""; }
    if (!ret) ret = ""None"";
"

;)
November 22, 2006
Lionello Lunesu wrote:
> Bill Baxter wrote:
> 
>>  From the spec:  'There are no escape sequences inside r" ":'
>>
>> Shouldn't there be an exception for the " character itself?
>> [...]
> 
> I'd prefer doubling the ", similar to program arguments on the command line:
> 
> r"foo""bar"
> 
> (This already compiles, but generates foobar instead of foo"bar; if you want foobar with the suggested behavior, you could add a space: r"foo" "bar")

You're right.  That would definitely be the cleaner solution.  If you use \ to escape the quote then you need yet another rule to handle the case where you want a literal \ followed by a " in the string.

--bb
November 22, 2006
Lionello Lunesu wrote:
> Oh, by the way:
> 
> "
>     if (k & e.Shift) { ret ~= ""Shift""; }
>     if (k & e.Ctrl)  { if (ret) ret~=""|""; ret ~= ""Ctrl""; }
>     if (k & e.Alt)   { if (ret) ret~=""|""; ret ~= ""Alt""; }
>     if (!ret) ret = ""None"";
> "
> 
> ;)

Yep, that looks quite reasonable (with the addition of an 'r' in front).
I wish it worked.  :-(

--bb
November 22, 2006
Bah, I feel that putting any fixed delimitor for string is bond to create a problem for some user whether it is simple, double quotes..

Why not reuse a good idea from the shell: <<FOO .... FOO putting a customisable end-of-text word can avoid many problem.

Sure this makes the parser a bit more complex, but not that much..
So for D it would be something like:
r <word>" ... "<word> where word is some text without space
or r(<word>)" .... "<word>  or the same thing but with a keyword "raw" instead of r.

Comments?

RenoX
November 22, 2006
Lionello Lunesu skrev:
> Oh, by the way:
> 
> "
>     if (k & e.Shift) { ret ~= ""Shift""; }
>     if (k & e.Ctrl)  { if (ret) ret~=""|""; ret ~= ""Ctrl""; }
>     if (k & e.Alt)   { if (ret) ret~=""|""; ret ~= ""Alt""; }
>     if (!ret) ret = ""None"";
> "
> 
> ;)
In python one can use:

r'''if (k & e.Shift) { ret ~= "Shift"; }
if (k & e.Ctrl)  { if (ret) ret~="|"; ret ~= "Ctrl"; }
if (k & e.Alt)   { if (ret) ret~="|"; ret ~= "Alt"; }
if (!ret) ret = "None"'''

or:

r"""if (k & e.Shift) { ret ~= "Shift"; }
if (k & e.Ctrl)  { if (ret) ret~="|"; ret ~= "Ctrl"; }
if (k & e.Alt)   { if (ret) ret~="|"; ret ~= "Alt"; }
if (!ret) ret = "None\""""
November 22, 2006
== Quote from renox (renaud.hebert@free.fr)'s article
> Bah, I feel that putting any fixed delimitor for string is bond to create a
> problem for some user whether it is simple, double quotes..
> Why not reuse a good idea from the shell: <<FOO .... FOO
> putting a customisable end-of-text word can avoid many problem.
> Sure this makes the parser a bit more complex, but not that much..
> So for D it would be something like:
> r <word>" ... "<word> where word is some text without space
> or r(<word>)" .... "<word>  or the same thing but with a keyword "raw" instead of r.
> Comments?
> RenoX

Well RenoX,
   I, for one, support your idea.  Years ago, I wondered why they didn't pick some
better character than a single and\or double quotes to bracket literals with.
Personally, I like the minature << and >> characters (ASCII decimal 171 and 187).
 You would still need some method of including those characters within a literal
but at least you wouldn't have the problem with single and double quotes which are
used in standard English text all the time...  :)
November 23, 2006

John S. Skogtvedt wrote:
> Lionello Lunesu skrev:
>> Oh, by the way:
>>
>> "
>>     if (k & e.Shift) { ret ~= ""Shift""; }
>>     if (k & e.Ctrl)  { if (ret) ret~=""|""; ret ~= ""Ctrl""; }
>>     if (k & e.Alt)   { if (ret) ret~=""|""; ret ~= ""Alt""; }
>>     if (!ret) ret = ""None"";
>> "
>>
>> ;)
> In python one can use:
> 
> r'''if (k & e.Shift) { ret ~= "Shift"; }
> if (k & e.Ctrl)  { if (ret) ret~="|"; ret ~= "Ctrl"; }
> if (k & e.Alt)   { if (ret) ret~="|"; ret ~= "Alt"; }
> if (!ret) ret = "None"'''
> 
> or:
> 
> r"""if (k & e.Shift) { ret ~= "Shift"; }
> if (k & e.Ctrl)  { if (ret) ret~="|"; ret ~= "Ctrl"; }
> if (k & e.Alt)   { if (ret) ret~="|"; ret ~= "Alt"; }
> if (!ret) ret = "None\""""

but if D has ''' or """ the problem will still manifest in the same way!!

counter example code:
auto x = """hey!''""";
auto y = '''yo!''';
//did you think you can use ` to do this?
auto z = """ oi ` oi """;

November 23, 2006

renox wrote:
> Bah, I feel that putting any fixed delimitor for string is bond to create a
> problem for some user whether it is simple, double quotes..
> 
> Why not reuse a good idea from the shell: <<FOO .... FOO
> putting a customisable end-of-text word can avoid many problem.
> 
> Sure this makes the parser a bit more complex, but not that much..
> So for D it would be something like:
> r <word>" ... "<word> where word is some text without space
> or r(<word>)" .... "<word>  or the same thing but with a keyword "raw" instead of r.
> 
> Comments?
> 
> RenoX

Walter likes to keep the lexer independent of the parser.
I don't understand your suggestion very well, but it seems to me that it will make the lexer dependent on the parser, and maybe even on the semantic analyzer. Well, depending on how do you define these "words".
« First   ‹ Prev
1 2