MPS generation: Generate Root node children as root nodes (flatten)

Hello.

I'm trying to describe a generation for models that can have root nodes of concepts “Element” and “Container” in the same model at the same time. On generation time I have generation mapping for “Element” and it works fine (transform Element to GeneratedElement). But also I need to define generation in the way that “Container” should be treated as a set of “Element”s. So, for generator it should look like I generate a model where Elements just roots in model, not a part of Container. Can I do make it in a “native” (proper) way? I can “populate” them with pre-processing scripts, but because nodes can't be part of several models (I can't just put them from origin model to input model) I need to create copy. It let to some strange behavior in some places (for example, origin node of generated node the generated node itself inside the gen context).

How can I do it? I saw https://mps-support.jetbrains.com/hc/en-us/community/posts/205828549-Creating-new-root-nodes-from-generator-pre-processing-script but I can't find a detailed explanation how can I do it. I've tried to use reduction rules, but it leads to generation cycle problems.

I believe that I can add some util classes to store some additional information like which nodes were copied, from which models, which nodes were generated out of it. But I think that there should be more MPS way to do so.

Thank you.

0

Please sign in to leave a comment.