How MPS Collects Generators to Engage on a Model

A diagram, based on the official documentation of The Generator Algorithm, showing how MPS collects the generators it will use to generate a model (engaged generators). ...

Adding Model Imports and Used Languages Programmatically

The SModel interface (org.jetbrains.mps.openapi.model.SModel) contains methods for querying and modifying nodes contained in a model but methods to modify the dependencies of a model (model imports or used languages) are absent. There’s another interface called jetbrains.mps.smodel.SModelInternal that has these methods but is there any way to modify the dependency information without resorting to internal APIs? It turns out there is an undocumented but public class named ModelImports (jetbrains.mps.smodel.ModelImports, MPS link) which is intended as a public facade to the dependency information....

Prefer Composition over Inheritance

There is a principle in object-oriented design to prefer composition over inheritance. This applies also to modeling in MPS. Example Problem Let’s say that as part of your language you need to describe an input for a certain transformation. The input has a name and can come from two sources: a named file or standard input (stdin). Inheritance-Based Solution Here is how you could model this requirement. First, let’s create a base concept for inputs:...

Build Script Error: Cannot Find Used Language in Dependencies

The Problem To define editors for your language you used plugins from MPS-extensions or mbeddr platform, such as grammar cells, tables, or diagram editors. Now you want to distribute your language to your users as a plugin. You have created a build script and it looks correct, MPS also tells you there are no errors in it. However, when you try to generate the Ant build file from it, you get the following error message:...

Debugging Generators

Sometimes your MPS generator doesn’t generate what you expect. For these cases MPS has tools to help you pinpoint the exact misbehaving rule. The Steps When a generator doesn’t give you the output you expect, here is what you can do: Enable keeping transient models. Rebuild your model. Find the first transient model with the error. In the editor, select the incorrectly generated node. Right-click on the node and choose Language Debug → Show generation traceback in the context menu....

Building MPS Projects Using Maven - A Sample

In case you are trying to figure out how to build MPS projects with Maven, I published a sample project showing how to configure Maven and MPS 2019.2 to work together. Get it on GitHub. ...

Build Script Error: Unsatisfied Dependency

The Problem You want to package your language as a plugin for distribution. You have sorted out the build script dependencies and created an idea plugin in the project structure section of the build script with your languages as the content. Now MPS reports an error for the contents, showing you a long list of “unsatisfied dependencies”: Now when you go and try to add these dependencies to the idea plugin’s dependency section, you find that they are not listed in the completion menu....

Build Script Error: Dependency On A Module Not Visible From Current Build Project

The Problem You have created a language based on mbeddr Platform, MPS Extensions, or KernelF (or all of the above). Now the time has come to create a build script for your language to package it for delivery to the users. However, after creating the build script you get an error message saying Error: dependency on a module not visible from current build project: What Is Going On Here? The solution jetbrains....

The Simplest Way To Use MPS Open API

MPS enables language developers to modify models programmatically via its Open API. The API is quite straightforward and clear. What’s not so clear and where newcomers to MPS often get lost is where to put the code and how to get MPS to execute it. Oh, and how to get the project reference, since this is often the first step to be able to actually write some Open API code....

Create A MPS Concept Declaration Programmatically

MPS offers the API to create concept declarations programmatically. This may come in handy when writing an importer or a converter, for example. However, it may not always be clear what API to use. Here is how you create a concept from code: public class AddConcept { public static node<ConceptDeclaration> addConcept(SRepository repo, model-ptr structureModel, string conceptName) { node<ConceptDeclaration> decl = new initialized node<ConceptDeclaration>(); decl.name = conceptName; node<PropertyDeclaration> prop = decl.propertyDeclaration.add new initialized(<default>); prop....

Want more MPS tips? Leave your e-mail address below and get MPS tips and tricks delivered to your inbox.