On 17.05.2018 02:31, Jochen Theodorou wrote:
So one obvious difference between our literals and the raw string is
the interpretation of escaping and interpolation. But if you are
really thinking about it... if I have /some regexp/, then does it need
to be interpolated?
I use interpolated regex strings quite a lot in my framework, to create
regex expressions from smaller building blocks, so that would be an
unpleasant breaking change for me.
What about not trying to reduce the number of string literals, but
creating a uniform, building block syntax for them, where you can easily
express different escaping/interpolation needs in a compact, unified
manner ?
From the top of my hat, just to visualize the general idea:
final GString multilineRegularexpressionInterpolated = mri"age:(\d+)
phone:${telephoneNumberRegex}
"
Translation
=========
'a' as Char -> c"a" // character
'abc' -> s"abc" // String
'''abc''' -> cm"abc" // character, multiline
"abc" -> "abc" or i"abc" // interpolated
"""abc""" -> m"abc" // multiline
/abc/ -> r"abc" // regular
`abc` -> l"abc" // literal
// trimmed
"""
abc
""".trim()
->
t"
abc
"
// undent
undent"""
abc
def
""")
->
u"""
abc
def
"""
For more complex cases maybe use an annotation-like syntax:
// "\n" appears as the char sequence {\,n} in the resulting string
// strings given as arguments to @S(...) are always literal
final GString
multilineRegularexpressionInterpolatedWithSpecificCharsInterpretedLiteral
= @S("ri",["\n"])"age:(\d+)phone:${telephoneNumberRegex}\n\n\n"
Cheers,
mg