MPS 2019.3 Help

Fast Track to MPS - Ten steps to mastery

Welcome! This tutorial was designed specifically for developers, who are completely new to MPS and prefer a guided tour through the MPS landscape. You will walk the beaten path one step at a time, following clear marks that show you where to go next. The information is structured so that you progress from simpler concepts to the more involved ones and at the end of the journey you'll understand MPS and will be able to use it effectively on your projects.

We admit that there are easier tasks in the world than learning MPS. Language design is a complex domain and projectional editing needs some getting used to. It helps a lot if you have prior experience with DSLs or language workbenches, but it is not necessary for understanding this tutorial. Just expect more bumps on the road. There certainly will be a lot of them - partly also because MPS has its own problems and bugs. So you are in for a tough experience that may take quite a big amount of your time. 

Bear in mind that many have walked through here before and succeeded. If you persist you'll be rewarded - you'll become a language designer who can prepare custom-tailored DSLs, integrate them into projects and develop high-value software with them.

So, take on good shoes, lace them tight and start going ...

Step 1 - Why MPS

Raw time estimate - 50 minutes

Let's start with some motivation for learning MPS.

  1. First of all, check out a two-minute overview video about MPS - Why JetBrains MPS, so you can assess whether this tool offers something that you need on your projects.

  2. Our new VoiceMenu demo application has been created to give people coming from different domains of expertise a quick understanding of the potential of MPS. Watch this short video.

Step 2 - The MPS projectional editor

Raw time estimate - 30 minutes

Before you continue, you should probably get to know the most distinct feature of MPS - the projectional editor. Check out a video that explains all the differences between traditional textual editors and the MPS projectional editor and lists the numerous benefits of this approach.

If you still hesitate, whether to invest more of your time into exploring MPS, you may consider checking out the following materials:

  • JetBrains MPS is an efficient and reliable development tool that has been adopted by software vendors on both commercial and academic projects. MPS-based DSLs have been adopted in wide range of domains, such as legislation modelling, electrical engineering, insurance industry, embedded software, medicine systems, bio-informatics and data analysis. The "How it works" page lists several of the successful projects and gives a high-level overview of the technology used.

  • You may also like to slow down a bit and read a few documents describing how people have succeeded with MPS. We've collected a few case studies that may inspire you to your own ideas on building something great around MPS. 

Step 3 - Install MPS and study the fundamentals

Raw time estimate - 45 minutes

Watch this video, now! - The first run. It gives you the essential information into how MPS is organised, how it works and how users are supposed to interact with it.

  1. If you are carefully evaluating MPS there must be many questions popping up in your head while watching videos or reading stories about MPS usages. I believe that some of these questions have already been answered in the MPS FAQ page. Check it out,

  2. Read a gentle introductory article on MPS fundamentals by Mikhail Barash. This is definitely worth your time at this moment, since you will understand all the principles as soon as you read the article.

  3. Stop for a minute now and skim through a short page listing the essential terms like node, Concept, AST in order to understand better the terminology used down the line.

Step 4 - MPS from the programmer's perspective

Raw time estimate - 45 minutes

Plain reading about MPS will never teach you as much as trying it for real yourself. You might have done this already, but if not, grab MPS from the download site and install it. With MPS installed you will be able to continue on the Fast Track.

Configure the editor

We are all different. If the default settings that MPS comes with do not fit your habits, you can always change them in the Preferences (MacOs, press Cmd + ,) or Settings (Windows, press Control + Shift + Space, or go to the menu File -> Settings). One of the most likely settings to change is the font size in the Editor -> General section:

EditorConfig

Be safe, wear the seatbelts

Knowing keyboard shortcuts turns good developers into great ones. As you learn MPS you will internalize various key combinations that trigger useful MPS functionalities. There's one key combination that you should remember from the very beginning, though - Control/Cmd + Z. Once again - Control/Cmd + Z. It is the Undo action. Whenever you either intentionally or by mistake do something wrong and you want do get back to functional code, turn to Control/Cmd + Z.

A quick ride

Since we programmers like trying things, how about taking the MPS editor for a simple test ride first? You may get the first impressions instantly, if you start MPS and open the Robot Kaja sample project. This project defines an artificial language to command a virtual robot. The robot can move within a rectangular area, drop and collect marks and check the surrounding cells for walls and marks. You write Scripts using the built-in commands as well as new commands that you create on the fly. When you run the script a simulator written in Java is started to visualize the execution of your program.

To open the project, start your fresh MPS, click on the Open Sample Project button and pick robot_Kaja. The sample projects have been installed into your HOME/MPSSamples folder.

                                                                                                                              

Robot open1

The following video has been borrowed from the MPS Introductory Online Training course. This explanatory video will help you start using MPS. Check it out.
If you like the video and if you are serious about learning MPS, you may consider enrolling into the MPS Introductory Online Training. It will give you thorough guidance through numerous hands-on exercises and you will be able to discuss your progress and questions with a live trainer.

Step 5 - Projectional editing tips and tricks

Raw time estimate - 30 minutes

When editing code in MPS you will run into situations when your coding habits interfere with the projectional nature of the MPS editor. I'm actually pretty confident that you have already discovered such surprises during your experiments. Code in MPS is not text, but instead it is a projection of the abstract syntax (AST). This gives several benefits to language designers and, at the same time, makes the editing experience slightly different and more-restrictive than in the commonplace text editors. This may or may not be considered to be an advantage, nevertheless, there is a learning curve to projectional editing. In general, in projectional code you more rely on the assistance of the editor. Code-completion, block selection and intention actions should become your close friends in order to become an efficient projectional coder. There's a good and a bad side to it:

  • good - in less than a week of programming in the MPS editor people typically get back to their full speed of coding they experienced before in text-based IDEs

  • bad - projectional editing is highly addictive and you may find text-based editors less compelling and less helpful than you thought they'd been before

Step 6 - MPS from the language designer's perspective

Raw time estimate - 40 minutes

Now you must be curious about how the robot sample language has been created. Please, open again the Robot Kaja sample project and play our Explanatory video showing you the fundamentals of language definition.
Again, this video has been borrowed from the MPS Introductory Online Training course to give you a taste of this paid course that JetBrains provides.
As you go through the video, pause frequently and look around the sample project yourself. This way you will understand a typical language structure and see the relationships between its individual parts.

At this point you should understand that language definition consists of several aspects. Some of these are mandatory, some are optional:

  • Structure - Defines the kinds of nodes (called Concepts) that may be used in user models. Each node in the program (model) refers to its concept. Concepts specify, which propertieschildren and references nodes may have. Concepts can extend other Concepts and implement ConceptInterfaces.

  • Constraints - Restricts the relationships between nodes as well as the allowed values for properties beyond the rules defined in Structure. Constraints typically define:

    • the target scope for references (a collection of allowed nodes a reference can point to) 

    • situations, in which a node can be a child/parent/ancestor of another node 

    • allowed values for properties 

    • property accessor methods (getters and setters)

  • Behavior - Just like classes in OOP hold methods, Concepts may define methods and static methods that can be invoked on nodes in a polymorphic way. Nodes thus carry behaviour alongside their properties and relationships.

  • Editor - Instead of defining a parser that would translate code from an editable form (i.e. text) into the tree-like structure that a computer could manipulate, MPS offers the concept of projectional editor, which let's the user edit the AST directly. The Editor aspect enables language designers to create a UI for editing their concept concepts.

  • Actions - Since the MPS editor manipulates the underlying AST directly, some editing actions, such as copy-paste or replacing one node with another one translate into non-trivial AST changes. The Actions aspect holds definitions of such customised AST transformations.

  • Intentions - All modern IDEs assist developers with instant code manipulating action available under a handy key-shortcut (Alt + Enter in MPS). Language authors can define such little code transformations for their languages in the Intentions aspect.

  • Typesystem - Language that need to type-check their code need to provide type-system rules. The MPS type-system engine will evaluate the rules on-the-fly, calculate types for nodes and report 
    errors, wherever the calculated type differs from the expectations.
    So called checking rules may additionally be defined to verify non-typesystem assertions about the model.

  • Dataflow - The ability to understand the flow of values and the flow of control through language constructs helps languages report issues such as unreachable code or potential null-pointer error. Language designer can leverage the Dataflow aspect to define the flow for each concept, which MPS will then use to calculate the dataflow for the whole program.

  • Generator - Models written in one or more languages get ultimately translated into runnable code in some target general-purpose language and platform, such as Java. Along the way models get gradually transformed so that repeatedly concepts get replaced with concepts from a lower level of abstraction until the bottom-line level is reached. The rules for translating concepts and their proper ordering is defined in the Generator aspect.

  • TextGen - During code generation after the Generator has reached the bottom-line AST representation, the TextGen phase kicks in and translates all nodes in the model into their textual representation and saves the resulting textual source files on disk.

Step 7 - Shapes tutorial

Raw estimate - 2 hours

The Shapes Tutorial gives you an opportunity to quickly create your own language. Check out the MPS entry-level Shapes Tutorial and build a language that enables non-programmers to build scenes of graphical shapes.

Tut1

Tut2

Step 8 - Calculator tutorial

Raw time estimate - 8 hours

Now you must be curious to find out more details about language design in MPS, right? Having given you all the fundamental information and some level of experience, the introductory tutorials should have left you in a good position to dive deeper and build a sample language all the way from the ground up. The Calculator tutorial will guide you through the process of language creation. You start with an empty project and end up with a language to build Java Swing-based visual applications. Try it out and have fun.

The Calculator tutorial in JavaScript

As an illustration that MPS is not limited to generating Java, we've prepared a similar Calculator sample project - CalculatorJS, which generates an HTML page and a JavaScript program to hold the computation. You may check it out on GitHub.

Step 9 - Managing dependencies and imported languages

Raw time estimate - 30 minutes

As you must have noticed already, MPS lets you manage dependencies between models as well as import languages. Since it is essential to understand these, read a user guide chapter on getting the dependencies right. It will teach you the distinction between dependencies and imported languages and how to set/manage them.

Step 10 - The Garage project tutorial

Raw time estimate - 5 hours

The Calculator tutorial should have left you with good overall knowledge of language design. Now it is time for a more thorough exercise. The garage project will have you create several interconnected languages, package them as reusable plugins and stack languages one above the other. To handle the complexity of this tutorial, we leverage the Stepik platform for online education. Enrol in the free MPS Elementary Course.

Reviewing the progress

Congratulations! By completing the above tutorials and exercises you've made a serious dent into the language design world. Your knowledge and command of MPS could now be qualified somewhere above the Advanced beginner stage of the Dreyfus model of skill acquisition. This is definitely a good time to celebrate and perhaps also to let us know about you success.

Moving up the ladder

The next stage in the Dreyfus model of skill acquisition is Competent. Once you reach that stage you'll be able to work on your own without concrete guidelines and supervision. But for this to happen, you'll need to spend more time solving various problems with MPS. If you already have an idea of a language to implement, go ahead and do it. If not, try to come up with a useful little language. You could as well try to re-implement one or more of the MPS samples and then see how closely you got. Or just pick a sample as the starting point and move it forward - add language features, implement a generator, add type-system rules, polish the editing experience - whatever feels like the right challenge for you.

Additionally, you should try these in order to become Competent in MPS and language design:

  1. Apply for the MPS Advanced Course by JetBrains. Both online and on-site options are available. In the advanced course you will learn about:

    • making the editors fluent, intelligent and convenient to use

    • implementing non-trivial generators

    • defining type-system rules

    • specifying code analysis rules and quick-fixes

    • building customized IDEs and language plugins

    • a ton of other things

  2. Learn from the experts in the MPS community. Kolja Dummann has created his Heavy Meta series of videos covering the advanced stuff.

  3. Study the cookbooks to deepen your knowledge of the various aspects of language design that are listed further down on this page.

  4. Get to know quotations and anti-quotations

  5. The Generator tutorial will teach you more subtle options that the MPS generator offers. You will learn about the different types of macros, generator scripts, utility models and more.

  6. Familiarise yourself with the languages bundled in MPS, such as closures, collections, concept functionsregexp, tuples, smodel, build language and other

  7. Learn how to build MPS projects from the command line, how to package languages into IntelliJ IDEA as well as MPS plugins, how to use the plugins and how to build standalone DSL IDEs

  8. Get a feel for the user guide so you can quickly find the information that you need

  9. Learn some of the keyboard shortcuts by heart

  10. Become active in the MPS community and try to answer the forum questions of people that walk behind you on the same path to MPS mastery

After becoming Competent you should definitely continue gaining experience. The more you work with MPS and the more divert your projects are, the faster you'll be moving up on the Dreyfus model of skill acquisition scale. If you set yourself a goal to become Proficient and ultimately an Expert in MPS, you might consider trying:

  1. Studying and practising advanced topics, such as:
    1. Find usages
    2. MPS Make Framework
    3. Debugger enhancements and customisation

    4. Custom persistence
    5. Dependency analyzer and Module dependency tool

    6. Custom dataflow analyzers

    7. Extensions 

  2. Helping MPS expand into there areas by creating a base language for a different target language/platform - Python, Ruby, Dart, Haskell, Go, etc

  3. Speaking about MPS at events

  4. Helping us evolve the documentation

  5. Contributing code to the MPS project

Although there's not much detailed documentation to guide you at this experience level and you'll have to be self-driven most of the time, we'll always be happy to discuss, advise and cooperate with you.

Documentation sources

Here's a list of documentation sources that you may need on your path to MPS mastery

MPS rocks

A curated list of awesome MPS extensions/libraries, software and resources. Head to MPS rocks for more resources on MPS.

Academic papers

The publications page collects all relevant papers about MPS and the related field.

Books

Fabien Campagne wrote The MPS Language Workbench: Volume I and Volume II books, which you can purchase both electronically and as paper-back. Although the books cover an older version of MPS, most of their contents is still relevant. Get them here.

MPS Book Cover Volume1 small
cover Volume 2 v3 thumbnail website1 216x300

Cookbooks

The get slightly simplified practical information as well as some tips and tricks on individual aspects of language design, you may try some of the cookbooks.

User guides

A full-blown reference documentation provides exhaustive information on MPS. Check out the Language designer's User Guide.

Screencasts

Over time the MPS team has created a large collection of screen-casts covering many aspects of MPS use and language design. You may check them out all nicely sorted at the MPS screen-cast page or directly at the MPS channel of JetBrains TV.

Guided Trainings

The MPS team offers hands-on trainings. Check out the details:

General documentation

The MPS documentation page will give you all the remaining pointers to case studies, tutorials, FAQs and other pieces of MPS documentation.

Other sample projects

MPS comes with several sample projects that you may play with to get a better grasp of language development. I recommend you tried them out, perhaps in the order as they are listed below. Find out what they do and how they are implemented. They may teach you important lessons. Don't worry if you sometimes cannot figure out how a particular feature has been implemented. Most likely you will find an answer in one of the following exercises and then you can revisit the sample and the thing will just click instantly.

Here's a list of the samples that we've prepared for you:

Language extensions:

  • SampleJavaExtensions  - a collection of small handy Java enhancements, such as parallel for loopunless statement, Money literaldecision tables and Constants definition. The sample will teach you how to extend existing general purpose languages with custom constructs. You may also like to watch a short screen-cast introducing the individual extensions.

  • Complex - defines a Java extension to work with complex numbers

  • XML Literals - allows XML literals to be used directly in Java code as first-class language elements. The language builds on top of .xml and generates into into org.jdom.* API. The user-inserted XML code may refer back to the surrounding Java context to easily parametrize.

  • math - provides fancy-looking math language extension to Java, which allows you to enter complex numbers, matrixes, intervals, summation, product and other common mathematical operations in a natural way.

Standalone languages:

  • LanguagePatterns - a set of sample languages illustrating implementations of common language patterns in MPS. It is useful for beginners to see in isolation concrete implementations of typical language constructs. This sample project is gradually being updated with new patterns.

  • MultipleProjections - an example of a simple state machine language that focuses on the mechanism of multiple projections per concept. The programmer, who uses the language, can on-the-fly switch between several pre-defined notations as she progressed with her state-machine definition. All the available notations are defined in the language or its extensions.

  • MultiTarget  - illustrates how to have a single language generated into multiple different target languages.

  • Custom Aspects - shows the ways to define custom aspects for language definition. Check out the Custom language aspect cookbook for details.

  • Cross Model Generation  - illustrates how to use custom generator plans to achieve cross-model generation.

  • Component Dependencies - a minimalistic example of a language for expressing dependencies between components of a system, which provides three alternative editor notations:
    1. Textual

    2. Tabular

    3. Diagrams

    This language comes with an XML generator to illustrate the possibility to generate non-imperative language, such as XML.
  • Customized Debugger - an example of hooking a languages with the Java debugger, even when the language neither extends nor generates into BaseLanguage.

  • Mind maps - an intuitive example of defining a diagramming notation, including a set of customized graphical symbols

  • State machine (Secret Compartment language/ DSL book sample) - an example of a state machine language, including a state machine test language. An overview screen-cast is available to help you get started.

  • The Custom Test Cases - a minimalistic example of building your own tests and run them from MPS.

  • The Simplest Language - a minimalistic example generating a Hello world application printing out a customized message. Shows the very basics of language generation.

  • Migrations  - a simple example of migration scripts to migrate two interconnected languages using both the smodel API and TransformStatement.

  • Lambda Calculus - a language simulating lambda calculus, with projectional editor and generation into Java

  • Agreement - an example of a business-oriented DSL

  • Expressions - a simplified expression language to allow you to play with the type system and the Type-system Trace tool. The language gives you a bare-bone expressions language with minimal editor support, but with well structured type-system rules, which you can help you learn the core of how MPS calculates types. Read more in the Typesystem Debugging documentation.

  • Fixed Length Reader - illustrates how to create a language for describing binary data formats. Comes with a stub for a hypothetical runtime library that would extract elements from binary data using the supplied data format description (called configuration).

  • HighLevel Languages - an example of defining a custom set of language definition languages. Illustrates how to define your own way to codify structure and editor for a language.

  • Sample Language - A very intuitive and minimalistic example showing how to implement a common pattern of a root concept containing definitions as well as references to them. In this sample, we simulate Java classes, method definitions and method calls. However, such a pattern is quite frequent in many languages and it is worthwhile to spend some time investigating. You may also check out a brief screen-cast showing you round this sample.

  • Formula Language - a sample definition of an expression language, including editor actions and a generator

  • Notes Organizer - a sample DSL plugin for IntelliJ IDEA including a build script, that simulates a task/todo list. Tasks can have different priorities, states and categories, which by themselves can also be customized. The task lists can be filtered using several kinds of Swing UI components and the user can choose among several alternative visualizations of the task lists. Shows as an example of filtering node collections, alternative editors and direct incorporation of Swing components into form-like notations.

  • State Chart - an example of a state-chart definition language that generates state charts in the SCXML standard.

  • Requirement Tracking (new) - an example of a universal, language-agnostic requirement tracking language. Goals of a software project can be captured in specification documents written using the provided requirement tracking language. Mentions of relevant requirements can be inserted into code at places that implement these requirements. The mentions can be used in code that uses any MPS language. The sample features Node Attributes, non-trivial scoping and multiple switchable editors for a single concept.

  • Attributes - a sample illustrating the transparent handling of attributes in text-gen and the generator. The two CommentAttribute node attribute concepts are passed through the generator unchanged so that their text-gen can convert them to text.

  • Sample Facet - illustrates a simple make facet that intercepts the make process.

  • Lightweight DSL - examples of usages of the jetbrains.mps.baselanguage.lightweightDSL language to build internal "lightweight" DSLs embedded into BaseLanguage classes.

  • Heating controller  - a simple language providing two notations to specify heating plans for a hypothetical home heating controller. The default notation allows for textual representation, while a language extension provides an alternative tabular notation.

  • Progress Indicator - a set of actions that illustrate the proper way to handle progress bars in actions, how to make actions cancellable and enable them to run in the background.

  • Property Persistence - a non-trivial example of stub model implementation for a custom format. Plain property files are loaded as models into MPS thanks to the implementation of custom model roots and custom models of this sample project. Please check out our Custom Persistence Cookbook for details.

  • XML Persistence - a non-trivial example of implementing custom persistence using ModelFactories and custom model implementations. The plugin contains three solutions (a build script, a persistence implementation and a plugin descriptor). The custom persistence implementation will load/save XML documents. Please check out our Custom Persistence Cookbook for details.

Samples to tutorials:

  • Shapes  - the language created as part of the introductory Shapes Tutorial.

  • Robot Kaja - the language for commanding a virtual robot used in many of the introductory screencasts. Now includes a sample Context Assistant implementation.

  • Calculator - the language created as part of the Calculator Tutorial.

  • Generator demo - the set of languages developed as part of the Generator Tutorial.

 

Last modified: 28 February 2020