Though I agree it's not a strong argument, but comment content is arbitrary. 
It's either /*  arbitrary characters */ or // arbitrary characters <eoln>. 
String content has to be contextual interpreted, i.e. have knowledge of valid 
escape sequences or translation of eoln.

String s = """
\{"abc\"}"}
""";

Also,  do we allow

String t = """
\{"\{\"abc\"}"}
""";
or

String t = """
\"""
\{"\{\"abc\"}"}
\"""
""";

It's not impossible to parse, just a little more complicated than just counting 
braces.

On Oct 30, 2021, at 6:13 PM, Guy Steele 
<guy.ste...@oracle.com<mailto:guy.ste...@oracle.com>> wrote:



On Oct 29, 2021, at 10:10 AM, Jim Laskey 
<james.las...@oracle.com<mailto:james.las...@oracle.com>> wrote:

For our early templated string prototypes, we restricted embedded expressions 
to just basic accessors and basic arithmetic. The intent was to keep things 
easy to read and to prevent side effects. Over time, we began thinking this 
restriction was unduly harsh. More precisely, we worried it that it would 
result in a complex, difficult-to-defend boundary. But we still would like 
users to not rely on side-effects.

Consequently, a new proposal for embedded expressions - we would allow any Java 
expression with the restriction that you can't use single quotes, double quotes 
or escape sequences. We opted to keep this restriction to allow tools (ex., 
syntax highlighters) to isolate embedded expressions within strings without 
requiring sophisticated parsing.

An interesting restriction. Would comments also be forbidden within such 
expressions (for the same reason)?

—Guy



Reply via email to