Alternate string literal syntax (with mixins)?

janderson askme at me.com
Fri Feb 16 08:58:21 PST 2007


Kristian Kilpi wrote:
> On Fri, 16 Feb 2007 07:54:01 +0200, janderson <askme at me.com> wrote:
> 
>> janderson wrote:
>>> Kristian Kilpi wrote:
>>>>
>>>> String literals with mixins are a bit awkward sometimes (editor 
>>>> highlighting etc).
>>>>
>>>> Some special marks -- I use @{ }@ here -- could be used to mark a 
>>>> part of a source file as a string literal, just like /* */ marks a 
>>>> part of code as a comment. For example:
>>>>
>>>>   mixin(
>>>>     @{
>>>>       //this is a string literal block
>>>>       if(..) {
>>>>         ...
>>>>       }
>>>>     }@
>>>>   );
>>>>
>>>> The @{ }@ marks have a close relation, of course, with quotation 
>>>> marks "". But because there is a starting mark and an ending mark, 
>>>> you can nest them. (And because they are used to mark a part of a 
>>>> file as a string literal, they are not actually the part of the 
>>>> 'working code' just like the "" literals are, if you get what I'm 
>>>> trying to say.)
>>>>
>>>> E.g.
>>>>
>>>>   alias @{
>>>>     str = @{ foo }@ ~ @{ bar }@;
>>>>     str ~= "blah";
>>>>     if(...) {
>>>>       ...
>>>>     }
>>>>   }@ MyCode;
>>>>
>>>>    mixin(MyCode);
>>>  Just a thought what about keeping this in the same spirit of D's 
>>> other string prefixes. ie
>>>  char[] string = l"
>>>   ";
>>>  I do like the label idea suggested before:
>>>  Perhaps:
>>>  char[] string = :something"
>>>   ":something;
>>>  Which would work with the  other postfixes:
>>>  char[] string = r:something"
>>>   "d:something;
>>>  And you could also choose not to label it:
>>>  char[] string = :"
>>>   ":;
>>>  Best of all worlds.
>>>  -Joel
>>
>>
>> Humm would be problomatic with ()?:
>>
>> Well @ or $ would be fine. I guess although it looks syntacticly ugly 
>> to me.
>>
>> char[] string = @label"
>>
>>
>> "@label;
>>
>> -Joel
> 
> Well, one could use ::" ":: syntax which is not ambiguous. However, 
> that's a bit lengthy.
> 
> In addition, because the syntax contains quotation marks, editors will 
> treat the text between them as normal strings. Instead, it would be 
> nice, IMO, that (meta)code between the marks would be highlighted normally.

It's a nice idea, however if you do a partial bit of code inside the 
mixin, some IDE's will choke.  Maybe using {} in some form would be 
helpful, although I think many IDE's will still have issues.

ie mixin(@ int A;
int
@

Ok the example is contrived, but I could imagine cases where you want to 
join string together.



More information about the Digitalmars-d mailing list