TextGen generate different programming langugages code from one concept

I have a concept (let's call it A) that is being generated into a Ruby class using TextGen. I want to have the possibility to generate the same concept into other languages e.g Python. Could someone describe how to do it or some hint?

0
5 comments

This is answered at the end of the Generator Cookbook: https://www.jetbrains.com/help/mps/generator-cookbook.html#howtogeneratemultiplefilesperrootnode

Basically, don't use TextGen, use the generator for that (where you can use plaintextgen language).

I would create two concepts: GenerateRubyFromA and GeneratePythonFromA. Each would have a reference to, or a copy of, concept A. You can create these concepts in a preprocessing script of the generator mapping configuration. Then I would define, using textgen or plaintextgen, the transformation of GenerateRubyFromA and GeneratePythonFromA to text.

1

Thank you for a quick response. I am new to MPS. I tried to use the plaintextgen language and the pre-processing script aproach. I defined two concepts - GenerateRubyFromA and GeneratePythonFromA. I defined root mapping for them (resulting in plaintext generation). I defined the pre-processing script it looks something like the code below. Additionally the "Generate*" concepts have the concept A (in this case called ApiController) as a children.

 

mapping script FeedApiControllerToGeneralPurposeLang

script kind : pre-process input model
modifies model : true

(genContext, model)->void {
node<GeneratePythonFromApiController> python = new node<GeneratePythonFromApiController>();
node<GenerateRubyFromApiController> ruby = new node<GenerateRubyFromApiController>();

nlist<ApiController> apiControllers = model.nodes(ApiController);
python.apiController = apiControllers.get(0);
}

Unfortunately, it does not work as intended. How should this script look like? Should I prepare separate models for the Generation concepts? 

0

Update: I manage to generate this files using root mapping and following pre-processing script: 

 

mapping script FeedApiControllerToGeneralPurposeLang

script kind : pre-process input model
modifies model : true

(genContext, model)->void {
node<GeneratePythonFromApiController> python = new node<GeneratePythonFromApiController>();
node<GenerateRubyFromApiController> ruby = new node<GenerateRubyFromApiController>();

// nlist<ApiController> apiControllers = model.nodes(ApiController);

// model.add root(python);
model.add root(ruby);
model.add root(python);
}

Is it a good approach? Should I now include there concept A instance via accessing it on the model variable? 

0

can you give me your sample project?

0

Please sign in to leave a comment.