How to realize this?

I define two languages(A and B) in a project,both of which can generate a Java class(CA and CB,both of them are macro).Can I define an instance of CA in CB in order to use the methods or fields in CA? If can,what to do?

3 comments
Comment actions Permalink

Do you mean you need to use instances of CA/CB in the generator templates?

0
Comment actions Permalink

If you want to reference some generated part from other part firtst you have to create reference macro. To create a reference macro to a method enter some method press controlshiftM. You will have something like this (see screenshot 1). To reference a generated method you have to find it in a some way.

In MPS every template has source node, the node that it is generated from. But usually from one node we generated more than one node so we have to distinguish them. To do so we can mark it with difference strings. To do so you have to create a node macro and set the name for it in inspector(see screenshot 2).

After that we can create a query method for a reference macro and write something like that in it:

return generator.findNodeBuilderForSource(sourceNode, "name").getTargetNode();

Also we have a generator tutorial http://www.sergeydmitriev.com/mps/doc/generator.html

If you want to find more examples of usage of these things you can look at jetbrains.bootstrap.editorLanguage and jetbrains.bootstrap.structureLanguage generators



Attachment(s):
screenshot-1.png
screenshot-2.png
0

Please sign in to leave a comment.