[squeak-dev] [Pharo-dev] Re: [vwnc] Does anyone have a "new" string literal?
Eliot Miranda
eliot.miranda at gmail.com
Mon Feb 27 21:33:42 UTC 2017
Hi Hannes,
On Mon, Feb 27, 2017 at 10:58 AM, H. Hirzel <hannes.hirzel at gmail.com> wrote:
> 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?
>
I did a quick hack in Squeak but didn't have time to finish is. I wrote
some tests. Complex cases worked, small tricky cases broke the scanner.
MCHttpRepository
location: 'http://source.squeak.org/inbox'
user: ''
password: ''
Compiler.quasiliteral-eem.280
[Derived from Compiler-nice.279, and renamed from
the bogusly named Compiler.quasiquote-eem.248]
Add a quasi-literal form for "string interpolation", that allows
convenient embedding of expressions within a format string,
and provides a convenient way of embedding literal strings
within an alternative literal string syntax whose string delimiter
is different.
e.g.
`hello [#cruel] world!`
evaluates to
'hello cruel world'.
`S1[B1]...SN[BN]SN+1`
is equivalent to
{ 'S1'. [B1] value. ... 'SN'. [BN] value. 'SN+1' } concatenateQuasiLiteral
where concatenateQuasiLiteral sends asString to each
element and answers the concatenation of those elements.
however, single-statement blocks are inlined, so e.g. the
above `hello [#cruel] world!` is compiled as
{ 'hello '. #cruel. ' world!' } concatenateQuasiLiteral
See e.g. Tests.quasiliteral-eem.296 for tests and examples.
Tests.quasiliteral-eem.296
Renamed from the bogus quasiquote to quasiliteral.
Added Balazs' errors as failing tests.
> --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.
>
>
--
_,,,^..^,,,_
best, Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20170227/46120b1d/attachment.html>
More information about the Squeak-dev
mailing list
|