hierarchical concept: where to start

I am trying to experiment with a simple hierarchical concept: "Tag" with children "Tag"[0..n] ...

 I guess I am not the first, but I have not been very successful at googling this topic.

 Could you point me to some non-obsolete resource? (doc, example, video ...)?

I would be particularly interested in importing/exporting textual representations either as a hierarchy:
  • a
    • a1
    • a2
  • b
    • b1
      • b11

or flattened

  • a , a1
  • a , a2
  • b , b1 , b11


(Maybe there could be a topic for beginners?)



I thought I was going somewhere but this:

append $list{node.ancestors<concept = Tag, +>.select({~it => it.name; }) with ,} ;

is producing:

".../textGen/Tag_TextGen.java : Type mismatch: cannot convert from ISequence<String> to Iterable<SNode> (line: 22)"

But checking the Language or Model gives no error!?  I am using  3.4 EAP / Build #MPS-162.357, built on July 7, 2016 / JRE: 1.8.0_101-b14 amd64

Note that the following is working:

append ${node.ancestors<concept = Tag, +>.reverse.select({~it => it.name; }).join(":")} ;

Any idea?  (There could be a topic "Is it a bug?")


Hey Bruno! It was very difficult for me to follow your text. I guess you just want to generate a textual representation of your bookmark language. Subsequently, you should just make a text gen component for each of your concept.

A simple language:

Root with [0..n] childs

textgen for Root

(context, buffer, node)->void{ 

textgen for Child

(context, buffer, node)->void{ 


Regards msch95


Alternatively, you can use com.dslfoundry.plaintextgen plugin (you can find it in File --> Settings --> Plugins --> Browse Repositories).

We've just created an example for you here: https://github.com/DSLFoundry/mps-plaintextgen

Please open the model Examples/NestedList/MyList. If you right click on the MyList root node and click "Preview Generated Text", you will get both examples that you need.

To incorporate a plaintextgen template in your project, go to generator/main of your language and add a root mapping rule. Then press ctrl+L to import the plaintextgen language:

Then, in the consequence of the rule, press Alt+enter and select "New Root Template":

And select a TextgenText concept to be substituted:

Then specify the text generator as you can see in our example (see link above).

Hope that this will provide a bit of easier text generation experience.

By the way, you can just paste in an example text into a plaintextgen element by right clicking and selecting "Paste Unstructured Text":



@Eugen nice plugin
I just had a quick glance at the plugin. Some question appeared to me as this can be useful for me and others too.

Are there all macros supported like in the xml generation language?

Are there some limitations in contrast to the build-in generation aspect?

Thanks & regards



Hi all, 

Thanks for your answers. I figured out the basic stuff already. I was more looking for inspirational examples around JSON, hierarchical data, import/export.  

For example some are advocating to use generator instead of textGen, because it would be very similar to the editor. Hence import and export would be closer.

On another level, what is the best practice to import data? What if I want to use a CSV file? Copy/paste in the editor?

All kind of questions ... but I am going forward step by step ...

I will test the plugin right now



Take a look:



Basically you just import data by adding a custom plugin and create new MPS nodes<concept>. Also there's the possibility of creating a custom persistence https://confluence.jetbrains.com/display/MPSD30/Custom+Persistence+Cookbook

I recommend the copy&paste approach if the CSV isn't that large.




@msch95 thanks! I'll pass it on to my co-developers Remi Bosman and Klemens Schindler.

To answer your question:

* Are all macros supported?

  --> Yes, all standard generator-macros can be used, because all the plaintextgen concepts are just normal MPS concepts.

* Are there limitations?

  --> We actually developed the plaintextgen, because we found the textgen aspect too limiting. For example, you cannot place it in the normal generator priority sequence. Further, we found it more easy to teach people to do text generation using a more declarative language that looks a bit like editors (i.e. VerticalCollection (editor) == VerticalLines (plaintextgen), IndentCollection == IndentedText, HorizontalCollection == Line), so the effort of learning new stuff is reduced.

We considered 2 main use cases for plaintextgen (which we've typically encountered):

 * Make a plain text generator from scratch (specify it in a way that feels similar to an editor)

 * Copy paste a "reference-implementation", including indent analysis, and then use macros to "templateize" it from a model

If you will use it and you find any other use cases (or limitations you run into), feel free to let us know (e.g. drop a issue in the github).



Thanks for your elaboration. The thing is that the generator is much more maintainable and readable in my opinion.


@Bruno: if you want an example on how to import data, you can see the "Paste Unstructured Text" intention in the intentions aspect of the com.dslfoundry.plaintextgen language source code (same repository).

Typically, the way I choose to import text is indeed as @msch95 says:

* If it's really small, just "copy paste" it by hand

* If it's bigger or I want it to be repeatable, I build an importer (see example) that can be called either by an action in MPS or by an intention (alt+enter).

Custom persistence I would only recommend if you want to use your format (CSV or XML or whatever) outside of MPS to interop with other applications.


Thanks a lot,

The plaintextgen is interesting and allowed me to go forward: https://github.com/BrunoVernay/bookmark-mps/tree/mps33

I would say that the most annoying stuff using MPS are these tables:editing them to achieve even a simple presentation is incredibly difficult.  (Seemed easy on the video ...)  I really need to find documentation on this subject.

Now I will try to look at the custom persistence and hope for improvement in the 3.4 release


@Bruno: could you send me a link to the video that you mean? And could you elaborate on what you find annoying? I'm wondering what aspect you find difficult: the fact that macros are used in the reduction (like in normal model to model reductions in MPS) or the way plaintextgen editors are rendered?


I cannot recall which particular video (Either MPS or Marcus Volter). But my point is purely on the table: how cells, rows and columns appears and disappears when you type "enter" or "Del". This is the part that annoyed me, because I could not figure out how to make this table look the way I wanted and what the "-/< were supposed to do.  

Admittedly, I should have stopped and search for the proper documentation instead of typing randomly. 

I will search the doc and update this post, when I find it.


There are getting started resources: https://www.jetbrains.com/mps/documentation/

A good book that gives you an introduction and overview exists as well, they have been written by Fabien Campagne: https://books.google.com/books?id=nvcEAwAAQBAJ&printsec=frontcover&dq=jetbrains+mps&hl=en&sa=X&ved=0ahUKEwje2-_skL7OAhViJsAKHQGKAuYQ6AEIJjAB

The most important thing you need to understand about MPS in order to not get surprised by things is that it is a projectional editor. You are, in fact, editing an Abstract Syntax Tree directly. So when you press enter and a column appears, then a sibling node has been created in the tree and in this table view you can see this as an extra column that has appeared.

What has helped me is to reason about it in terms of model-view-controller. Your model is an abstract syntax tree and it gets rendered into the view/controller in the form of editors. This gives you the flexibility to use multiple notations for the same model (textual, table, mathematical, graphical). There are two nice books from Markus Völter on these topics. The DSLBook and his doctoral thesis Generic Tools, Specific Languages (see http://voelter.de/books/).


In addition, the editor cookbook will help you out. It covers many common problems.



Please sign in to leave a comment.