<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body dir="auto">
I suppose I should have mentioned you can do this by convention as well. Define RAW and use to highlight where StringTemplates are needed.
<div><br>
</div>
<div>TemplateProcessor<<span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">StringTemplate</span>> RAW = st -> st;</div>
<div><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">StringTemplate template = RAW.”…”;</span></div>
<div><br>
<div dir="ltr">📱</div>
<div dir="ltr"><br>
<blockquote type="cite">On Oct 21, 2022, at 6:03 PM, Jim Laskey <james.laskey@oracle.com> wrote:<br>
<br>
</blockquote>
</div>
<blockquote type="cite">
<div dir="ltr"> It’s not unreasonable. In fact, the early POCs had a RAW processor.
<div><br>
</div>
<div>I would still like to see how it plays out as-is during Preview. Others might develop other opinions or ideas. </div>
<div><br>
</div>
<div>Cheers,</div>
<div><br>
</div>
<div>— Jim<br>
<div dir="ltr">📱</div>
<div dir="ltr"><br>
<blockquote type="cite">On Oct 21, 2022, at 5:34 PM, Tagir Valeev <amaembo@gmail.com> wrote:<br>
<br>
</blockquote>
</div>
<blockquote type="cite">
<div dir="ltr">
<div dir="auto">
<div>Hello!<br>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Fri, Oct 21, 2022, 15:05 Victor Nazarov <<a href="mailto:asviraspossible@gmail.com" rel="noreferrer noreferrer" target="_blank">asviraspossible@gmail.com</a>> wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">
<div dir="ltr" class="gmail_attr">
<div>Hello!<br>
</div>
<div><br>
</div>
<div>I think one suggestion that fixes stated problems was already proposed before and I heard no arguments against going this route</div>
<div dir="auto">...</div>
</div>
<div class="gmail_quote">
<div><br>
</div>
<div>One suggestion that fixes this problem is to forbid bare template strings without policy-prefixes and instead introduce some policy that returns TemplateString itself.</div>
<div><br>
</div>
<div>````<br>
</div>
<div> StringTemplate tmpl = TMPL."\{x} plus \{y} equals \{x + y}" ;</div>
<div> String s1 = tmpl.apply(STR);</div>
<div> String s2 = STR."\{x} plus \{y} equals \{x + y}";</div>
<div> assertEquals(s1, s2);</div>
<div>````<br>
</div>
<div><br>
</div>
In this world the following can be observed:<br>
<br>
````<br>
System.out.println(STR."\{x} plus \{y} equals \{x + y}"); // Prints "10 plus 20 equals 30"<br>
System.out.println(TMPL."\{x} plus \{y} equals \{x + y}"); // Prints "StringTemplate{segments = ["", " plus ", " equals "], values = [10, 20, 30]}"</div>
<div class="gmail_quote"> System.out.println("\{x} plus \{y} equals \{x + y}"); // COMPILATION ERROR: error: unrecognized escape sequence '\{', policy is required for template strings</div>
<div class="gmail_quote">````<br>
</div>
</div>
</blockquote>
</div>
</div>
<div dir="auto"><br>
</div>
<div dir="auto">Sounds really good to me. In any case, template expression is not directly substitutable. E.g. you cannot replace</div>
<div dir="auto"><br>
</div>
<div dir="auto">STR."Hello \{user}"</div>
<div dir="auto"><br>
</div>
<div dir="auto">with</div>
<div dir="auto"><br>
</div>
<div dir="auto">StringTemplate t = "Hello \{user}"</div>
<div dir="auto">STR.t</div>
<div dir="auto"><br>
</div>
<div dir="auto">Instead, you need to desugar to a method call, like STR.process(t). I think that in Java, all the expressions we had before were substitutable in this sense: you could extract them to variable, and use that variable instead. So it would be more
consistent to avoid naming the right part of process template expression as expression itself. I would suggest the following:</div>
<div dir="auto"><br>
</div>
<div dir="auto">If parser meets a dot that follows single double quote, or triple double quote, then the right part is always a string template, or a text blocks template, and the whole thing including qualifier is process template expression. Template may
have no substitutions at all, in this case it looks exactly like string or text block, but it's a template. Template is not an expression and cannot appear in any context other than in process template expression.</div>
<div dir="auto"><br>
</div>
<div dir="auto">This simplifies grammar somewhat, as we say that template without placeholders is still a template. Also, having an identity template processor, like TMPL proposed by Victor, makes it possible and consistent to instantiate the StringTemplate
object that contains no placeholders. The cost is five characters (TMPL.) necessary for presumably rare and advanced uses of templates where one wants to store it without immediate processing.</div>
<div dir="auto"><br>
</div>
<div dir="auto">What do you think?</div>
<div dir="auto">Tagir Valeev </div>
</div>
</div>
</blockquote>
</div>
</div>
</blockquote>
</div>
</body>
</html>