Multiline template strings that don't break indentation

Salvador de la Puente González salva at unoyunodiez.com
Thu Sep 11 00:16:28 PDT 2014


Hi guys.

Notice we are dealing with literals and I would want to keep the strings as
literal as possible so I think this is a syntax issue as the programmatic
solution like regexp  substitution is always available.

My proposal:
var s = `This is a multiline
string. It keeps literal unless
            ' finding that mark. It
            ' delimit the beginning
            ' of the text and must
            ' be the first one. I mean
            ' this other ' is interpreted
            ' as a quote. The double
            ' quote is valid as well.`;

This is syntax can be automatized by text editors. To avoid ambiguity, the
following is a syntax error:

var s = `This is a syntax error
to have characters before ' but
only for the first`;

To not find a quote mark in a line implies to take the full line literally.

The syntax is quite informative as it points the specific column where
literal start again.

Notice the case you specifically want to write the delimiter is quite rare
and you always can provide:

var s = `Take this
             \' literal`;

You don't need the quotes to be even aligned.

WDYT?
 On 11 Sep 2014 08:37, "李白|字一日" <calidion at gmail.com> wrote:

> I would prefer
>
> var a = `This is a template string.`
>      `Even though each line is indented to keep the`
>      `code neat and tidy, the white space used to indent`
>      `is not in the resulting string` keepindentation`;
>
> as a multiple line string,
>
>
> 2014-09-11 13:55 GMT+08:00 Sebastian Zartner <sebastianzartner at gmail.com>:
>
>> On 9 September 2014 16:51, Allen Wirfs-Brock <allen at wirfs-brock.com>
>> wrote:
>>
>>> Well, just for fun
>>>
>>>         const N = "\n";  //maybe we could find evocative unicode name.
>>>         var a = `This is a template string. ${
>>>                N}Even though each line is indented to keep the ${
>>>                N}code neat and tidy, the white space used to indent ${
>>>                N}is not in the resulting string`;
>>>
>>
>> To me this looks still somewhat hacky.
>> Couldn't a simple keyword be added at the the end of a template string?
>> So it would be something like this:
>>
>>         var a = `This is a template string.
>>                  Even though each line is indented to keep the
>>                  code neat and tidy, the white space used to indent
>>                  is not in the resulting string` keepindentation;
>>
>> This would explicitly keep the spaces at the beginning of each line while
>> without the keyword they would be removed. Of course the keyword may also
>> indicate the opposite depending on parsing would be chosen as default.
>> Surely the name for this keyword is not optimal yet and would need to be
>> discussed.
>>
>> Sebastian
>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140911/3463b6b2/attachment-0001.html>


More information about the es-discuss mailing list