digitalmars.D - WYSIWYG string still limited
- Swer (15/15) Dec 15 2007 r"abc\s*$" ok
- Kirk McDonald (13/35) Dec 15 2007 The D 2.x series has already added a few new forms of string literals,
- Swer (17/22) Dec 15 2007 hmm thats still not enough, and complex for compiler to implement. I
- Kirk McDonald (26/60) Dec 15 2007 The compiler already has implemented them. Also, I've written the D
- Swer (2/10) Dec 16 2007 That's I want, D 2.0 is great! Thanks!
- Robert DaSilva (4/26) Dec 15 2007 We do.
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.
Dec 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
Dec 15 2007
"Kirk McDonald" <kirklin.mcdonald gmail.com> Swer wrote: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.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"
Dec 15 2007
Swer wrote:"Kirk McDonald" <kirklin.mcdonald gmail.com> Swer wrote: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.hmm thats still not enough, and complex for compiler to implement. I modified my poposal as below: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"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
Dec 15 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!
Dec 16 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
Dec 15 2007