digitalmars.D.learn - What's that 'q' before '{' in this code?
- Machine Code (1/1) Jan 15 2019 https://github.com/dlang/dmd/blob/master/src/dmd/compiler.d#L75
- SrMordred (3/4) Jan 15 2019 https://dlang.org/spec/lex.html#token_strings
- Machine Code (9/13) Jan 15 2019 I had just infered from the commend in the code "The D code to be
- Adam D. Ruppe (7/8) Jan 15 2019 It is a string literal that must be made out of D code tokens.
On Tuesday, 15 January 2019 at 17:52:35 UTC, Machine Code wrote:https://github.com/dlang/dmd/blob/master/src/dmd/compiler.d#L75https://dlang.org/spec/lex.html#token_strings :)
Jan 15 2019
On Tuesday, 15 January 2019 at 17:56:10 UTC, SrMordred wrote:On Tuesday, 15 January 2019 at 17:52:35 UTC, Machine Code wrote:I had just infered from the commend in the code "The D code to be generated is provided as D source code in the form of a string." then I tried: auto s = q{ foo(); return 10 }; writeln(s); Then whoa. What a feature! I'm not aware of any language with this feature. Amazing. Thank for your answer as well :)https://github.com/dlang/dmd/blob/master/src/dmd/compiler.d#L75https://dlang.org/spec/lex.html#token_strings :)
Jan 15 2019
On Tuesday, 15 January 2019 at 17:52:35 UTC, Machine Code wrote:https://github.com/dlang/dmd/blob/master/src/dmd/compiler.d#L75It is a string literal that must be made out of D code tokens. In my blog this week, I talked about some code that uses them: http://dpldocs.info/this-week-in-d/Blog.Posted_2019_01_14.html#the-generated-client You can see how it syntax highlights as code, but is semantically a string. The code inside is passed to mixin, so this hybrid appearance works well.
Jan 15 2019