There are several resources on the web that are instructive in writing Scala compiler plugins that match a template with code, but they do not help generate code (building symbol trees). Where should I start figuring out how to do this? (If there is an easier way than manually creating symbol trees, I would be interested as well.)
For example, I would like to write a plugin that replaces some code with a simple AST for this expression, where the variables (extracted from the source code) can be of any type:
"" + hello + ", " + world + "!"
I understand that this can be tricky due to boxing and toString , for example. if hello were an object and world were int, it really should be something like:
"".+(hello.toString().+(", ".+(new Integer(world).toString().+("!"))))
compiler-construction scala plugins code-generation
Yang
source share