Model to model transformation (How to do it?)

Hello,

I would like to do some model-to-model transforms using JetBrains MPS, but can't find how to transform a language LangA into a language LangB.

For example, let's say I have two simple languages:

  • LangA with a root concept RootA, which has an integer attribute Foo
  • LangB with a root concept RootB, which has a string attribute Bar

I would like to transform models for the language LangA into models for the language LangB, mapping the RootA nodes to RootB nodes, where the Bar attribute will be the .ToString() of the Foo attribute.

The idea is to transform LangA into LangB and then LangB into text (using the TextGen aspect).

How could I create such a transformation? I can only see the TextGen aspect, to transform LangA directly into text, and the Generator aspect, to transform LangA into the BaseLanguage, but nothing that would allow me to transform LangA into LangB.

Thank you.
2 comments
The Generator in LangA allows you to transform into any language, including LangB. You need to specify LangB as a used language in the LangA's generator module and model, so you could define templates holding LangB's concepts. Then you create a root template that maps RootA to RootB.

We've got a tutorial for code generation at https://confluence.jetbrains.com/display/MPSD31/Generator+Demos
You can learn about how to set dependencies at https://confluence.jetbrains.com/display/MPSD32/Getting+the+dependencies+right

Vaclav
0
Thank you Vaclav, my mistake was to add LangB as a used language on the generator/<no name> aspect only, not on the main@generator, hence it wasn't available.
0

Please sign in to leave a comment.