Generator

What can be generated?

Have a look at the language repostory. You might also find other languages on Github. In general there doesn't have to be an existing language. Any text can be generated with TextGen or Plaintextgen from mps-extensions. It's also possible to generate code from an action or pre/post-processing script in the generator by using an existing Java library such as Apache Poi. A tutorial for example for excel can be found here.

I want to create multi outputs for my language.1

Use a dummy concept or generation plan with fork. Also answered in documentation.

Can I invoke the generator from an external tool?2

Yes, it can be run from Ant.

The import x cannot be resolved.3

The solution that contains the class has to be added as a runtime solution (see here)

I want to copy the output to another location.

Use the @CopyOutcome annotation.

I want to generate latex files.

The mbeddr documentation language can do this. Have a look at the documentation.

I don't want to generate code.

You can interpret your models instead. Use mbeddr.mpsutil.interpreter from the mbeddr plattform.

I want to generate text.

Use the textgen aspect or use mps-plaintextgen from mps-extensions.

I need a temporary model.

Use the class TemporaryModels.

I want to call preview generated text programmatically.

Use the MPS action TextPreviewModel or call the methods in TextGeneratorEngine if you want to use textgen.

Why are my root nodes generated multiple times?

Have you used one of your root nodes as a child of another node? It will still act as a root node in this case.

Should I use generation plans or generator priorities?

Have a look at the motivation for generation plans in the official documentation. Generation plans should be used when the generation order is simple.

I need to get the output path for a solution.

  • To get an IFile call SModelOperations.getOutputLocation(model).
  • To get an string call ProjectPathUtil.getGeneratorOutputPath(module.getModuleDescriptor()). You have to first cast the module to an AbstractModule.

no output location for X.

Make sure that the Java facet is enabled in the properties of the language or solution. This error can often be seen when opening an old MPS project.

Which variable names can't be used because of hidden variables in the generator?

Underlined variables are special variables that are available.

  • Console: ConsoleContext context, ConsoleStream console
  • Constraint:
    • Scope: ReferenceConstraintsContext _context
  • Typesystem:
    • all rules: IsApplicable2Status status, TypeCheckingContext typeCheckingContext
    • comparison rule: SNode node1, SNode node2,
    • inequation replacement rule
      • custom condition: SNode subtype, SNode supertype,
      • rule: SNode subtype, SNode supertype, EquationInfo equationInfo, TypeCheckingContext typeCheckingContext, boolean inequalityIsWeak, boolean inequalityIsLessThan
    • substitute type rule: SNode originalType
  • Generator:
    • mapping configuration: CreateRootRuleContext _context
  • Editor:
    • General: SNode myNode

How do I debug generators?

Specific Languages Blog — Debugging generators

How does MPS collect generators to engage on a model?

Specific Languages Blog — How MPS collects generators to engage on a model

How do I generate language X from MPS?

Specific Languages Blog — How do I generate language X from MPS?


Last update: May 5, 2022

Comments

Back to top