StringTemplate evolution

P Holder pholder at gmail.com
Tue Mar 19 19:56:15 UTC 2024


Now that it appears that StringTemplates are evolving to a special
introducer token, I hope it's also being recognized that they can then also
change to support a syntax that is more friendly and common with other
languages.  In particular, there would appear to be no need any more to
require the backslash to introduce the values.  The backslash can now be
reversed and offered to escape the open brace when it's desired as a
literal.

To get the result: The value of foo is 42.
Go from:
  STR."The value of \{name} is \{value}.";
to
  $"The value of {name} is {value}.";

and to get the result: The value of {foo} is {42}.
Go from:
  STR."The value of {\{name}} is {\{value}}";
to:
  $"The value of \{{name}} is \{{value}}";

I'd also propose that you could use a keyword token instead of the $
without causing too much grief.  This would have the benefit of looking
like a name, and allowing for future evolution in a direction where you
might want something additional and don't want to find an additional
punctuation character.

So, where ST stands for StringTemplate a string template could look like:
  ST."The value of {name} is {value}.";
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20240319/dc35f88d/attachment-0001.htm>


More information about the amber-dev mailing list