Why is Scala separate characters and letters in identifiers and can I change that?

I am thinking of using Scala for internal DSL (i.e. DSL is really Scala) for musical composition. I would like to use identifiers with characters such as the sharp sign, ♯ (U + 266F). It looks like this is not possible:

val c♯0 = 13

      

not analyzed. The closest I can get is:

val c0_♯ = 13

      

I do not like this. What rationale for forcing IDs should be called that?

+3


source to share


1 answer


Scala grammar tries to satisfy many conflicting requirements. To make optional any empty space between operator-like method names (such as +

, /

or ::

) and their arguments on either side, you need to have a way to mean that the given name contains a mixture of punctuation and alphanumeric characters.

Be aware that internal DSLs are not new languages! They represent, at best, the illusion of new languages. They are still Scala.



If you want complete freedom to control the language you give your users, you can write a combinator parser or use an external parser.

For anyone doing language processing in Scala, I highly recommend you check out Kiama before translating your highly focused, single-purpose language processing code, Kiama is a gem!

+5


source







All Articles