Generating two different text outputs from one DSL
Dear MPS hackers.
I developed my own DSL and it went really smooth and was so easy. I also managed to create my own generator, generating text output (via gtext) as input for a visualization tool.
Now I would like to have a second generator, generating different text output for another tool. I tried three different ways of doing so:
Is there another possibility to have two different text outputs generated from my DSL?
Glad to receive any hint. Thanks in advance.
Best,
Arne
I developed my own DSL and it went really smooth and was so easy. I also managed to create my own generator, generating text output (via gtext) as input for a visualization tool.
Now I would like to have a second generator, generating different text output for another tool. I tried three different ways of doing so:
- I tried to create a second generator for my DSL1 which I didn`t manage to do (just doesn`t seem to be available).
- I tried adding the TextGen aspect, but text continues to be generated with the formerly created generator. The TextGen aspect seems to be ignored if a generator is available.
- I tried creating a second project with a second language extending my original DSL. Within this project I created a new generator for the extended DSL. But when generating text for my second DSL, the generator of my original language is used, the new generator seems to be ignored.
Is there another possibility to have two different text outputs generated from my DSL?
Glad to receive any hint. Thanks in advance.
Best,
Arne
Please sign in to leave a comment.
you do not have to create a second generator, just create a second model in your original generator. Your code is then kind of separated into two models - in case you want that.
If you want to create a second artifact (like text) out of a input node (your instances of concept - the model) then do not consume the input node, but leave it in the generation process, i.e. set "keep input root" in the "root mapping rule" configuration in our generator to "true" for the first text output and to "default" in the second.
Dan
I created a second model in my generator, which worked at first, but then the confusion started. I reproduced it with a small toy example (which I attached).
So I have two generator models, each with a root mapping rule and some reductions rules. The root mapping rule works perfect, but the reduction rules get mixed between the two generator models.
In the example, I have just one parent concept and one child concept. Both generators now have a root mapping rule for the parent concept (mapping to gtext gdocument) and for the child concept. One of the generators is generating text in capital letters, the pother one in small letters. As expected I get two documents generated, one from each generator model, but the content of the documents look like this:
Root mapping is fine (for parent), reduction rule (for child) is wrong.
GeneratorTest.tar.gz (37KB)
Do I have to take care in any way that these models don't get mixed?
I appreciate every help/hint. Thank you much in advance.
Cheers,
Arne
you know that there are priorities for generators. "Show mappings partitioning".
I also have two models in a generator with a mapping file in each. Works perfekt for me. But i do not use gtext - i transform to java baselang.
Dan
Thanks for your reply and for the "Show mappings partitioning" hint. I didn`t know that yet. Anyway, when I looked at it, it looked quite fine.
My two generators
Mappings seem to be right for the two generators (as seen in SMP "Show Mappings Partitioning" ):
Generator #1 ("foo"):
Generator #2 ("main"):
I did not find too much information on how to extract the necessary information from this output, though. Do you know id I somehow can find out in this SMP output, why the "foo" generator takes the "reduce_GTChild" (and not "reduce_GTChild2") reduction rule for reducing the child concepts?
Cheers,
Arne
ok. I opened your project. If you click on the solution.sandbox, the following priorities are listed:
--------------------- mappings partitioning
[ 1 ]
jetbrains.mps.gtext.generator.baseLanguage.template.main.mc_rewrite
[ 2 ]
GeneratorTest.generator.template.foo.main2
GeneratorTest.generator.template.main.main
jetbrains.mps.baseLanguage.generator.java.closures.MAPPING_closures
jetbrains.mps.baseLanguage.generator.java.main.mc_baseLanguage
jetbrains.mps.baseLanguage.generator.java.strings.string
jetbrains.mps.baseLanguageInternal.generator.template.main.main
jetbrains.mps.gtext.generator.baseLanguage.template.main.mc_convertToBL
1 roots, 1 components
Strong:
1 roots, 1 components
So this basically means that if you reduce a child, foo.main2 is always first. In your case, maybe you have to work with two generators. Some guys from Jetbrains should suggest a solution?
Sorry,
Dan
Cheers,
Arne
In my language there are three root concepts (let's call it A, B, C), two of them (A, B) can be nested in the third one (C). In my generator I abandon C, which is just a container for A and B and does not contain any further information. With my normal generator, which produces baselanguage everything works fine.
But additional I want to create a textGen output just for A. After setting keep input root to true in my root mapping rule for concept A, the textGen output is generated for nodes of A, when they are root nodes. If they are nested in a C node they are ignored.
If I set keep input root to true in my root mapping rule for concept B, I get empty files for every root node of Type B, even/because there is no textGen entry for concept B.
So the textGen generator seems to be influenced by my generator rules. I didn't expect this behavior and I guess it shouldn't be like this.
Additional I recognized, that something else goes wrong in textGen. For concept A I have got an behavior method which returns a list of referenced nodes of concept B in the current node. In my generator this method works fine, calling it from textGen it just return null. It seems to me that my model is already reduced, when the textGen generator is called. Is it somehow possible to give textGen a higher priority and make sure, that my normal generator gets an unchanged model as input?
To solve my problems I think textGen should
In my language L1 I've got a root node with a statement list. For every statement declared in L1 there is a reduction rule. The last reduction rule is for Statement and its inheritors and abandons the input.
In my second language L2 there are some more statements. These statements should not affect the output of the generator of L1 but in return they should produce some text files using textgen. Therefore I created a new root node with textgen specification where the statement should be copied to. Unfortunately the abandon reduction rule from L1 prevents this copying. If I disable the rule the output of L2's generator is fine but the one of L1 is broken, because there are input nodes in the output model. I don't have a clue how to deal with this.
Is it necessary that the reduction rules of other languages/generators are supplied or is it a bug? Is there any workaround for this issue? I don't have any idea left...