[squeak-dev] [Pharo-dev] Re: [vwnc] Does anyone have a "new" string literal?

H. Hirzel hannes.hirzel at gmail.com
Mon Feb 27 18:58:45 UTC 2017


On 2/27/17, DavidLeibs <david.leibs at gmail.com> wrote:
> I realize this is a few years old but I wanted to give an update on my
> quest
> for quasi-literals.  I did a complete quasi-literal framework for Java when
> I moved over to Oracle Labs.  It used the annotation compiler + a few
> tweeks
> to the scanner and parser.  You could extend the name space of the
> quasi-literal and have inline SQL or APL.  All the parsing, validation, and
> code rewriting happened at compile time. We proposed it to the Java Product
> guys and got ignored to death.
>
> As to the characters I did backquote for simple quasi-literal Strings and
> used Oxford Brackets for the quasi-literals with a language namespace. <|
> ...|>.  Back quote can be hard to see but is nice for String substitute.
>
> At this point in time the language that does it most right is JavaScript.
> Thanks Mark Miller for all the hard work over the years!

Thanks David for following up this discussion.

I wonder if just going for JavaScript ES6 solution (back-ticks) would
be the most straightforward thing to do?

--Hannes


https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Template_literals

Syntax
----------

`string text`

`string text line 1
 string text line 2`

`string text ${expression} string text`

tag `string text ${expression} string text`


Description
----------------

Template literals are enclosed by the back-tick (` `) (grave accent)
character instead of double or single quotes. Template literals can
contain place holders. These are indicated by the Dollar sign and
curly braces (${expression}). The expressions in the place holders and
the text between them get passed to a function. The default function
just concatenates the parts into a single string. If there is an
expression preceding the template literal (tag here),  the template
string is called "tagged template literal". In that case, the tag
expression (usually a function) gets called with the processed
template literal, which you can then manipulate before outputting. To
escape a back-tick in a template literal, put a backslash \ before the
back-tick.


More information about the Squeak-dev mailing list