Skip to content

TextGen Aspect¶ ⧉

The TextGen language aspect defines a model-to-text transformation.

MPS documentation

How do you get the TextGen for a node?

Use the classTextGeneratorEngine ⧉. It only works for root nodes such as ClassConcept ⧉ and returns null when no text output exists.

Can you also generate the text from the generator aspect?

Use the language com.dslfoundry.plaintextgen from MPS Extensions ⧉.

Can I implement text generation for another language?

I want to implement text generation for language A in a separate language B. I need different text generation for some of the KernelF concepts. When I try to do this, I get a compile error because it looks like the generated descriptor does not include "inherited" concepts:

public TextGenDescriptor getDescriptor(@NotNull SAbstractConcept concept) {
    switch (myIndex.index(concept)) {
        case LanguageConceptSwitch.Component:
            return new Component_TextGen();
        case LanguageConceptSwitch.Contract:
            return new Contract_TextGen();
        case LanguageConceptSwitch.EmptyContent:
            return new EmptyContent_TextGen();
        case LanguageConceptSwitch.Library:
            return new Library_TextGen();
       case LanguageConceptSwitch.Port:
            return new Port_TextGen();

Is it not possible to "override the textgen" this way?

asked by: @markusvoelter

It's not possible this way. So far, the two ways I have found to make this happen are:

  1. Extend the original language (A.ex) and create subconcepts of all the concepts you need to specialize the textgen. You will then need to do M2M transformation to replace the extended concepts. You can do this generically by using a script. The generator that searches for all nodes of concepts that are extended in A.ex and replaces them by using the RefactoringRuntime.replaceWithNewConcept method.

  2. Create annotations that override the text generation of the concepts and attach them in a generator. TThen MPS will first call the annotation's text gen, and you can override it there.

There is MPS-22092 ⧉ which describes this request.

answered by: @coolya

Which built-in languages do not use the generator but only text generation?

  • jetbrains.mps.baseLanguage.javadoc
  • jetbrains.mps.core.xml