Thread overview
WYSIWYG string still limited
Dec 15, 2007
Swer
Dec 15, 2007
Kirk McDonald
Dec 15, 2007
Swer
Dec 15, 2007
Kirk McDonald
Dec 16, 2007
Swer
Dec 15, 2007
Robert DaSilva
December 15, 2007
r"abc\s*$"  ok
r"abc"s*$"  fail

 `abc"s*$`  ok
 `abc`s*$`  fail

as a improvement from C/C++, D use [`] as WYSIWYG string delimiter easy to use, but still not enough. why dont perfect solution to WYSIWYG string. perl has one, but not fit for D. My poposal below.

pargam(delimiter, "[[WYSIWYG]]");

const char [] somestr = [[WYSIWYG]]
You can use write any some here.
const char [] code_demo1 = `demo1`;
const char [] code_demo2 = r"demo2";
[[WYSIWYG]]

ofcause you can replace the delimiter from "[[WYSIWYG]]" to any string you like.


December 15, 2007
Swer wrote:
> r"abc\s*$"  ok
> r"abc"s*$"  fail
> 
>  `abc"s*$`  ok
>  `abc`s*$`  fail
> 
> as a improvement from C/C++, D use [`] as WYSIWYG string delimiter easy to use, but still not enough. why dont perfect solution to WYSIWYG string. perl has one, but not fit for D. My poposal below.
> 
> pargam(delimiter, "[[WYSIWYG]]");
> 
> const char [] somestr = [[WYSIWYG]]
> You can use write any some here.
> const char [] code_demo1 = `demo1`;
> const char [] code_demo2 = r"demo2";
> [[WYSIWYG]]
> 
> ofcause you can replace the delimiter from "[[WYSIWYG]]" to any string you like. 
> 
> 

The D 2.x series has already added a few new forms of string literals, including delimited strings. They look like this:

q"(foo(xxx))"   // "foo(xxx)"
q"[foo{]"       // "foo{"
q"/foo"bar/"    // "foo\"bar"

They are documented here:

http://digitalmars.com/d/lex.html#StringLiteral

-- 
Kirk McDonald
http://kirkmcdonald.blogspot.com
Pyd: Connecting D and Python
http://pyd.dsource.org
December 15, 2007
Swer wrote:
> r"abc\s*$"  ok
> r"abc"s*$"  fail
> 
>  `abc"s*$`  ok
>  `abc`s*$`  fail
> 
> as a improvement from C/C++, D use [`] as WYSIWYG string delimiter easy to use, but still not enough. why dont perfect solution to WYSIWYG string. perl has one, but not fit for D. My poposal below.
> 
> pargam(delimiter, "[[WYSIWYG]]");
> 
> const char [] somestr = [[WYSIWYG]]
> You can use write any some here.
> const char [] code_demo1 = `demo1`;
> const char [] code_demo2 = r"demo2";
> [[WYSIWYG]]
> 
> ofcause you can replace the delimiter from "[[WYSIWYG]]" to any string you like.
> 
> 

We do.
q"[do"too]"
http://www.digitalmars.com/d/lex.html#StringLiteral
December 15, 2007
"Kirk McDonald" <kirklin.mcdonald@gmail.com> Swer wrote:
> > The D 2.x series has already added a few new forms of string literals,
> including delimited strings. They look like this:
>
> q"(foo(xxx))"   // "foo(xxx)"
> q"[foo{]"       // "foo{"
> q"/foo"bar/"    // "foo\"bar"

hmm thats still not enough, and complex for compiler to implement. I modified my poposal as below:

const char [] code_demo = {{anystr{
 q"(foo(xxx))"   // "foo(xxx)"
 q"[foo{]"       // "foo{"
 q"/foo"bar/"    // "foo\"bar"
}anystr}}

or

const char [] code_demo = {{{
 q"(foo(xxx))"   // "foo(xxx)"
 q"[foo{]"       // "foo{"
 q"/foo"bar/"    // "foo\"bar"
}}}

if there is no }}} in text.

'anystr' can be replaced to any string you like. '{{'  '}}'  '{{{'  '}}}' are easier for compiler to detect.


December 15, 2007
Swer wrote:
> "Kirk McDonald" <kirklin.mcdonald@gmail.com> Swer wrote:
> 
>>>The D 2.x series has already added a few new forms of string literals,
>>
>>including delimited strings. They look like this:
>>
>>q"(foo(xxx))"   // "foo(xxx)"
>>q"[foo{]"       // "foo{"
>>q"/foo"bar/"    // "foo\"bar"
> 
> 
> hmm thats still not enough, and complex for compiler to implement. I modified my poposal as below:
> 

The compiler already has implemented them. Also, I've written the D lexer in Pygments (which supports them) and implemented highlighting for these new string literals in vim. They are not particularly hard to implement.

> const char [] code_demo = {{anystr{
>  q"(foo(xxx))"   // "foo(xxx)"
>  q"[foo{]"       // "foo{"
>  q"/foo"bar/"    // "foo\"bar"
> }anystr}}
> 
> or
> 
> const char [] code_demo = {{{
>  q"(foo(xxx))"   // "foo(xxx)"
>  q"[foo{]"       // "foo{"
>  q"/foo"bar/"    // "foo\"bar"
> }}}
> 
> if there is no }}} in text.
> 
> 'anystr' can be replaced to any string you like. '{{'  '}}'  '{{{'  '}}}' are easier for compiler to detect.
> 
> 

If you'd bothered looking at the docs, you'd have seen that there are other forms of string literals which I did not mention. There are token strings:

q{
 q"(foo(xxx))"   // "foo(xxx)"
 q"[foo{]"       // "foo{"
 q"/foo"bar/"    // "foo\"bar"
}

These have the caveat that they can only contain valid D tokens.

There are also heredoc strings, which are really just a kind of delimited string:

q"IDENT
This is a string. It can contain anything.
IDENT"

IDENT may be any identifier. The newlines after the opening identifier and before the closing one are required.

-- 
Kirk McDonald
http://kirkmcdonald.blogspot.com
Pyd: Connecting D and Python
http://pyd.dsource.org
December 16, 2007
"Kirk McDonald" <kirklin.mcdonald@gmail.com>  Swer wrote:
> These have the caveat that they can only contain valid D tokens.
>
> There are also heredoc strings, which are really just a kind of delimited string:
>
> q"IDENT
> This is a string. It can contain anything.
> IDENT"
>
> IDENT may be any identifier. The newlines after the opening identifier and before the closing one are required.

That's I want, D 2.0 is great! Thanks!