I would like to have some clarity on custom string interpolation in Scala. I am looking at the example from this page -> https://www.scala-lang.org/api/2.12.6/scala/StringContext.html
If I understand correctly, the compiler interprets any string preceded by any literal (without space) differently. E.g: s"abc"
This seems to be translated to an instantiation of the case class - StringContext by compiler. This case class takes >=1 strings as arguments.
When we have literals preceded by other than s, f or raw, that becomes a custom interpolator and we need to have a function for implicit conversion.
In the example given in the above link, the implicit class JsonHelper - takes a StringContext value.
In the call: val x: JSONObject = json"{ a: $a }"
, I am not getting how { a: $a }
is made into a StringContext and how it is used in the function definition.
Can someone please help me.
Thanks!