Writing an importer: The basics

NOTE: Due to an error, only a single paragraph was sent by e-mail from the first post in this series. I apologize for any inconvenience caused and hope it will work better this time. Continuing from our last post, let’s have a brief look at the data and the language we are going to work with and set things up. Remember, the code is available on GitHub. The language I have created a very small language for this tutorial, called game....

Writing an importer: Introduction

What do you do if you have some data that you want to import into MPS? There is no built-in importer in MPS, nor is there a ready-to-use framework, so it can be overwhelming for a beginning MPS language developer to piece together all the required knowledge of MPS subsystems. That’s why I want to start a series of beginner-level posts to cover the process of writing an importer. I will assume you have experience programming in Java but are just starting with MPS....

Why is my editor so slow?

A client has asked me recently to look into why one of their editors was performing slowly. The editor was using a table to display a large imported data structure. The initial rendering of the table took around 6 seconds on my notebook, and typing a character caused the editor to pause for another 6 seconds, which was unacceptable. Considering that the actual language users would be using a VM as is often the case in big companies, the delay there could be even longer....

Language design patterns: Inline definitions

Language users will often want to write certain definitions that are later reused elsewhere in their models. For example, a user might define an entity, listing its attributes and references to other entities, or a UI component, such as an address form or a search form. Many of these definitions are best written separately from their usages. You first define an entity and then have other entities link to it. Or you create a form first and then refer to it from some action code....

Debugging in MPS

What do you do when your MPS language compiles and builds with no errors but behaves unexpectedly? Menu items you want to see don’t show up, the type system shows a strange error that comes from nowhere, or the generator produces unexpected output. In a “classic” development situation, this would be the point where you would start your program under a debugger or add some print or log statements. But how do you debug your MPS language?...

Logging in MPS

MPS offers several logging mechanisms suitable for different use cases and different users. Logging to the Messages tool window You can have your messages appear in the Messages tool window, looking like this: Logging to Messages tool window To log a message: Import the jetbrains.mps.baseLanguage.logging language into your model using Import Language action (Ctrl+L/Cmd+L). Add message statements (message error, message info, etc.) to your code. Provide the current project if possible....

MPS Office Hours

As mentioned on Twitter, I would like to offer MPS Office Hours to the community. This will be a recurring one-hour meeting via Zoom where we talk about MPS and I offer my help with your MPS problems. You can either describe your problem in words, you can do a screen share, or I can do a screen share. If you are interested, I have prepared a form below where you can sign up to get notified about the whereabouts of the future meetings....

Debugging MPS Remotely Using IntelliJ IDEA

When MPS behaves unexpectedly and simple attempts to pinpoint the cause fail, it may become necessary to go deep and unleash the power of a full-blown debugger on the generated code. MPS being a Java application, it is possible to debug it remotely. The configuration involved is non-trivial, however, and this article will show you how to set up remote debugging step-by-step using IntelliJ IDEA Community Edition. Note that the term remote debugging doesn’t necessarily mean debugging from another computer....

Making intentions visible

Intentions are a signature feature of the entire family of JetBrains IDEs, including MPS. An intention is defined in the eponymous language aspect. In order for an intention to be visible, the user has to import the language into their model. If you want to add an intention to an existing language (for example, adding a great new refactoring to base language, to be invoked via an intention), you could define a new language extending the original language and add the intention there....

Running MPS code from command line

You can execute MPS code not only from within MPS but also from command line. This can come useful for batch processing or when exporting models from MPS. There are two options for running code from command line: Using an MPS-provided Ant task. Writing custom code using MPS libraries. Using MPS-provided Ant task This approach is documented in the JetBrains MPS Help. It’s quite simple to set up so you can be up and running quickly....