I’ve been writing Groovy recently. Groovy has a shockingly flexible string syntax, as I discovered when trying to improve the Emacs mode.
Groovy tries really hard to make you happy. It provides normal strings:
and since it’s a recent scripting language, it provides string interpolation too!
Groovy doesn’t stop there, however. Oh no.
The string interpolation is very flexible. You can access object attributes, or even write arbitrary Groovy expressions.
Naturally, you might not always want interpolation. Groovy provides an escaping mechanism, and an additional syntax for this:
You want multiline strings? Groovy has those too, in both interpolated and raw flavours:
These are useful, but sometimes you want to start a line with
"""
. Groovy lets you escape that:
Other scripting languages also support a /foo/
syntax. Groovy users
might want this as well, so of course they’re available:
For the brave of heart, you can interpolate into your regular expressions:
Groovy doesn’t even stop here. What if you have a string with many embedded single-quotes and double-quotes? The interpolated, multiline, dollar-slashy-string is available!
The dollar-slashy-string is so awkward to highlight that even the official docs don’t try to highlight it!
To stake its claim as an incredibly versatile syntax, Groovy strings have one last trick up their sleeves. Strings can be lazily evaluated!
Needless to say, only a total madman would try to write a syntax highlighter for this:
Groovy is a really neat language that is excellent for glue code. I’ve had a whole lot of fun making it work in Emacs.