It can't be done with the Scala compiler as-is, but maybe it would be possible with a compiler plugin that changed the way identifiers were parsed (perhaps if the back-tick's function was somehow replaced with some obscure unicode character).
In the Scala SLS 1.1, there is the lexical syntax for identifiers:
op ::= opchar {opchar}
varid ::= lower idrest
boundvarid ::= varid
| ‘`’ varid ‘`’
plainid ::= upper idrest
| varid
| op
id ::= plainid
| ‘`’ { charNoBackQuoteOrNewline | UnicodeEscape | charEscapeSeq } ‘`’
idrest ::= {letter | digit} [‘_’ op]
The problem is, the only rule that allows any character other than letters, digits, or _
is the one that requires the identifier be quoted with back-ticks:
‘`’ { charNoBackQuoteOrNewline | UnicodeEscape | charEscapeSeq } ‘`’
However, it explicitly doesn't allow back-ticks with charNoBackQuoteOrNewline
, and in case you think you can work around it with UnicodeEscape
, that doesn't work either:
scala> val `hello \u0060world` = "hello world"
<console>:1: error: unclosed quoted identifier
val `hello \u0060world` = "hello world"
^