I'm thinking of using Scala for an internal DSL (ie, the DSL is really Scala) for musical composition. I'd want to use identifiers with characters like the sharp sign, ♯ (U+266F). Looks like this is not possible:
val c♯0 = 13
does not parse. The closest I can get is:
val c0_♯ = 13
I don't like it. What's the rationale for forcing identifiers to be named like this?
Scala's grammar tries to cater to a lot of conflicting requirements. In order to make optional any white-space between "operator-like" method names (such as +
, /
or ::
) and their arguments on either side, it's necessary to have a way of signifying that a given name contains a mixture of punctuation and alphanumeric characters.
Keep in mind that internal DSLs are not new languages! They're at best illusions of being new languages. They are still Scala.
If you want complete freedom to control the language you provide to your users, you can write a combinator parser or use an external parser generator.
For anyone involved in language processing in Scala, I highly recommend you check out Kiama before rolling your own narrowly focused, single-purpose language processing code. Kiama is a gem!