mps generating 2 xml elements for one node

Hello, 

I'm new to mps and i'm struggeling a bit with the generator. For a project for my university and company i want to create a language which creates xml GUI files.

so first a little bit about the structure:
- the root concept 'ProtokollPart' can have several 'Component' concepts (not rootable, abstract)

- the 'Frage' Concept extends the abstract concept 'Component'

- depending on a boolean ('buchstabenNum') in 'ProtokollPart' the concept 'frage' should be generating one (if false) or two (if true) label.


My first problem is that a templat can generate only one xml-element, but i need two
the second problem is, that i don't know how to get the boolean from the parent. (Only 'ProtokollPart' can be the parent of 'Frage')

here are some pictures from my current code:
this is the file which should generate the 'ProtokollPart'

 

I'm thankful for any help and suggestions :)

6 comments
Comment actions Permalink

A template can generate two things, you can have two template fragments (<TF...TF>) in your reduce_FrageBuchstabeNum template but you need to put them into a context, in this case another XML node. So it would look something like this:

<context>
  <TF <component id="..."> TF>
  </component>
  <TF <component id="..."> TF>
  </component>
</context>

The <context> part is completely ignored, it is there just to have some place where to put the multiple nodes.

In your case the second TF would probably contain an $IF$ macro. To use the property value from the parent, use node.parent:ProtokolPart.buchstabenNum. The ':ProtokolPart' is a node cast.

1
Comment actions Permalink

hello, thank you so much again, i worked right away. now i think i will be able to finish my project. :) 

I already bought a book about mps ('the MPS Language Workbench') but it doesn't explain everything and the online documentation does neither. 
maybe you have some literature you can recommend?

1
Comment actions Permalink

I used that book myself to get into MPS when I was just starting :) Unfortunately there aren't any other books to recommend. JetBrains has some tutorial videos available. And there's now https://heavymeta.tv where Kolja Dummann has published videos of creating a new language from scratch, including writing a generator. I publish some tips on my website (https://specificlanguages.com) occasionally as well, but nothing generator-related yet.

0
Comment actions Permalink

thank your for the recommendations. I will take a look a these.

0
Comment actions Permalink

so now i just realized, that i have another question, i hope that can be answered too.
i want to have a variable thats available for all components of the copy_scrl in the first picture and also for the elements that are children of the components there. also i must be able to change it after a component used it. it should be a counter for the rows and each new element should be in a new row.
i couln't really find out how exactly the var macro works and if that would be the right thing to use or how i could do it.

0
Comment actions Permalink

VAR macro works if you define a variable and use it in the same template. It saves you from typing the same expression over and over and of course helps with performance. But you cannot change the value of the variable.

I'd consider using a session/step/transient object first, see the corresponding section in the MPS Generator Language documentation. Or maybe use a $MAP_SRC$ macro with a postprocessing function that sets the row number based on outputNode.index.

0

Please sign in to leave a comment.