Transformation Macros and Generation to TLBase

Hi All,

I created generator from language A to jetbrains.mps.transformation.TLBase. I create template fragments for concepts from A, and now I need to insert transformation macros (copy, loop etc.) into the template fragment so that it could appear in the generated fragment.

The problem is that I can add it by pressing CtrlM+ but it will be evaluated during transformation, but I need that macro to appear in the generated template fragment.

How can I solve this problem ?

Thanks.

8 comments
Comment actions Permalink

It's now impossible to generate to TLBase at least with our generators framework. Why do you need to generate templates? Could you please describe what are you doing?

0
Comment actions Permalink

I created my own "structureLanguage_my". It contains only one concept "ConceptDeclaration_" which inherites from jetbrains.mps.structureLanguage.ConceptDeclaration.

Then I created generator "structureLanguage_my->TLBase" to automatically create template fragments for concepts from some language.

Template fragments (using jetbrains.mps.xml) are something like following:

*

        ... // link1 structure            ... // link2 structure            ... // link3 structure      ...

*

So, these fragments represent language concepts in the xml language.

I've already made generator which creates template fragments for concepts and property attributes with PropertyMacros but now I don't know how to define query functions of these PropertyMacros - I create them "on the fly" by calling sourceModel.new node(PropertyMacro, <no prototype>).

That's another problem I met.

Hope for your patience :-)

P.S. Of course, defining mapping rule "ConceptDeclaration_" -> "ConceptDeclarationTemplateFragment" required small hack - I just edited generator file manually :-)

0
Comment actions Permalink

I was wrong. It was possible to implement it with $COPY_SRC macro but in this case you have to do all the job with your hands: $COPY_SCR's query should return a created node.

0
Comment actions Permalink

To understand what you should do to create a query, look to the declaration of macro's concept. You can do this by pressing controlaltshiftS having selected an instance of a concept. To find out- what are the children of some property macro you can use project pane: select a node and press altF1 (show in project).

0
Comment actions Permalink

Well, now I've got another problem.

When I create PropertyMacro instance and add it as a property attribute to some node, of course, type of sourceNode isn't automatically set and when I edit macro's value function it has no type.

I just need to know how to setup argument type manually for sourceNode in PropertyMacro value functions ?

Thank you.

0
Comment actions Permalink

It's not an argument. It's an instance of special concept derived from ConceptFunctionParameter concept. You can find out which arguments which concept function has by looking at concept properties and links in ConceptFunction declaration.

0
Comment actions Permalink

Well I've found another way. Now I use mapping to PropertyMacro, NodeMacro, ...

I have one more question. Now it is about NodeBuilders. How can I map just created node using generator ?

I do following:

*void func(SModel srcModel, ITemplateGenerator generator)

{

  snode newNode = srcModel . new node( SomeConceptFromSourceLanguage );

  INodeBuilder nodeBuilder = generator.findNodeBuilderForSource(newNode, "mappingRuleName");

  

  • // but nodeBuilder is always null here

  • snode<SomeConceptFromTargetLanguage> targetNode = ( snode<SomeConceptFromTargetLanguage> )generator.getTargetNode();

  ...

}*

What should I do to map one node to another using mapping rule?

0
Comment actions Permalink

You usage is incorrect. You can find node builder only for a node in a source model, and nodes which created after the generation don't have corresponding node builders. If you want to insert a custom node in a model, I recommend using $COPY_SRC macro instead of this stuff.

0

Please sign in to leave a comment.