What are good tutorials on making multi-target code generation in MPS?
I want to have the ability to translate not only into corporate Java but also for Python/Django, and Erlang/Elixir stacks.
At least for Java, there are three targets: corporate/desktop stack, Web (intranet), and Android. So, when I compile, it requires to have some switch to point what type of code I want to use (mostly external dependencies and library bindings).
As far as I remember, you can only have one generator per language. So, if you want to have multiple targets, you need multiple languages extending a common one, e.g. YourLang/JavaDesktop, YourLang/Android, YourLang/JavaWeb and so on.
I think they have introduced generation plans that could allow this.
Also, you may have different ways to generate stuff. Sure, there is the “standard” generation mechanism, that happen when you build your models, but nothing prevents you from adding a “generate X” button somewhere (in the main menu, in a contextual menu, in an editor) and do arbitrarily stuff when it is pressed, like navigating your model and generate stuff on a file. I personally have done that in a few projects. This makes a lot of sense if your generation is heavy and you want it to be started only when you decide to, and not every time you build your code. Or maybe because you may want to trigger some side effects, like pushing some code and add a git tag somewhere. With these mechanism you may have 10 buttons for 10 different targets.
Assume we have language
MyLang and want to generate it to Java, text, and XML.
Have a second language
MyLang.gen.base, that just contains a
Config root concept, and concept interface
0..* of them.
Each generator resides in its own language, i.e.
MyLang.gen.xml. These languages contain only the generator, and a concept
The user has to add a
Config instance, and add all the generators they need.
In a generation plan, I fork the model for each generator. Each generator discards everything if it has not been selected by the user.