Model2Model - 1 node should result in 2 generated nodes

Hi forum,

i wrote a top-level forms UI language with which i generate code for another language i wrote. So i m really doing a model2model transformation. However i have a serious problem with the $LOOP$. The $LOOP$ get s a list of nodes as input and executes it s body then.

But what, if i have concept "label" as input of a $LOOP$ and should generate TWO concepts "table.column" for each input node. E.g. on the attached picuter, i highlighted two nodes.

MPSLoopProblem.png


It would be perfect, if i could put a $LOOP$ over both nodes. But that s not possible. Did i miss something?

Of course it is not possible to use two LOOP´s, i.e. over each node one, because the generated nodes are alternating ...

is that a general model2model problem?

Best,
Dan
6 comments
Comment actions Permalink
Loop's functionality is not good for your requirement.

Use the COPYSRCL to copy a list of nodes from your input model to this place.

Then use a reduction rule to reduce each node to e.g. 2 output-nodes.

If you have further questions feel free to ask.
0
Comment actions Permalink
Hi Michael,

thanks for your support. However, problem stays the same when following your approach. You will get (the same) a problem with the Template-Fragment macro. You can not put a Template Fragement macro over to nodes - like in the picture above.

One solution for the $LOOP$ (or <TF) problem is to generate a list double as long as the original list (in the $LOOP$ inspector) and work with an if/else inside the loop. But i don´t like the solution...

No better one?

Dan
0
Comment actions Permalink
Hi!

This is a current limitation of MPS templates. I'll try to explain the problem: any generator macros ($LOOP$/ $COPY_..) are represented in editor as "blocks" wrapping some syntactical constructions. In the same time in model those macros are stored as a child elements of the element they are wrapping. It's clear that it's not possible to create common (single) child element for two different target language constructions... So, you have to use two $LOOP$ macros there.

In BaseLanguage we are using BlockStatement for such situations - you can create single macro "around" block statement and then put couple of elements inside this block statement.
0
Comment actions Permalink
Hi Dani,

not sure if it helps,
but you can have several Template Fragments as long as they are in the same parent node.

I do this all the time.
0
Comment actions Permalink
Hi Michael,

indeed - good answer. I did not know that one can use more than one Template Fragment in the same parent node. This is at least one alternative solution to mine.

But then generally speaking - it should be also possible to clamp more than one node with a $LOOP$ statement ... i stumbled more than once over the $LOOP$ restriction - it would be a great generator improvement

Dan
0
Comment actions Permalink
for those still looking for an answer , like i was quite sometime back:

the way is via 2 generator configs and setting priorities among them and you could weave/go the script way to pre-process or post-process based on priorities.However both nodes will certainly end up in the same model
0

Please sign in to leave a comment.